1 /* Copyright (c) 1999 Adrian Sun (asun@zoology.washington.edu)
2 * All Rights Reserved. See COPYRIGHT.
16 #include <sys/param.h>
19 #include <netatalk/endian.h>
20 #include <atalk/asp.h>
21 #include <atalk/dsi.h>
22 #include <atalk/afp.h>
23 #include <atalk/util.h>
27 /* --- server uam functions -- */
29 /* uam_load. uams must have a uam_setup function. */
30 struct uam_mod *uam_load(const char *path, const char *name)
32 char buf[MAXPATHLEN + 1], *p;
36 if ((module = mod_open(path)) == NULL) {
37 syslog(LOG_ERR, "uam_load(%s): failed to load.", name);
38 syslog(LOG_ERR, dlerror());
42 if ((mod = (struct uam_mod *) malloc(sizeof(struct uam_mod))) == NULL) {
43 syslog(LOG_ERR, "uam_load(%s): malloc failed", name);
47 strncpy(buf, name, sizeof(buf));
48 if ((p = strchr(buf, '.')))
50 if ((mod->uam_fcn = mod_symbol(module, buf)) == NULL) {
54 if (mod->uam_fcn->uam_type != UAM_MODULE_SERVER) {
55 syslog(LOG_ERR, "uam_load(%s): attempted to load a non-server module",
60 /* version check would go here */
62 if (!mod->uam_fcn->uam_setup ||
63 ((*mod->uam_fcn->uam_setup)(name) < 0)) {
64 syslog(LOG_ERR, "uam_load(%s): uam_setup failed", name);
68 mod->uam_module = module;
78 /* unload the module. we check for a cleanup function, but we don't
79 * die if one doesn't exist. however, things are likely to leak without one.
81 void uam_unload(struct uam_mod *mod)
83 if (mod->uam_fcn->uam_cleanup)
84 (*mod->uam_fcn->uam_cleanup)();
85 mod_close(mod->uam_module);
89 /* -- client-side uam functions -- */
91 /* set up stuff for this uam. */
92 int uam_register(const int type, const char *path, const char *name, ...)
100 /* see if it already exists. */
101 if ((uam = auth_uamfind(type, name, strlen(name)))) {
102 if (strcmp(uam->uam_path, path)) {
103 /* it exists, but it's not the same module. */
104 syslog(LOG_ERR, "uam_register: \"%s\" already loaded by %s",
112 /* allocate space for uam */
113 if ((uam = calloc(1, sizeof(struct uam_obj))) == NULL)
116 uam->uam_name = name;
117 uam->uam_path = strdup(path);
122 case UAM_SERVER_LOGIN: /* expect three arguments */
123 uam->u.uam_login.login = va_arg(ap, void *);
124 uam->u.uam_login.logincont = va_arg(ap, void *);
125 uam->u.uam_login.logout = va_arg(ap, void *);
127 case UAM_SERVER_CHANGEPW: /* one argument */
128 uam->u.uam_changepw = va_arg(ap, void *);
130 case UAM_SERVER_PRINTAUTH: /* x arguments */
131 uam->u.uam_printer = va_arg(ap, void *);
138 /* attach to other uams */
139 if (auth_register(type, uam) < 0) {
148 void uam_unregister(const int type, const char *name)
155 uam = auth_uamfind(type, name, strlen(name));
156 if (!uam || --uam->uam_count > 0)
159 auth_unregister(uam);
164 /* Crap to support uams which call this afpd function */
165 int uam_afpserver_option(void *private, const int what, void *option,
171 /* --- helper functions for plugin uams --- */
173 struct passwd *uam_getname(char *name, const int len)
175 struct passwd *pwent;
179 if ((pwent = getpwnam(name)))
182 #ifndef NO_REAL_USER_NAME
183 for (i = 0; i < len; i++)
184 name[i] = tolower(name[i]);
187 while ((pwent = getpwent())) {
188 if (user = strchr(pwent->pw_gecos, ','))
190 user = pwent->pw_gecos;
192 /* check against both the gecos and the name fields. the user
193 * might have just used a different capitalization. */
194 if ((strncasecmp(user, name, len) == 0) ||
195 (strncasecmp(pwent->pw_name, name, len) == 0)) {
196 strncpy(name, pwent->pw_name, len);
203 /* os x server doesn't keep anything useful if we do getpwent */
204 return pwent ? getpwnam(name) : NULL;
208 int uam_checkuser(const struct passwd *pwd)
212 if (!pwd || !pwd->pw_shell || (*pwd->pw_shell == '\0'))
215 while ((p = getusershell())) {
216 if ( strcmp( p, pwd->pw_shell ) == 0 )
222 syslog( LOG_INFO, "illegal shell %s for %s",pwd->pw_shell,pwd->pw_name);