]> arthur.barton.de Git - netatalk.git/blob - etc/uams/uams_guest.c
Warning fixes.
[netatalk.git] / etc / uams / uams_guest.c
1 /*
2  * $Id: uams_guest.c,v 1.8 2001-10-24 14:34:33 srittau 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 <errno.h>
14
15 /* STDC check */
16 #if STDC_HEADERS
17 #include <string.h>
18 #else /* STDC_HEADERS */
19 #ifndef HAVE_STRCHR
20 #define strchr index
21 #define strrchr index
22 #endif /* HAVE_STRCHR */
23 char *strchr (), *strrchr ();
24 #ifndef HAVE_MEMCPY
25 #define memcpy(d,s,n) bcopy ((s), (d), (n))
26 #define memmove(d,s,n) bcopy ((s), (d), (n))
27 #endif /* ! HAVE_MEMCPY */
28 #endif /* STDC_HEADERS */
29
30 #include <pwd.h>
31 #include <syslog.h>
32
33 #include <atalk/afp.h>
34 #include <atalk/uam.h>
35
36 static int noauth_login(void *obj, struct passwd **uam_pwd,
37                         char *ibuf, int ibuflen, 
38                         char *rbuf, int *rbuflen)
39 {
40     struct passwd *pwent;
41     char *guest, *username;
42
43     *rbuflen = 0;
44     syslog( LOG_INFO, "login noauth" );
45
46     if (uam_afpserver_option(obj, UAM_OPTION_GUEST, (void *) &guest,
47                              NULL) < 0)
48       return AFPERR_MISC;
49
50     if (uam_afpserver_option(obj, UAM_OPTION_USERNAME, 
51                              (void *) &username, NULL) < 0)
52       return AFPERR_MISC;
53
54     strcpy(username, guest);
55     if ((pwent = getpwnam(guest)) == NULL) {
56         syslog( LOG_ERR, "noauth_login: getpwnam( %s ): %s",
57                 guest, strerror(errno) );
58         return( AFPERR_BADUAM );
59     }
60
61 #ifdef AFS
62     if ( setpag() < 0 ) {
63         syslog( LOG_ERR, "noauth_login: setpag: %s", strerror(errno) );
64         return( AFPERR_BADUAM );
65     }
66 #endif /* AFS */
67
68     *uam_pwd = pwent;
69     return( AFP_OK );
70 }
71
72
73 /* Printer NoAuthUAM Login */
74 int noauth_printer(start, stop, username, out)
75         char    *start, *stop, *username;
76         struct papfile  *out;
77 {
78     char        *data, *p, *q;
79     static const char *loginok = "0\r";
80
81     data = (char *)malloc(stop - start + 1);
82     strncpy(data, start, stop - start + 1);
83
84     /* We are looking for the following format in data:
85      * (username)
86      *
87      * Hopefully username doesn't contain a ")"
88      */
89
90     if ((p = strchr(data, '(' )) == NULL) {
91         syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
92         free(data);
93         return(-1);
94     }
95     p++;
96     if ((q = strchr(data, ')' )) == NULL) {
97         syslog(LOG_INFO,"Bad Login NoAuthUAM: username not found in string");
98         free(data);
99         return(-1);
100     }
101     strncpy(username, p, q - p);
102
103     /* Done copying username, clean up */
104     free(data);
105
106     if (getpwnam(username) == NULL) {
107         syslog(LOG_INFO, "Bad Login NoAuthUAM: %s: %s",
108                username, strerror(errno) );
109         return(-1);
110     }
111
112     /* Login successful */
113     append(out, loginok, strlen(loginok));
114     syslog(LOG_INFO, "Login NoAuthUAM: %s", username);
115     return(0);
116 }
117
118
119 static int uam_setup(const char *path)
120 {
121   if (uam_register(UAM_SERVER_LOGIN, path, "No User Authent",
122                noauth_login, NULL, NULL) < 0)
123         return -1;
124   if (uam_register(UAM_SERVER_PRINTAUTH, path, "NoAuthUAM",
125                 noauth_printer) < 0)
126         return -1;
127
128   return 0;
129 }
130
131 static void uam_cleanup()
132 {
133   uam_unregister(UAM_SERVER_LOGIN, "No User Authent");
134   uam_unregister(UAM_SERVER_PRINTAUTH, "NoAuthUAM");
135 }
136
137 UAM_MODULE_EXPORT struct uam_export uams_guest = {
138   UAM_MODULE_SERVER,
139   UAM_MODULE_VERSION,
140   uam_setup, uam_cleanup
141 };