2 * $Id: uams_guest.c,v 1.18 2009-11-08 01:07:17 didg Exp $
4 * (c) 2001 (see COPYING)
9 #endif /* HAVE_CONFIG_H */
17 #include <atalk/logger.h>
18 #include <atalk/afp.h>
19 #include <atalk/uam.h>
20 #include <atalk/util.h>
23 #define MIN(a,b) ((a) < (b) ? (a) : (b))
26 /*XXX in etc/papd/file.h */
28 extern UAM_MODULE_EXPORT void append(struct papfile *, const char *, int);
30 /* login and login_ext are almost the same */
31 static int noauth_login(void *obj, struct passwd **uam_pwd,
32 char *ibuf _U_, size_t ibuflen _U_,
33 char *rbuf _U_, size_t *rbuflen)
36 char *guest, *username;
39 LOG(log_info, logtype_uams, "login noauth" );
41 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
45 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
46 (void *) &username, NULL) < 0)
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 );
58 LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
59 return( AFPERR_BADUAM );
67 static 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)
71 return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
75 /* Printer NoAuthUAM Login */
76 static int noauth_printer(char *start, char *stop, char *username, struct papfile *out)
79 static const char *loginok = "0\r";
81 data = (char *)malloc(stop - start + 1);
83 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc");
87 strlcpy(data, start, stop - start + 1);
89 /* We are looking for the following format in data:
92 * Hopefully username doesn't contain a ")"
95 if ((p = strchr(data, '(' )) == NULL) {
96 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
101 if ((q = strchr(p, ')' )) == NULL) {
102 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
106 memcpy(username, p, MIN( UAM_USERNAMELEN, q - p ));
108 /* Done copying username, clean up */
111 if (getpwnam(username) == NULL) {
112 LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s",
113 username, strerror(errno) );
117 /* Login successful */
118 append(out, loginok, strlen(loginok));
119 LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username);
124 static int uam_setup(const char *path)
126 if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent",
127 noauth_login, NULL, NULL, noauth_login_ext) < 0)
130 if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
137 static void uam_cleanup(void)
139 uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
140 uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
143 UAM_MODULE_EXPORT struct uam_export uams_guest = {
146 uam_setup, uam_cleanup