2 * $Id: uam.c,v 1.11 2009-10-15 11:39:48 didg Exp $
4 * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
19 #else /* STDC_HEADERS */
23 #endif /* HAVE_STRCHR */
24 char *strchr (), *strrchr ();
26 #define memcpy(d,s,n) bcopy ((s), (d), (n))
27 #define memmove(d,s,n) bcopy ((s), (d), (n))
28 #endif /* ! HAVE_MEMCPY */
29 #endif /* STDC_HEADERS */
33 #endif /* HAVE_UNISTD_H */
36 #include <atalk/logger.h>
37 #include <sys/param.h>
40 #include <netatalk/endian.h>
41 #include <atalk/asp.h>
42 #include <atalk/dsi.h>
43 #include <atalk/afp.h>
44 #include <atalk/util.h>
48 /* --- server uam functions -- */
50 /* uam_load. uams must have a uam_setup function. */
51 struct uam_mod *uam_load(const char *path, const char *name)
53 char buf[MAXPATHLEN + 1], *p;
57 if ((module = mod_open(path)) == NULL) {
58 LOG(log_error, logtype_papd, "uam_load(%s): failed to load: %s", name, mod_error());
62 if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
63 LOG(log_error, logtype_papd, "uam_load(%s): malloc failed", name);
67 strlcpy(buf, name, sizeof(buf));
68 if ((p = strchr(buf, '.')))
70 if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
74 if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) {
75 LOG(log_error, logtype_papd, "uam_load(%s): attempted to load a non-server module",
80 /* version check would go here */
82 if (!mod->uam_fcn->uam_setup ||
83 ((*mod->uam_fcn->uam_setup)(name) < 0)) {
84 LOG(log_error, logtype_papd, "uam_load(%s): uam_setup failed", name);
88 mod->uam_module = module;
98 /* unload the module. we check for a cleanup function, but we don't
99 * die if one doesn't exist. however, things are likely to leak without one.
101 void uam_unload(struct uam_mod *mod)
103 if (mod->uam_fcn->uam_cleanup)
104 (*mod->uam_fcn->uam_cleanup)();
105 mod_close(mod->uam_module);
109 /* -- client-side uam functions -- */
111 /* set up stuff for this uam. */
112 int uam_register(const int type, const char *path, const char *name, ...)
121 /* see if it already exists. */
122 if ((uam = auth_uamfind(type, name, strlen(name)))) {
123 if (strcmp(uam->uam_path, path)) {
124 /* it exists, but it's not the same module. */
125 LOG(log_error, logtype_papd, "uam_register: \"%s\" already loaded by %s",
133 /* allocate space for uam */
134 if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
137 uam->uam_name = name;
138 uam->uam_path = strdup(path);
143 case UAM_SERVER_LOGIN: /* expect three arguments */
144 uam->u.uam_login.login = va_arg(ap, void *);
145 uam->u.uam_login.logincont = va_arg(ap, void *);
146 uam->u.uam_login.logout = va_arg(ap, void *);
148 case UAM_SERVER_CHANGEPW: /* one argument */
149 uam->u.uam_changepw = va_arg(ap, void *);
151 case UAM_SERVER_PRINTAUTH: /* x arguments */
152 uam->u.uam_printer = va_arg(ap, void *);
159 /* attach to other uams */
160 ret = auth_register(type, uam);
169 void uam_unregister(const int type, const char *name)
176 uam = auth_uamfind(type, name, strlen(name));
177 if (!uam || --uam->uam_count > 0)
180 auth_unregister(uam);
185 /* Crap to support uams which call this afpd function */
186 int uam_afpserver_option(void *private _U_, const int what _U_, void *option _U_,
192 /* --- helper functions for plugin uams --- */
194 struct passwd *uam_getname(void *dummy _U_, char *name, const int len)
196 struct passwd *pwent;
200 if ((pwent = getpwnam(name)))
203 #ifndef NO_REAL_USER_NAME
204 for (i = 0; i < len; i++)
205 name[i] = tolower(name[i]);
208 while ((pwent = getpwent())) {
209 if ((user = strchr(pwent->pw_gecos, ','))) *user = '\0';
210 user = pwent->pw_gecos;
212 /* check against both the gecos and the name fields. the user
213 * might have just used a different capitalization. */
214 if ((strncasecmp(user, name, len) == 0) ||
215 (strncasecmp(pwent->pw_name, name, len) == 0)) {
216 strncpy(name, pwent->pw_name, len);
221 #endif /* NO_REAL_USER_NAME */
223 /* os x server doesn't keep anything useful if we do getpwent */
224 return pwent ? getpwnam(name) : NULL;
228 int uam_checkuser(const struct passwd *pwd)
232 if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0'))
235 while ((p = getusershell())) {
236 if ( strcmp( p, pwd->pw_shell ) == 0 )
241 #ifndef DISABLE_SHELLCHECK
243 LOG(log_info, logtype_papd, "illegal shell %s for %s",pwd->pw_shell,pwd->pw_name);
246 #endif /* DISABLE_SHELLCHECK */