buf, buflen);
}
-
-/****************************************
- * user mapping database handling *
- * (very rudiment) *
- ****************************************/
-
-#define MAPPING_GROW_SIZE 512
-#define MAX_LINE_LEN 256
-
-struct user_map_item {
- char *principal; /* NULL means match all */
- lnet_nid_t nid;
- uid_t uid;
-};
-
-struct user_mapping {
- int nitems;
- struct user_map_item *items;
-};
-
-static struct user_mapping mapping;
-/* FIXME to be finished: monitor change of mapping database */
-static int mapping_mtime;
-
-void cleanup_mapping(void)
-{
- if (mapping.items) {
- for (; mapping.nitems > 0; mapping.nitems--)
- if (mapping.items[mapping.nitems-1].principal)
- free(mapping.items[mapping.nitems-1].principal);
-
- free(mapping.items);
- mapping.items = NULL;
- }
-}
-
-static int grow_mapping(int nitems)
-{
- struct user_map_item *new;
- int oldsize, newsize;
-
- oldsize = (mapping.nitems * sizeof(struct user_map_item) +
- MAPPING_GROW_SIZE - 1) / MAPPING_GROW_SIZE;
- newsize = (nitems * sizeof(struct user_map_item) +
- MAPPING_GROW_SIZE - 1) / MAPPING_GROW_SIZE;
- while (newsize <= oldsize)
- return 0;
-
- newsize *= MAPPING_GROW_SIZE;
- new = malloc(newsize);
- if (!new) {
- printerr(LL_ERR, "can't alloc mapping size %d\n", newsize);
- return -1;
- }
-
- if (mapping.items) {
- memcpy(new, mapping.items,
- mapping.nitems * sizeof(struct user_map_item));
- free(mapping.items);
- }
- mapping.items = new;
- return 0;
-}
-
uid_t parse_uid(char *uidstr)
{
struct passwd *pw;
return -1;
}
-static int read_mapping_db(void)
-{
- char princ[MAX_LINE_LEN];
- char nid_str[MAX_LINE_LEN];
- char dest[MAX_LINE_LEN];
- char linebuf[MAX_LINE_LEN];
- char *line;
- lnet_nid_t nid;
- uid_t dest_uid;
- FILE *f;
-
- /* cleanup old mappings */
- cleanup_mapping();
-
- f = fopen(MAPPING_DATABASE_FILE, "r");
- if (!f) {
- printerr(LL_ERR, "can't open mapping database: %s\n",
- MAPPING_DATABASE_FILE);
- return -1;
- }
-
- while ((line = fgets(linebuf, MAX_LINE_LEN, f)) != NULL) {
- char *name;
-
- if (sscanf(line, "%s %s %s", princ, nid_str, dest) != 3) {
- printerr(LL_ERR, "mapping db: syntax error\n");
- continue;
- }
-
- if (!strcmp(princ, "*")) {
- name = NULL;
- } else {
- name = strdup(princ);
- if (!name) {
- printerr(LL_ERR, "fail to dup str %s\n", princ);
- continue;
- }
- }
-
- if (!strcmp(nid_str, "*")) {
- nid = LNET_NID_ANY;
- } else {
- nid = libcfs_str2nid(nid_str);
- if (nid == LNET_NID_ANY) {
- printerr(LL_ERR, "fail to parse nid %s\n",
- nid_str);
- if (name)
- free(name);
- continue;
- }
- }
-
- dest_uid = parse_uid(dest);
- if (dest_uid == -1) {
- printerr(LL_ERR, "no valid user: %s\n", dest);
- if (name)
- free(name);
- continue;
- }
-
- if (grow_mapping(mapping.nitems + 1)) {
- printerr(LL_ERR, "fail to grow mapping to %d\n",
- mapping.nitems + 1);
- if (name)
- free(name);
- fclose(f);
- return -1;
- }
-
- mapping.items[mapping.nitems].principal = name;
- mapping.items[mapping.nitems].nid = nid;
- mapping.items[mapping.nitems].uid = dest_uid;
- mapping.nitems++;
- printerr(LL_WARN, "add mapping: %s(%s/0x%llx) ==> %d\n",
- name, nid_str, nid, dest_uid);
- }
-
- fclose(f);
- return 0;
-}
-
-static inline int mapping_changed(void)
-{
- struct stat st;
-
- if (stat(MAPPING_DATABASE_FILE, &st) == -1) {
- /* stat failed, treat it like doesn't exist or be removed */
- if (mapping_mtime == 0)
- return 0;
-
- printerr(LL_ERR, "stat %s failed: %s\n",
- MAPPING_DATABASE_FILE, strerror(errno));
-
- mapping_mtime = 0;
- return 1;
- }
- printerr(LL_WARN,
- "Use of idmap.conf is deprecated.\nPlease consider switching to auth_to_local or equivalent as provided by Kerberos for cross-realm trust remapping.\n");
-
- if (st.st_mtime != mapping_mtime) {
- mapping_mtime = st.st_mtime;
- return 1;
- }
-
- return 0;
-}
-
-void load_mapping(void)
-{
- if (mapping_changed())
- (void)read_mapping_db();
-}
-
-int mapping_empty(void)
-{
- return !mapping.nitems;
-}
-
-int lookup_mapping(char *princ, lnet_nid_t nid, uid_t *uid)
-{
- int n;
-
- *uid = -1;
-
- /* FIXME race condition here */
- if (mapping_changed()) {
- if (read_mapping_db())
- printerr(LL_ERR, "all remote users will be denied\n");
- }
-
- for (n = 0; n < mapping.nitems; n++) {
- struct user_map_item *entry = &mapping.items[n];
-
- if (entry->nid != LNET_NID_ANY && entry->nid != nid)
- continue;
- if (!entry->principal || !strcasecmp(entry->principal, princ)) {
- printerr(LL_WARN, "found mapping: %s ==> %d\n",
- princ, entry->uid);
- *uid = entry->uid;
- return 0;
- }
- }
-
- printerr(LL_INFO, "no mapping for %s/%#Lx\n", princ, nid);
- return -1;
-}
-
/* realm of this node */
char *krb5_this_realm;