/* * This routine descends through a path to a directory, logging to * every cell it encounters along the way. */ static int auth_to_path(krb5_context context, char *path) { int status = AKLOG_SUCCESS; int auth_to_cell_status = AKLOG_SUCCESS; char *nextpath; char pathtocheck[MAXPATHLEN + 1]; char mountpoint[MAXPATHLEN + 1]; char *cell; char *endofcell; /* Initialize */ if (BeginsWithDir(path, TRUE)) strcpy(pathtocheck, path); else { if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL) { fprintf(stderr, "Unable to find current working directory:\n"); fprintf(stderr, "%s\n", pathtocheck); fprintf(stderr, "Try an absolute pathname.\n"); akexit(AKLOG_BADPATH); } else { /* in WIN32, if getcwd returns a root dir (eg: c:\), the returned string * will already have a trailing slash ('\'). Otherwise, the string will * end in the last directory name */ #ifdef WIN32 if(pathtocheck[strlen(pathtocheck) - 1] != BDIR) #endif strcat(pathtocheck, DIRSTRING); strcat(pathtocheck, path); } } next_path(pathtocheck); /* Go on to the next level down the path */ while (nextpath = next_path(NULL)) { strcpy(pathtocheck, nextpath); if (dflag) printf("Checking directory [%s]\n", pathtocheck); /* * If this is an afs mountpoint, determine what cell from * the mountpoint name which is of the form * #cellname:volumename or %cellname:volumename. */ if (get_afs_mountpoint(pathtocheck, mountpoint, sizeof(mountpoint))) { if(dflag) printf("Found mount point [%s]\n", mountpoint); /* skip over the '#' or '%' */ cell = mountpoint + 1; if (endofcell = strchr(mountpoint, VOLMARKER)) { *endofcell = '\0'; if (auth_to_cell_status = auth_to_cell(context, cell, NULL)) { if (status == AKLOG_SUCCESS) status = auth_to_cell_status; else if (status != auth_to_cell_status) status = AKLOG_SOMETHINGSWRONG; } } } else { struct stat st; if (lstat(pathtocheck, &st) < 0) { /* * If we've logged and still can't stat, there's * a problem... */ fprintf(stderr, "%s: stat(%s): %s\n", progname, pathtocheck, strerror(errno)); return(AKLOG_BADPATH); } else if (!S_ISDIR(st.st_mode)) { /* Allow only directories */ fprintf(stderr, "%s: %s: %s\n", progname, pathtocheck, strerror(ENOTDIR)); return(AKLOG_BADPATH); } } } return(status); }
/* * This routine descends through a path to a directory, logging to * every cell it encounters along the way. */ static int auth_to_path(char *path) { int status = AKLOG_SUCCESS; int auth_to_cell_status = AKLOG_SUCCESS; char *nextpath; char pathtocheck[MAXPATHLEN + 1]; char mountpoint[MAXPATHLEN + 1]; char *cell; char *endofcell; /* Initialize */ if (path[0] == DIR) strcpy(pathtocheck, path); else { if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL) { fprintf(stderr, "Unable to find current working directory:\n"); fprintf(stderr, "%s\n", pathtocheck); fprintf(stderr, "Try an absolute pathname.\n"); exit(AKLOG_BADPATH); } else { strcat(pathtocheck, DIRSTRING); strcat(pathtocheck, path); } } next_path(pathtocheck); /* Go on to the next level down the path */ while (nextpath = next_path(NULL)) { strcpy(pathtocheck, nextpath); if (dflag) printf("Checking directory %s\n", pathtocheck); /* * If this is an afs mountpoint, determine what cell from * the mountpoint name which is of the form * #cellname:volumename or %cellname:volumename. */ if (get_afs_mountpoint(pathtocheck, mountpoint, sizeof(mountpoint))) { /* skip over the '#' or '%' */ cell = mountpoint + 1; if (endofcell = strchr(mountpoint, VOLMARKER)) { *endofcell = '\0'; if (auth_to_cell_status = auth_to_cell(cell, NULL)) { if (status == AKLOG_SUCCESS) status = auth_to_cell_status; else if (status != auth_to_cell_status) status = AKLOG_SOMETHINGSWRONG; } } } else { struct stat st; if (lstat(pathtocheck, &st) < 0) { /* * If we've logged and still can't stat, there's * a problem... */ fprintf(stderr, "%s: stat(%s): %s\n", progname, pathtocheck, strerror(errno)); return(AKLOG_BADPATH); } else if (!S_ISDIR(st.st_mode)) { /* Allow only directories */ fprintf(stderr, "%s: %s: %s\n", progname, pathtocheck, strerror(ENOTDIR)); return(AKLOG_BADPATH); } } } return(status); }