2 * $Id: uams_guest.c,v 1.14 2009-09-14 00:02:21 didg Exp $
4 * (c) 2001 (see COPYING)
9 #endif /* HAVE_CONFIG_H */
18 #else /* STDC_HEADERS */
22 #endif /* HAVE_STRCHR */
23 char *strchr (), *strrchr ();
25 #define memcpy(d,s,n) bcopy ((s), (d), (n))
26 #define memmove(d,s,n) bcopy ((s), (d), (n))
27 #endif /* ! HAVE_MEMCPY */
28 #endif /* STDC_HEADERS */
31 #include <atalk/logger.h>
33 #include <atalk/afp.h>
34 #include <atalk/uam.h>
35 #include <atalk/util.h>
38 #define MIN(a,b) ((a) < (b) ? (a) : (b))
41 extern void append(void *, const char *, int);
43 /* login and login_ext are almost the same */
44 static int noauth_login(void *obj, struct passwd **uam_pwd,
45 char *ibuf _U_, int ibuflen _U_,
46 char *rbuf _U_, int *rbuflen)
49 char *guest, *username;
52 LOG(log_info, logtype_uams, "login noauth" );
54 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
58 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
59 (void *) &username, NULL) < 0)
62 strcpy(username, guest);
63 if ((pwent = getpwnam(guest)) == NULL) {
64 LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s",
65 guest, strerror(errno) );
66 return( AFPERR_BADUAM );
71 LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
72 return( AFPERR_BADUAM );
80 static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd,
81 char *ibuf, int ibuflen,
82 char *rbuf, int *rbuflen)
84 return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
88 /* Printer NoAuthUAM Login */
89 int noauth_printer(start, stop, username, out)
90 char *start, *stop, *username;
94 static const char *loginok = "0\r";
96 data = (char *)malloc(stop - start + 1);
98 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc");
102 strlcpy(data, start, stop - start + 1);
104 /* We are looking for the following format in data:
107 * Hopefully username doesn't contain a ")"
110 if ((p = strchr(data, '(' )) == NULL) {
111 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
116 if ((q = strchr(p, ')' )) == NULL) {
117 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
121 memcpy(username, p, MIN( UAM_USERNAMELEN, q - p ));
123 /* Done copying username, clean up */
126 if (getpwnam(username) == NULL) {
127 LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s",
128 username, strerror(errno) );
132 /* Login successful */
133 append(out, loginok, strlen(loginok));
134 LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username);
139 static int uam_setup(const char *path)
141 if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent",
142 noauth_login, NULL, NULL, noauth_login_ext) < 0)
145 if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
152 static void uam_cleanup()
154 uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
155 uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
158 UAM_MODULE_EXPORT struct uam_export uams_guest = {
161 uam_setup, uam_cleanup