• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/netatalk-3.0.5/etc/uams/
1/*
2 *
3 * (c) 2001 (see COPYING)
4 */
5
6#ifdef HAVE_CONFIG_H
7#include "config.h"
8#endif /* HAVE_CONFIG_H */
9
10#include <stdio.h>
11#include <stdlib.h>
12#include <errno.h>
13#include <string.h>
14#include <pwd.h>
15
16#include <atalk/logger.h>
17#include <atalk/afp.h>
18#include <atalk/uam.h>
19#include <atalk/util.h>
20#include <atalk/compat.h>
21
22#ifndef MIN
23#define MIN(a,b) ((a) < (b) ? (a) : (b))
24#endif /* MIN */
25
26/*XXX in etc/papd/file.h */
27struct papfile;
28extern UAM_MODULE_EXPORT void append(struct papfile *, const char *, int);
29
30/* login and login_ext are almost the same */
31static int noauth_login(void *obj, struct passwd **uam_pwd,
32			char *ibuf _U_, size_t ibuflen _U_,
33			char *rbuf _U_, size_t *rbuflen)
34{
35    struct passwd *pwent;
36    char *guest, *username;
37
38    *rbuflen = 0;
39    LOG(log_info, logtype_uams, "login noauth" );
40
41    if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
42			     NULL) < 0)
43      return AFPERR_MISC;
44
45    if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
46			     (void *) &username, NULL) < 0)
47      return AFPERR_MISC;
48
49    strcpy(username, guest);
50    if ((pwent = getpwnam(guest)) == NULL) {
51	LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s",
52		guest, strerror(errno) );
53	return( AFPERR_BADUAM );
54    }
55
56#ifdef AFS
57    if ( setpag() < 0 ) {
58	LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
59	return( AFPERR_BADUAM );
60    }
61#endif /* AFS */
62
63    *uam_pwd = pwent;
64    return( AFP_OK );
65}
66
67static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd,
68                     char *ibuf, size_t ibuflen,
69                     char *rbuf, size_t *rbuflen)
70{
71        return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
72}
73
74
75/* Printer NoAuthUAM Login */
76static int noauth_printer(char *start, char *stop, char *username, struct papfile *out)
77{
78    char	*data, *p, *q;
79    static const char *loginok = "0\r";
80
81    data = (char *)malloc(stop - start + 1);
82    if (!data) {
83	LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc");
84	return(-1);
85    }
86
87    strlcpy(data, start, stop - start + 1);
88
89    /* We are looking for the following format in data:
90     * (username)
91     *
92     * Hopefully username doesn't contain a ")"
93     */
94
95    if ((p = strchr(data, '(' )) == NULL) {
96	LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
97	free(data);
98	return(-1);
99    }
100    p++;
101    if ((q = strchr(p, ')' )) == NULL) {
102	LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
103	free(data);
104	return(-1);
105    }
106    memcpy(username, p,  MIN( UAM_USERNAMELEN, q - p ));
107
108    /* Done copying username, clean up */
109    free(data);
110
111    if (getpwnam(username) == NULL) {
112	LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s",
113	       username, strerror(errno) );
114	return(-1);
115    }
116
117    /* Login successful */
118    append(out, loginok, strlen(loginok));
119    LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username);
120    return(0);
121}
122
123
124static int uam_setup(const char *path)
125{
126  if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent",
127                   noauth_login, NULL, NULL, noauth_login_ext) < 0)
128        return -1;
129
130  if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
131		noauth_printer) < 0)
132	return -1;
133
134  return 0;
135}
136
137static void uam_cleanup(void)
138{
139  uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
140  uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
141}
142
143UAM_MODULE_EXPORT struct uam_export uams_guest = {
144  UAM_MODULE_SERVER,
145  UAM_MODULE_VERSION,
146  uam_setup, uam_cleanup
147};
148