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