2 * $Id: uams_guest.c,v 1.12.6.2.2.1 2005-09-27 10:40:41 didg Exp $
4 * (c) 2001 (see COPYING)
9 #endif /* HAVE_CONFIG_H */
19 #else /* STDC_HEADERS */
23 #endif /* HAVE_STRCHR */
24 char *strchr (), *strrchr ();
26 #define memcpy(d,s,n) bcopy ((s), (d), (n))
27 #define memmove(d,s,n) bcopy ((s), (d), (n))
28 #endif /* ! HAVE_MEMCPY */
29 #endif /* STDC_HEADERS */
32 #include <atalk/logger.h>
34 #include <atalk/afp.h>
35 #include <atalk/uam.h>
36 #include <atalk/util.h>
39 #define MIN(a,b) ((a) < (b) ? (a) : (b))
42 extern void append(void *, const char *, int);
44 /* login and login_ext are almost the same */
45 static int noauth_login(void *obj, struct passwd **uam_pwd,
46 char *ibuf _U_, int ibuflen _U_,
47 char *rbuf _U_, int *rbuflen)
50 char *guest, *username;
53 LOG(log_info, logtype_uams, "login noauth" );
55 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
59 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
60 (void *) &username, NULL) < 0)
63 strcpy(username, guest);
64 if ((pwent = getpwnam(guest)) == NULL) {
65 LOG(log_error, logtype_uams, "noauth_login: getpwnam( %s ): %s",
66 guest, strerror(errno) );
67 return( AFPERR_BADUAM );
72 LOG(log_error, logtype_uams, "noauth_login: setpag: %s", strerror(errno) );
73 return( AFPERR_BADUAM );
81 static int noauth_login_ext(void *obj, char *uname _U_, struct passwd **uam_pwd,
82 char *ibuf, int ibuflen,
83 char *rbuf, int *rbuflen)
85 return ( noauth_login (obj, uam_pwd, ibuf, ibuflen, rbuf, rbuflen));
89 /* Printer NoAuthUAM Login */
90 int noauth_printer(start, stop, username, out)
91 char *start, *stop, *username;
95 static const char *loginok = "0\r";
97 data = (char *)malloc(stop - start + 1);
99 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: malloc");
103 strlcpy(data, start, stop - start + 1);
105 /* We are looking for the following format in data:
108 * Hopefully username doesn't contain a ")"
111 if ((p = strchr(data, '(' )) == NULL) {
112 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
117 if ((q = strchr(p, ')' )) == NULL) {
118 LOG(log_info, logtype_uams,"Bad Login NoAuthUAM: username not found in string");
122 memcpy(username, p, MIN( UAM_USERNAMELEN, q - p ));
124 /* Done copying username, clean up */
127 if (getpwnam(username) == NULL) {
128 LOG(log_info, logtype_uams, "Bad Login NoAuthUAM: %s: %s",
129 username, strerror(errno) );
133 /* Login successful */
134 append(out, loginok, strlen(loginok));
135 LOG(log_info, logtype_uams, "Login NoAuthUAM: %s", username);
140 static int uam_setup(const char *path)
142 if (uam_register(UAM_SERVER_LOGIN_EXT, path, "No User Authent",
143 noauth_login, NULL, NULL, noauth_login_ext) < 0)
146 if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
153 static void uam_cleanup()
155 uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
156 uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
159 UAM_MODULE_EXPORT struct uam_export uams_guest = {
162 uam_setup, uam_cleanup