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