/* This routine maintains a list of strings preventing duplication. */ int ll_add_string(linked_list *list, char *string) { ll_node *node; char *new_string; if (!ll_string_check(list, string)) { node = ll_add_node(list, ll_tail); if (node) { new_string = strdup(string); if (new_string) ll_add_data(node, new_string); else return LL_FAILURE; } else return LL_FAILURE; } return LL_SUCCESS; }
/* This routine maintains a list of strings preventing duplication. */ int ll_string(linked_list *list, ll_s_action action, char *string) { int status = LL_SUCCESS; ll_node *cur_node; switch(action) { case ll_s_check: /* Scan the list until we find the string in question */ for (cur_node = list->first; cur_node && (status == FALSE); cur_node = cur_node->next) status = (strcmp(string, cur_node->data) == 0); break; case ll_s_add: /* Add a string to the list. */ if (!ll_string(list, ll_s_check, string)) { if ((cur_node = ll_add_node(list, ll_tail))) { char *new_string; if ((new_string = (char *)calloc(strlen(string) + 1, sizeof(char)))) { strcpy(new_string, string); ll_add_data(cur_node, new_string); } else status = LL_FAILURE; } else status = LL_FAILURE; } break; default: /* This should never happen */ status = LL_FAILURE; break; } return(status); }
int main(int argc, char *argv[]) { int status = AKLOG_SUCCESS; int i; int somethingswrong = FALSE; cellinfo_t cellinfo; extern char *progname; /* Name of this program */ extern int dflag; /* Debug mode */ int cmode = FALSE; /* Cellname mode */ int pmode = FALSE; /* Path name mode */ char realm[REALM_SZ]; /* Kerberos realm of afs server */ char cell[BUFSIZ]; /* Cell to which we are authenticating */ char path[MAXPATHLEN + 1]; /* Path length for path mode */ linked_list cells; /* List of cells to log to */ linked_list paths; /* List of paths to log to */ ll_node *cur_node; memset(&cellinfo, 0, sizeof(cellinfo)); memset(realm, 0, sizeof(realm)); memset(cell, 0, sizeof(cell)); memset(path, 0, sizeof(path)); ll_init(&cells); ll_init(&paths); /* Store the program name here for error messages */ if (progname = LastComponent(argv[0])) progname++; else progname = argv[0]; /* Initialize list of cells to which we have authenticated */ (void)ll_init(&authedcells); /* Parse commandline arguments and make list of what to do. */ for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-d") == 0) dflag++; else if (strcmp(argv[i], "-5") == 0) usev5++; #ifdef HAVE_KRB4 else if (strcmp(argv[i], "-m") == 0) use524++; else if (strcmp(argv[i], "-4") == 0) usev5 = 0; #endif else if (strcmp(argv[i], "-noprdb") == 0) noprdb++; else if (strcmp(argv[i], "-force") == 0) force++; else if (((strcmp(argv[i], "-cell") == 0) || (strcmp(argv[i], "-c") == 0)) && !pmode) { if (++i < argc) { cmode++; strcpy(cell, argv[i]); } else usage(); } else if (((strcmp(argv[i], "-path") == 0) || (strcmp(argv[i], "-p") == 0)) && !cmode) { if (++i < argc) { pmode++; strcpy(path, argv[i]); } else usage(); } else if (argv[i][0] == '-') usage(); else if (!pmode && !cmode) { if (FirstComponent(argv[i]) || (strcmp(argv[i], ".") == 0) || (strcmp(argv[i], "..") == 0)) { pmode++; strcpy(path, argv[i]); } else { cmode++; strcpy(cell, argv[i]); } } else usage(); if (cmode) { if (((i + 1) < argc) && (strcmp(argv[i + 1], "-k") == 0)) { i += 2; if (i < argc) strcpy(realm, argv[i]); else usage(); } /* Add this cell to list of cells */ strcpy(cellinfo.cell, cell); strcpy(cellinfo.realm, realm); if (cur_node = ll_add_node(&cells, ll_tail)) { char *new_cellinfo; if (new_cellinfo = copy_cellinfo(&cellinfo)) ll_add_data(cur_node, new_cellinfo); else { fprintf(stderr, "%s: failure copying cellinfo.\n", progname); akexit(AKLOG_MISC); } } else { fprintf(stderr, "%s: failure adding cell to cells list.\n", progname); akexit(AKLOG_MISC); } memset(&cellinfo, 0, sizeof(cellinfo)); cmode = FALSE; memset(cell, 0, sizeof(cell)); memset(realm, 0, sizeof(realm)); } else if (pmode) { /* Add this path to list of paths */ if (cur_node = ll_add_node(&paths, ll_tail)) { char *new_path; if (new_path = strdup(path)) ll_add_data(cur_node, new_path); else { fprintf(stderr, "%s: failure copying path name.\n", progname); akexit(AKLOG_MISC); } } else { fprintf(stderr, "%s: failure adding path to paths list.\n", progname); akexit(AKLOG_MISC); } pmode = FALSE; memset(path, 0, sizeof(path)); } } if (!noprdb) initialize_PT_error_table(); if (usev5) { validate_krb5_availability(); if (krb5_init_context(&context)) return(AKLOG_KERBEROS); load_krb5_error_message_funcs(); } else validate_krb4_availability(); afs_set_com_err_hook(redirect_errors); /* If nothing was given, log to the local cell. */ if ((cells.nelements + paths.nelements) == 0) status = auth_to_cell(context, NULL, NULL); else { /* Log to all cells in the cells list first */ for (cur_node = cells.first; cur_node; cur_node = cur_node->next) { memcpy(&cellinfo, cur_node->data, sizeof(cellinfo)); if (status = auth_to_cell(context, cellinfo.cell, cellinfo.realm)) somethingswrong++; } /* Then, log to all paths in the paths list */ for (cur_node = paths.first; cur_node; cur_node = cur_node->next) { if (status = auth_to_path(context, cur_node->data)) somethingswrong++; } /* * If only one thing was logged to, we'll return the status * of the single call. Otherwise, we'll return a generic * something failed status. */ if (somethingswrong && ((cells.nelements + paths.nelements) > 1)) status = AKLOG_SOMETHINGSWRONG; } akexit(status); }