2 * $Id: uam.c,v 1.5 2001-06-25 20:13:45 rufustfirefly Exp $
4 * Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
5 * All Rights Reserved. See COPYRIGHT.
10 #endif /* HAVE_CONFIG_H */
17 #endif /* HAVE_UNISTD_H */
21 #include <sys/param.h>
24 #include <netatalk/endian.h>
25 #include <atalk/asp.h>
26 #include <atalk/dsi.h>
27 #include <atalk/afp.h>
28 #include <atalk/util.h>
32 /* --- server uam functions -- */
34 /* uam_load. uams must have a uam_setup function. */
35 struct uam_mod *uam_load(const char *path, const char *name)
37 char buf[MAXPATHLEN + 1], *p;
41 if ((module = mod_open(path)) == NULL) {
42 syslog(LOG_ERR, "uam_load(%s): failed to load.", name);
43 syslog(LOG_ERR, dlerror());
47 if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
48 syslog(LOG_ERR, "uam_load(%s): malloc failed", name);
52 strncpy(buf, name, sizeof(buf));
53 if ((p = strchr(buf, '.')))
55 if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
59 if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) {
60 syslog(LOG_ERR, "uam_load(%s): attempted to load a non-server module",
65 /* version check would go here */
67 if (!mod->uam_fcn->uam_setup ||
68 ((*mod->uam_fcn->uam_setup)(name) < 0)) {
69 syslog(LOG_ERR, "uam_load(%s): uam_setup failed", name);
73 mod->uam_module = module;
83 /* unload the module. we check for a cleanup function, but we don't
84 * die if one doesn't exist. however, things are likely to leak without one.
86 void uam_unload(struct uam_mod *mod)
88 if (mod->uam_fcn->uam_cleanup)
89 (*mod->uam_fcn->uam_cleanup)();
90 mod_close(mod->uam_module);
94 /* -- client-side uam functions -- */
96 /* set up stuff for this uam. */
97 int uam_register(const int type, const char *path, const char *name, ...)
105 /* see if it already exists. */
106 if ((uam = auth_uamfind(type, name, strlen(name)))) {
107 if (strcmp(uam->uam_path, path)) {
108 /* it exists, but it's not the same module. */
109 syslog(LOG_ERR, "uam_register: \"%s\" already loaded by %s",
117 /* allocate space for uam */
118 if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
121 uam->uam_name = name;
122 uam->uam_path = strdup(path);
127 case UAM_SERVER_LOGIN: /* expect three arguments */
128 uam->u.uam_login.login = va_arg(ap, void *);
129 uam->u.uam_login.logincont = va_arg(ap, void *);
130 uam->u.uam_login.logout = va_arg(ap, void *);
132 case UAM_SERVER_CHANGEPW: /* one argument */
133 uam->u.uam_changepw = va_arg(ap, void *);
135 case UAM_SERVER_PRINTAUTH: /* x arguments */
136 uam->u.uam_printer = va_arg(ap, void *);
143 /* attach to other uams */
144 if (auth_register(type, uam) < 0) {
153 void uam_unregister(const int type, const char *name)
160 uam = auth_uamfind(type, name, strlen(name));
161 if (!uam || --uam->uam_count > 0)
164 auth_unregister(uam);
169 /* Crap to support uams which call this afpd function */
170 int uam_afpserver_option(void *private, const int what, void *option,
176 /* --- helper functions for plugin uams --- */
178 struct passwd *uam_getname(char *name, const int len)
180 struct passwd *pwent;
184 if ((pwent = getpwnam(name)))
187 #ifndef NO_REAL_USER_NAME
188 for (i = 0; i < len; i++)
189 name[i] = tolower(name[i]);
192 while ((pwent = getpwent())) {
193 if ((user = strchr(pwent->pw_gecos, ','))) *user = '\0';
194 user = pwent->pw_gecos;
196 /* check against both the gecos and the name fields. the user
197 * might have just used a different capitalization. */
198 if ((strncasecmp(user, name, len) == 0) ||
199 (strncasecmp(pwent->pw_name, name, len) == 0)) {
200 strncpy(name, pwent->pw_name, len);
205 #endif /* NO_REAL_USER_NAME */
207 /* os x server doesn't keep anything useful if we do getpwent */
208 return pwent ? getpwnam(name) : NULL;
212 int uam_checkuser(const struct passwd *pwd)
216 if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0'))
219 while ((p = getusershell())) {
220 if ( strcmp( p, pwd->pw_shell ) == 0 )
225 #ifndef DISABLE_SHELLCHECK
227 syslog( LOG_INFO, "illegal shell %s for %s",pwd->pw_shell,pwd->pw_name);
230 #endif /* DISABLE_SHELLCHECK */