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>
21 #include <atalk/compat.h>
24 #define MIN(a,b) ((a) < (b) ? (a) : (b))
27 /*XXX in etc/papd/file.h */
29 extern UAM_MODULE_EXPORT void append(struct papfile *, const char *, int);
31 /* login and login_ext are almost the same */
32 static int noauth_login(void *obj, struct passwd **uam_pwd,
33 char *ibuf _U_, size_t ibuflen _U_,
34 char *rbuf _U_, size_t *rbuflen)
37 char *guest, *username;
40 LOG(log_info, logtype_uams, "login noauth" );
42 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
46 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
47 (void *) &username, NULL) < 0)
50 strcpy(username, guest);
51 if ((pwent = getpwnam(guest)) == NULL) {
52 LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s",
53 guest, strerror(errno) );
54 return( AFPERR_BADUAM );
59 LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
60 return( AFPERR_BADUAM );
68 static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd,
69 char *ibuf, size_t ibuflen,
70 char *rbuf, size_t *rbuflen)
72 return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
76 /* Printer NoAuthUAM Login */
77 static int noauth_printer(char *start, char *stop, char *username, struct papfile *out)
80 static const char *loginok = "0\r";
82 data = (char *)malloc(stop - start + 1);
84 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc");
88 strlcpy(data, start, stop - start + 1);
90 /* We are looking for the following format in data:
93 * Hopefully username doesn't contain a ")"
96 if ((p = strchr(data, '(' )) == NULL) {
97 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
102 if ((q = strchr(p, ')' )) == NULL) {
103 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
107 memcpy(username, p, MIN( UAM_USERNAMELEN, q - p ));
109 /* Done copying username, clean up */
112 if (getpwnam(username) == NULL) {
113 LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s",
114 username, strerror(errno) );
118 /* Login successful */
119 append(out, loginok, strlen(loginok));
120 LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username);
125 static int uam_setup(const char *path)
127 if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent",
128 noauth_login, NULL, NULL, noauth_login_ext) < 0)
131 if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
138 static void uam_cleanup(void)
140 uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
141 uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
144 UAM_MODULE_EXPORT struct uam_export uams_guest = {
147 uam_setup, uam_cleanup