]> arthur.barton.de Git - netatalk.git/blob - etc/uams/uams_guest.c
fixed a typo in uams_guest.c.
[netatalk.git] / etc / uams / uams_guest.c
1 /*
2  * $Id: uams_guest.c,v 1.6 2001-06-27 18:22:20 uhees Exp $
3  *
4  * (c) 2001 (see COPYING)
5  */
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif /* HAVE_CONFIG_H */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <pwd.h>
15 #include <syslog.h>
16
17 #include <atalk/afp.h>
18 #include <atalk/uam.h>
19
20 static int noauth_login(void *obj, struct passwd **uam_pwd,
21                         char *ibuf, int ibuflen, 
22                         char *rbuf, int *rbuflen)
23 {
24     struct passwd *pwent;
25     char *guest, *username;
26
27     *rbuflen = 0;
28     syslog( LOG_INFO, "login noauth" );
29
30     if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
31                              NULL) < 0)
32       return AFPERR_MISC;
33
34     if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, 
35                              (void *) &username, NULL) < 0)
36       return AFPERR_MISC;
37
38     strcpy(username, guest);
39     if ((pwent = getpwnam(guest)) == NULL) {
40         syslog( LOG_ERR, "noauth_login: getpwnam( %s ): %m", guest);
41         return( AFPERR_BADUAM );
42     }
43
44 #ifdef AFS
45     if ( setpag() < 0 ) {
46         syslog( LOG_ERR, "noauth_login: setpag: %m" );
47         return( AFPERR_BADUAM );
48     }
49 #endif /* AFS */
50
51     *uam_pwd = pwent;
52     return( AFP_OK );
53 }
54
55
56 /* Printer NoAuthUAM Login */
57 int noauth_printer(start, stop, username, out)
58         char    *start, *stop, *username;
59         struct papfile  *out;
60 {
61     char        *data, *p, *q;
62     static const char *loginok = "0\r";
63
64     data = (char *)malloc(stop - start + 1);
65     strncpy(data, start, stop - start + 1);
66
67     /* We are looking for the following format in data:
68      * (username)
69      *
70      * Hopefully username doesn't contain a ")"
71      */
72
73     if ((p = strchr(data, '(' )) == NULL) {
74         syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
75         free(data);
76         return(-1);
77     }
78     p++;
79     if ((q = strchr(data, ')' )) == NULL) {
80         syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
81         free(data);
82         return(-1);
83     }
84     strncpy(username, p, q - p);
85
86     /* Done copying username, clean up */
87     free(data);
88
89     if (getpwnam(username) == NULL) {
90         syslog(LOG_INFO, "Bad Login NoAuthUAM: %s: %m", username);
91         return(-1);
92     }
93
94     /* Login successful */
95     append(out, loginok, strlen(loginok));
96     syslog(LOG_INFO, "Login NoAuthUAM: %s", username);
97     return(0);
98 }
99
100
101 static int uam_setup(const char *path)
102 {
103   if (uam_register(UAM_SERVER_LOGIN, path, "No User Authent",
104                noauth_login, NULL, NULL) < 0)
105         return -1;
106   if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
107                 noauth_printer) < 0)
108         return -1;
109
110   return 0;
111 }
112
113 static void uam_cleanup()
114 {
115   uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
116   uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
117 }
118
119 UAM_MODULE_EXPORT struct uam_export uams_guest = {
120   UAM_MODULE_SERVER,
121   UAM_MODULE_VERSION,
122   uam_setup, uam_cleanup
123 };