Date: Tue, 31 May 2005 11:38:38 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 77764 for review Message-ID: <200505311138.j4VBccAe021678@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=77764 Change 77764 by rwatson@rwatson_paprika on 2005/05/31 11:38:17 Converge on style(9). Affected files ... .. //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#4 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/libbsm/bsm_user.c#4 (text+ko) ==== @@ -34,14 +34,14 @@ #include <libbsm.h> /* - * Parse the contents of the audit_user file into au_user_ent structures + * Parse the contents of the audit_user file into au_user_ent structures. */ -static FILE *fp = NULL; -static char linestr[AU_LINE_MAX]; -static char *delim = ":"; +static FILE *fp = NULL; +static char linestr[AU_LINE_MAX]; +static char *delim = ":"; -static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* * XXX The reentrant versions of the following functions is TBD @@ -50,39 +50,41 @@ */ /* - * Allocate a user area structure + * Allocate a user area structure. */ -static struct au_user_ent *get_user_area() +static struct au_user_ent * +get_user_area(void) { struct au_user_ent *u; u = (struct au_user_ent *) malloc (sizeof(struct au_user_ent)); - if(u == NULL) { - return NULL; - } + if (u == NULL) + return (NULL); u->au_name = (char *)malloc(AU_USER_NAME_MAX * sizeof(char)); - if(u->au_name == NULL) { + if (u->au_name == NULL) { free(u); - return NULL; + return (NULL); } - return u; + return (u); } /* * Destroy a user area structure */ -static void destroy_user_area(struct au_user_ent *u) +static void +destroy_user_area(struct au_user_ent *u) { + free(u->au_name); free(u); } - /* - * Parse one line from the audit_user file into the au_user_ent structure + * Parse one line from the audit_user file into the au_user_ent structure. */ -static struct au_user_ent *userfromstr(char *str, char *delim, struct au_user_ent *u) +static struct au_user_ent * +userfromstr(char *str, char *delim, struct au_user_ent *u) { char *username, *always, *never; char *last; @@ -91,217 +93,189 @@ always = strtok_r(NULL, delim, &last); never = strtok_r(NULL, delim, &last); - if((username == NULL) - || (always == NULL) - || (never == NULL)) { + if ((username == NULL) || (always == NULL) || (never == NULL)) + return (NULL); - return NULL; - } + if (strlen(username) >= AU_USER_NAME_MAX) + return (NULL); - if(strlen(username) >= AU_USER_NAME_MAX) { - return NULL; - } - strcpy(u->au_name, username); - if(getauditflagsbin(always, &(u->au_always)) == -1) { - return NULL; - } + if (getauditflagsbin(always, &(u->au_always)) == -1) + return (NULL); - if(getauditflagsbin(never, &(u->au_never)) == -1) { - return NULL; - } + if (getauditflagsbin(never, &(u->au_never)) == -1) + return (NULL); - return u; + return (u); } /* * Rewind to beginning of the file */ -void setauuser() +void +setauuser(void) { + pthread_mutex_lock(&mutex); - - if(fp != NULL) { + if (fp != NULL) fseek(fp, 0, SEEK_SET); - } - pthread_mutex_unlock(&mutex); } /* * Close the file descriptor */ -void endauuser() +void +endauuser(void) { + pthread_mutex_lock(&mutex); - - if(fp != NULL) { + if (fp != NULL) { fclose(fp); fp = NULL; } - pthread_mutex_unlock(&mutex); } /* * Enumerate the au_user_ent structures from the file */ -struct au_user_ent *getauuserent() +struct au_user_ent * +getauuserent(void) { struct au_user_ent *u; char *nl; pthread_mutex_lock(&mutex); - if((fp == NULL) - && ((fp = fopen(AUDIT_USER_FILE, "r")) == NULL)) { - + if ((fp == NULL) && ((fp = fopen(AUDIT_USER_FILE, "r")) == NULL)) { pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } - if(fgets(linestr, AU_LINE_MAX, fp) == NULL) { - + if (fgets(linestr, AU_LINE_MAX, fp) == NULL) { pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } - /* Remove new lines */ - if((nl = strrchr(linestr, '\n')) != NULL) { + + /* Remove new lines. */ + if ((nl = strrchr(linestr, '\n')) != NULL) *nl = '\0'; - } u = get_user_area(); - if(u == NULL) { - + if (u == NULL) { pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } - /* Get the next structure */ - if(userfromstr(linestr, delim, u) == NULL) { - + /* Get the next structure. */ + if (userfromstr(linestr, delim, u) == NULL) { destroy_user_area(u); - pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } pthread_mutex_unlock(&mutex); - return u; + return (u); } /* - * Find a au_user_ent structure matching the given user name + * Find a au_user_ent structure matching the given user name. */ -struct au_user_ent *getauusernam(const char *name) +struct au_user_ent * +getauusernam(const char *name) { struct au_user_ent *u; char *nl; - if(name == NULL) { - return NULL; - } + if (name == NULL) + return (NULL); setauuser(); pthread_mutex_lock(&mutex); - if((fp == NULL) - && ((fp = fopen(AUDIT_USER_FILE, "r")) == NULL)) { - + if ((fp == NULL) && ((fp = fopen(AUDIT_USER_FILE, "r")) == NULL)) { pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } u = get_user_area(); - if(u == NULL) { - + if (u == NULL) { pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } - while(fgets(linestr, AU_LINE_MAX, fp) != NULL) { - /* Remove new lines */ - if((nl = strrchr(linestr, '\n')) != NULL) { + while (fgets(linestr, AU_LINE_MAX, fp) != NULL) { + /* Remove new lines. */ + if ((nl = strrchr(linestr, '\n')) != NULL) *nl = '\0'; - } - if(userfromstr(linestr, delim, u) != NULL) { - if(!strcmp(name, u->au_name)) { - + if (userfromstr(linestr, delim, u) != NULL) { + if (!strcmp(name, u->au_name)) { pthread_mutex_unlock(&mutex); - return u; + return (u); } } } destroy_user_area(u); - pthread_mutex_unlock(&mutex); - return NULL; + return (NULL); } /* - * Read the default system wide audit classes from audit_control, - * combine with the per-user audit class and update the - * binary preselection mask + * Read the default system wide audit classes from audit_control, combine with + * the per-user audit class and update the binary preselection mask. */ -int au_user_mask(char *username, au_mask_t *mask_p) +int +au_user_mask(char *username, au_mask_t *mask_p) { struct au_user_ent *u; char auditstring[MAX_AUDITSTRING_LEN + 1]; - /* get user mask */ - if((u = getauusernam(username)) != NULL) { - - if(-1 == getfauditflags(&u->au_always, &u->au_never, mask_p)) { - return -1; - } - - return 0; + /* Get user mask. */ + if ((u = getauusernam(username)) != NULL) { + if (-1 == getfauditflags(&u->au_always, &u->au_never, mask_p)) + return (-1); + return (0); } - /* read the default system mask */ - if(getacflg(auditstring, MAX_AUDITSTRING_LEN) == 0) { - if(-1 == getauditflagsbin(auditstring, mask_p)) { - return -1; - } - return 0; + /* Read the default system mask. */ + if (getacflg(auditstring, MAX_AUDITSTRING_LEN) == 0) { + if (-1 == getauditflagsbin(auditstring, mask_p)) + return (-1); + return (0); } - /* No masks defined */ - return -1; + /* No masks defined. */ + return (-1); } /* - * Generate the process audit state by combining the audit maks - * passed as parameters with the sustem audit masks + * Generate the process audit state by combining the audit maks passed as + * parameters with the sustem audit masks. */ -int getfauditflags(au_mask_t *usremask, au_mask_t *usrdmask, - au_mask_t *lastmask) +int +getfauditflags(au_mask_t *usremask, au_mask_t *usrdmask, au_mask_t *lastmask) { char auditstring[MAX_AUDITSTRING_LEN + 1]; - if((usremask == NULL) - || (usrdmask == NULL) - || (lastmask == NULL)) { + if ((usremask == NULL) || (usrdmask == NULL) || (lastmask == NULL)) + return (-1); - return -1; - } - lastmask->am_success = 0; lastmask->am_failure = 0; /* get the system mask */ - if(getacflg(auditstring, MAX_AUDITSTRING_LEN) == 0) { + if (getacflg(auditstring, MAX_AUDITSTRING_LEN) == 0) getauditflagsbin(auditstring, lastmask); - } ADDMASK(lastmask, usremask); SUBMASK(lastmask, usrdmask); - return 0; + return (0); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200505311138.j4VBccAe021678>