2 * $Id: uams_guest.c,v 1.7 2001-09-06 20:00:59 rufustfirefly Exp $
4 * (c) 2001 (see COPYING)
9 #endif /* HAVE_CONFIG_H */
17 #else /* STDC_HEADERS */
21 #endif /* HAVE_STRCHR */
22 char *strchr (), *strrchr ();
24 #define memcpy(d,s,n) bcopy ((s), (d), (n))
25 #define memmove(d,s,n) bcopy ((s), (d), (n))
26 #endif /* ! HAVE_MEMCPY */
27 #endif /* STDC_HEADERS */
32 #include <atalk/afp.h>
33 #include <atalk/uam.h>
35 static int noauth_login(void *obj, struct passwd **uam_pwd,
36 char *ibuf, int ibuflen,
37 char *rbuf, int *rbuflen)
40 char *guest, *username;
43 syslog( LOG_INFO, "login noauth" );
45 if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
49 if (uam_afpserver_option(obj, UAM_OPTION_USERNAME,
50 (void *) &username, NULL) < 0)
53 strcpy(username, guest);
54 if ((pwent = getpwnam(guest)) == NULL) {
55 syslog( LOG_ERR, "noauth_login: getpwnam( %s ): %m", guest);
56 return( AFPERR_BADUAM );
61 syslog( LOG_ERR, "noauth_login: setpag: %m" );
62 return( AFPERR_BADUAM );
71 /* Printer NoAuthUAM Login */
72 int noauth_printer(start, stop, username, out)
73 char *start, *stop, *username;
77 static const char *loginok = "0\r";
79 data = (char *)malloc(stop - start + 1);
80 strncpy(data, start, stop - start + 1);
82 /* We are looking for the following format in data:
85 * Hopefully username doesn't contain a ")"
88 if ((p = strchr(data, '(' )) == NULL) {
89 syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
94 if ((q = strchr(data, ')' )) == NULL) {
95 syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
99 strncpy(username, p, q - p);
101 /* Done copying username, clean up */
104 if (getpwnam(username) == NULL) {
105 syslog(LOG_INFO, "Bad Login NoAuthUAM: %s: %m", username);
109 /* Login successful */
110 append(out, loginok, strlen(loginok));
111 syslog(LOG_INFO, "Login NoAuthUAM: %s", username);
116 static int uam_setup(const char *path)
118 if (uam_register(UAM_SERVER_LOGIN, path, "No User Authent",
119 noauth_login, NULL, NULL) < 0)
121 if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
128 static void uam_cleanup()
130 uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
131 uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
134 UAM_MODULE_EXPORT struct uam_export uams_guest = {
137 uam_setup, uam_cleanup