/* * Return the next au_class_ent structure from the file setauclass should be * called before invoking this function for the first time. * * Must be called with mutex held. */ static struct au_class_ent * getauclassent_r_locked(struct au_class_ent *c) { char *tokptr, *nl; if ((fp == NULL) && ((fp = fopen(AUDIT_CLASS_FILE, "r")) == NULL)) return (NULL); /* * Read until next non-comment line is found, or EOF. */ while (1) { if (fgets(linestr, AU_LINE_MAX, fp) == NULL) return (NULL); /* Skip comments. */ if (linestr[0] == '#') continue; /* Remove trailing new line character. */ if ((nl = strrchr(linestr, '\n')) != NULL) *nl = '\0'; /* Parse tokptr to au_class_ent components. */ tokptr = linestr; if (classfromstr(tokptr, c) == NULL) return (NULL); break; } return (c); }
/* * Return the next au_class_entry having the given class name */ struct au_class_ent *getauclassnam(const char *name) { struct au_class_ent *c; char *nl; if(name == NULL) { return NULL; } /* Rewind to beginning of file */ setauclass(); pthread_mutex_lock(&mutex); if((fp == NULL) && ((fp = fopen(AUDIT_CLASS_FILE, "r")) == NULL)) { pthread_mutex_unlock(&mutex); return NULL; } c = get_class_area(); /* allocate */ if(c == NULL) { pthread_mutex_unlock(&mutex); return NULL; } while(fgets(linestr, AU_LINE_MAX, fp) != NULL) { /* Remove trailing new line character */ if((nl = strrchr(linestr, '\n')) != NULL) { *nl = '\0'; } /* parse tokptr to au_class_ent components */ if(classfromstr(linestr, delim, c) != NULL) { if(!strcmp(name, c->ac_name)) { pthread_mutex_unlock(&mutex); return c; } } } free_au_class_ent(c); pthread_mutex_unlock(&mutex); return NULL; }
/* * Return the next au_class_ent structure from the file * setauclass should be called before invoking this function * for the first time */ struct au_class_ent *getauclassent() { struct au_class_ent *c; char *tokptr, *nl; pthread_mutex_lock(&mutex); if((fp == NULL) && ((fp = fopen(AUDIT_CLASS_FILE, "r")) == NULL)) { pthread_mutex_unlock(&mutex); return NULL; } if(fgets(linestr, AU_LINE_MAX, fp) == NULL) { pthread_mutex_unlock(&mutex); return NULL; } /* Remove trailing new line character */ if((nl = strrchr(linestr, '\n')) != NULL) { *nl = '\0'; } tokptr = linestr; c = get_class_area(); /* allocate */ if(c == NULL) { pthread_mutex_unlock(&mutex); return NULL; } /* parse tokptr to au_class_ent components */ if(classfromstr(tokptr, delim, c) == NULL) { free_au_class_ent(c); pthread_mutex_unlock(&mutex); return NULL; } pthread_mutex_unlock(&mutex); return c; }