1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139
|
/*
* $Id: auth.c,v 1.9 2009-10-13 22:55:37 didg Exp $
*
* Copyright (c) 1990,1993 Regents of The University of Michigan.
* All Rights Reserved. See COPYRIGHT.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <netatalk/endian.h>
#include <atalk/afp.h>
#include <atalk/compat.h>
#include <atalk/util.h>
#include <limits.h>
#include <string.h>
#include <ctype.h>
#include <pwd.h>
#include <grp.h>
#include <atalk/logger.h>
#include "uam_auth.h"
static struct uam_mod uam_modules = {NULL, NULL, &uam_modules, &uam_modules};
static struct uam_obj uam_login = {"", "", 0, {{NULL, NULL, NULL}}, &uam_login,
&uam_login};
static struct uam_obj uam_changepw = {"", "", 0, {{NULL, NULL, NULL}}, &uam_changepw,
&uam_changepw};
static struct uam_obj uam_printer = {"", "", 0, {{NULL, NULL, NULL}}, &uam_printer,
&uam_printer};
/*
* Return a list of names for loaded uams
*/
int getuamnames(const int type, char *uamnames)
{
struct uam_obj *prev, *start;
if (!(start = UAM_LIST(type)))
return(-1);
prev = start;
while((prev = prev->uam_prev) != start) {
strcat(uamnames, prev->uam_name);
strcat(uamnames, "\n");
}
strcat(uamnames, "*\n");
return(0);
}
/* just do a linked list search. this could be sped up with a hashed
* list, but i doubt anyone's going to have enough uams to matter. */
struct uam_obj *auth_uamfind(const int type, const char *name,
const int len)
{
struct uam_obj *prev, *start;
if (!name || !(start = UAM_LIST(type)))
return NULL;
prev = start;
while ((prev = prev->uam_prev) != start)
if (strndiacasecmp(prev->uam_name, name, len) == 0)
return prev;
return NULL;
}
int auth_register(const int type, struct uam_obj *uam)
{
struct uam_obj *start;
if (!uam || !uam->uam_name || (*uam->uam_name == '\0'))
return -1;
if (!(start = UAM_LIST(type)))
return 1;
uam_attach(start, uam);
return 0;
}
/* load all of the modules */
int auth_load(const char *path, const char *list)
{
char name[MAXPATHLEN + 1], buf[MAXPATHLEN + 1], *p;
struct uam_mod *mod;
struct stat st;
size_t len;
if (!path || !list || (len = strlen(path)) > sizeof(name) - 2)
return -1;
strlcpy(buf, list, sizeof(buf));
if ((p = strtok(buf, ",")) == NULL)
return -1;
strcpy(name, path);
if (name[len - 1] != '/') {
strcat(name, "/");
len++;
}
while (p) {
strlcpy(name + len, p, sizeof(name) - len);
if ((stat(name, &st) == 0) && (mod = uam_load(name, p))) {
uam_attach(&uam_modules, mod);
LOG(log_info, logtype_papd, "uam: %s loaded", p);
}
p = strtok(NULL, ",");
}
return 0;
}
/* get rid of all of the uams */
void auth_unload(void)
{
struct uam_mod *mod, *prev, *start = &uam_modules;
prev = start->uam_prev;
while ((mod = prev) != start) {
prev = prev->uam_prev;
uam_detach(mod);
uam_unload(mod);
}
}
|