errcode_t KRB5_CALLCONV profile_init(const_profile_filespec_t *files, profile_t *ret_profile) { const_profile_filespec_t *fs; profile_t profile; prf_file_t new_file, last = 0; errcode_t retval = 0, access_retval = 0; profile = malloc(sizeof(struct _profile_t)); if (!profile) return ENOMEM; memset(profile, 0, sizeof(struct _profile_t)); profile->magic = PROF_MAGIC_PROFILE; /* * If the filenames list is not specified or empty, return an empty * profile. */ if ( files && !PROFILE_LAST_FILESPEC(*files) ) { for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) { retval = profile_open_file(*fs, &new_file); /* if this file is missing, skip to the next */ if (retval == ENOENT) { continue; } /* If we can't read this file, remember it but keep going. */ if (retval == EACCES || retval == EPERM) { access_retval = retval; continue; } if (retval) { profile_release(profile); return retval; } if (last) last->next = new_file; else profile->first_file = new_file; last = new_file; } /* * If last is still null after the loop, then all the files were * missing or unreadable, so return the appropriate error. */ if (!last) { profile_release(profile); return access_retval ? access_retval : ENOENT; } } *ret_profile = profile; return 0; }
errcode_t KRB5_CALLCONV profile_init_flags(const_profile_filespec_t *files, int flags, profile_t *ret_profile) { const_profile_filespec_t *fs; profile_t profile; prf_file_t new_file, last = 0; errcode_t retval = 0, access_retval = 0; char *modspec = NULL, **modspec_arg; profile = malloc(sizeof(struct _profile_t)); if (!profile) return ENOMEM; memset(profile, 0, sizeof(struct _profile_t)); profile->magic = PROF_MAGIC_PROFILE; /* * If the filenames list is not specified or empty, return an empty * profile. */ if ( files && !PROFILE_LAST_FILESPEC(*files) ) { for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) { /* Allow a module declaration if it is permitted by flags and this * is the first file parsed. */ modspec_arg = ((flags & PROFILE_INIT_ALLOW_MODULE) && !last) ? &modspec : NULL; retval = profile_open_file(*fs, &new_file, modspec_arg); if (retval == PROF_MODULE && modspec) { /* Stop parsing files and load a dynamic module instead. */ free(profile); retval = init_load_module(modspec, ret_profile); free(modspec); return retval; } /* if this file is missing, skip to the next */ if (retval == ENOENT) { continue; } /* If we can't read this file, remember it but keep going. */ if (retval == EACCES || retval == EPERM) { access_retval = retval; continue; } if (retval) { profile_release(profile); return retval; } if (last) last->next = new_file; else profile->first_file = new_file; last = new_file; } /* * If last is still null after the loop, then all the files were * missing or unreadable, so return the appropriate error. */ if (!last) { profile_release(profile); return access_retval ? access_retval : ENOENT; } } *ret_profile = profile; return 0; }
long profile_init(const char **files, profile_t *ret_profile) { const char **fs; profile_t profile; prf_file_t new_file, *last; long retval = 0; char **cpp, *cp, **array = 0; profile = malloc(sizeof(struct _profile_t)); if (!profile) return ENOMEM; memset(profile, 0, sizeof(struct _profile_t)); profile->magic = PROF_MAGIC_PROFILE; last = &profile->first_file; /* if the filenames list is not specified return an empty profile */ if ( files ) { for (fs = files; !PROFILE_LAST_FILESPEC(*fs); fs++) { retval = get_dirlist(*fs, &array); if (retval == 0) { if (!array) continue; for (cpp = array; (cp = *cpp); cpp++) { retval = profile_open_file(cp, &new_file); if (retval == EACCES) continue; if (retval) goto errout; *last = new_file; last = &new_file->next; } } else if ((retval != ENOTDIR) && strcmp(*fs, default_filename)) goto errout; retval = profile_open_file(*fs, &new_file); /* if this file is missing, skip to the next */ if (retval == ENOENT || retval == EACCES) { continue; } if (retval) goto errout; *last = new_file; last = &new_file->next; } /* * If all the files were not found, return the appropriate error. */ if (!profile->first_file) { profile_release(profile); return ENOENT; } } free_list(array); *ret_profile = profile; return 0; errout: free_list(array); profile_release(profile); return retval; }