2 * $Id: uams_guest.c,v 1.16 2009-10-14 01:38:28 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 /*XXX in etc/papd/file.h */
43 extern void append(struct papfile *, const char *, int);
45 /* login and login_ext are almost the same */
46 static int noauth_login(void *obj, struct passwd **uam_pwd,
47 char *ibuf _U_, int ibuflen _U_,
48 char *rbuf _U_, int *rbuflen)
51 char *guest, *username;
54 LOG(log_info, logtype_uams, "login noauth" );
56 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
60 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
61 (void *) &username, NULL) < 0)
64 strcpy(username, guest);
65 if ((pwent = getpwnam(guest)) == NULL) {
66 LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s",
67 guest, strerror(errno) );
68 return( AFPERR_BADUAM );
73 LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
74 return( AFPERR_BADUAM );
82 static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd,
83 char *ibuf, int ibuflen,
84 char *rbuf, int *rbuflen)
86 return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
90 /* Printer NoAuthUAM Login */
91 static int noauth_printer(char *start, char *stop, char *username, struct papfile *out)
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(void)
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