diff options
author | Thorsten Kukuk <kukuk@thkukuk.de> | 2005-06-09 17:29:18 +0000 |
---|---|---|
committer | Thorsten Kukuk <kukuk@thkukuk.de> | 2005-06-09 17:29:18 +0000 |
commit | 0a7fe016a03184815b03fe92d50c58e67c8c05fc (patch) | |
tree | b9c25dd0fbbb71e08b2826e046b763facdcff8df /modules/pam_env | |
parent | fa433b9e2fa1a00e13df36a8b709ffda9e3e715b (diff) | |
download | pam-0a7fe016a03184815b03fe92d50c58e67c8c05fc.tar.gz pam-0a7fe016a03184815b03fe92d50c58e67c8c05fc.tar.bz2 pam-0a7fe016a03184815b03fe92d50c58e67c8c05fc.zip |
Relevant BUGIDs: none
Purpose of commit: cleanup
Commit summary:
---------------
Fix all occurrence of dereferencing type-punned pointer will break
strict-aliasing rules warnings
Diffstat (limited to 'modules/pam_env')
-rw-r--r-- | modules/pam_env/pam_env.c | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/modules/pam_env/pam_env.c b/modules/pam_env/pam_env.c index 2c93ebab..d05e33f8 100644 --- a/modules/pam_env/pam_env.c +++ b/modules/pam_env/pam_env.c @@ -4,7 +4,7 @@ * $Id$ * * Written by Dave Kinchlea <kinch@kinch.ark.com> 1997/01/31 - * Inspired by Andrew Morgan <morgan@kernel.org>, who also supplied the + * Inspired by Andrew Morgan <morgan@kernel.org>, who also supplied the * template for this file (via pam_mail) */ @@ -59,21 +59,21 @@ typedef struct var { #define GOOD_LINE 0 #define BAD_LINE 100 /* This must be > the largest PAM_* error code */ -#define DEFINE_VAR 101 +#define DEFINE_VAR 101 #define UNDEFINE_VAR 102 #define ILLEGAL_VAR 103 static int _assemble_line(FILE *, char *, int); static int _parse_line(char *, VAR *); static int _check_var(pam_handle_t *, VAR *); /* This is the real meat */ -static void _clean_var(VAR *); +static void _clean_var(VAR *); static int _expand_arg(pam_handle_t *, char **); static const char * _pam_get_item_byname(pam_handle_t *, const char *); static int _define_var(pam_handle_t *, VAR *); static int _undefine_var(pam_handle_t *, VAR *); /* This is a flag used to designate an empty string */ -static char quote='Z'; +static char quote='Z'; /* some syslogging */ @@ -141,7 +141,7 @@ static int _parse_config_file(pam_handle_t *pamh, int ctrl, char **conffile) const char *file; char buffer[BUF_SIZE]; FILE *conf; - VAR Var, *var=&Var; + VAR Var, *var=&Var; var->name=NULL; var->defval=NULL; var->override=NULL; D(("Called.")); @@ -154,13 +154,13 @@ static int _parse_config_file(pam_handle_t *pamh, int ctrl, char **conffile) D(("Config file name is: %s", file)); - /* - * Lets try to open the config file, parse it and process + /* + * Lets try to open the config file, parse it and process * any variables found. */ if ((conf = fopen(file,"r")) == NULL) { - _log_err(LOG_ERR, "Unable to open config file: %s", + _log_err(LOG_ERR, "Unable to open config file: %s", strerror(errno)); return PAM_IGNORE; } @@ -176,19 +176,19 @@ static int _parse_config_file(pam_handle_t *pamh, int ctrl, char **conffile) retval = _check_var(pamh, var); if (DEFINE_VAR == retval) { - retval = _define_var(pamh, var); + retval = _define_var(pamh, var); } else if (UNDEFINE_VAR == retval) { - retval = _undefine_var(pamh, var); - } - } - if (PAM_SUCCESS != retval && ILLEGAL_VAR != retval + retval = _undefine_var(pamh, var); + } + } + if (PAM_SUCCESS != retval && ILLEGAL_VAR != retval && BAD_LINE != retval && PAM_BAD_ITEM != retval) break; - - _clean_var(var); + + _clean_var(var); } /* while */ - + (void) fclose(conf); /* tidy up */ @@ -272,7 +272,7 @@ static int _parse_env_file(pam_handle_t *pamh, int ctrl, char **env_file) break; } } - + (void) fclose(conf); /* tidy up */ @@ -367,41 +367,41 @@ static int _assemble_line(FILE *f, char *buffer, int buf_len) static int _parse_line(char *buffer, VAR *var) { - /* - * parse buffer into var, legal syntax is + /* + * parse buffer into var, legal syntax is * VARIABLE [DEFAULT=[[string]] [OVERRIDE=[value]] * - * Any other options defined make this a bad line, + * Any other options defined make this a bad line, * error logged and no var set */ - + int length, quoteflg=0; - char *ptr, **valptr, *tmpptr; - + char *ptr, **valptr, *tmpptr; + D(("Called buffer = <%s>", buffer)); length = strcspn(buffer," \t\n"); - + if ((var->name = malloc(length + 1)) == NULL) { _log_err(LOG_ERR, "Couldn't malloc %d bytes", length+1); return PAM_BUF_ERR; } - - /* - * The first thing on the line HAS to be the variable name, + + /* + * The first thing on the line HAS to be the variable name, * it may be the only thing though. */ strncpy(var->name, buffer, length); var->name[length] = '\0'; D(("var->name = <%s>, length = %d", var->name, length)); - /* + /* * Now we check for arguments, we only support two kinds and ('cause I am lazy) * each one can actually be listed any number of times */ - + ptr = buffer+length; - while ((length = strspn(ptr, " \t")) > 0) { + while ((length = strspn(ptr, " \t")) > 0) { ptr += length; /* remove leading whitespace */ D((ptr)); if (strncmp(ptr,"DEFAULT=",8) == 0) { @@ -417,18 +417,18 @@ static int _parse_line(char *buffer, VAR *var) _log_err(LOG_ERR, "Unrecognized Option: %s - ignoring line", ptr); return BAD_LINE; } - + if ('"' != *ptr) { /* Escaped quotes not supported */ length = strcspn(ptr, " \t\n"); tmpptr = ptr+length; } else { - tmpptr = strchr(++ptr, '"'); + tmpptr = strchr(++ptr, '"'); if (!tmpptr) { D(("Unterminated quoted string: %s", ptr-1)); _log_err(LOG_ERR, "Unterminated quoted string: %s", ptr-1); return BAD_LINE; } - length = tmpptr - ptr; + length = tmpptr - ptr; if (*++tmpptr && ' ' != *tmpptr && '\t' != *tmpptr && '\n' != *tmpptr) { D(("Quotes must cover the entire string: <%s>", ptr)); _log_err(LOG_ERR, "Quotes must cover the entire string: <%s>", ptr); @@ -449,11 +449,11 @@ static int _parse_line(char *buffer, VAR *var) } ptr = tmpptr; /* Start the search where we stopped */ } /* while */ - - /* + + /* * The line is parsed, all is well. */ - + D(("Exit.")); ptr = NULL; tmpptr = NULL; valptr = NULL; return GOOD_LINE; @@ -461,16 +461,16 @@ static int _parse_line(char *buffer, VAR *var) static int _check_var(pam_handle_t *pamh, VAR *var) { - /* - * Examine the variable and determine what action to take. + /* + * Examine the variable and determine what action to take. * Returns DEFINE_VAR, UNDEFINE_VAR depending on action to take * or a PAM_* error code if passed back from other routines * * if no DEFAULT provided, the empty string is assumed * if no OVERRIDE provided, the empty string is assumed - * if DEFAULT= and OVERRIDE evaluates to the empty string, + * if DEFAULT= and OVERRIDE evaluates to the empty string, * this variable should be undefined - * if DEFAULT="" and OVERRIDE evaluates to the empty string, + * if DEFAULT="" and OVERRIDE evaluates to the empty string, * this variable should be defined with no value * if OVERRIDE=value and value turns into the empty string, DEFAULT is used * @@ -498,18 +498,18 @@ static int _check_var(pam_handle_t *pamh, VAR *var) } /* Now its easy */ - - if (var->override && *(var->override) && "e != var->override) { + + if (var->override && *(var->override) && "e != var->override) { /* if there is a non-empty string in var->override, we use it */ D(("OVERRIDE variable <%s> being used: <%s>", var->name, var->override)); var->value = var->override; retval = DEFINE_VAR; } else { - + var->value = var->defval; if ("e == var->defval) { - /* - * This means that the empty string was given for defval value + /* + * This means that the empty string was given for defval value * which indicates that a variable should be defined with no value */ *var->defval = '\0'; @@ -531,12 +531,12 @@ static int _check_var(pam_handle_t *pamh, VAR *var) static int _expand_arg(pam_handle_t *pamh, char **value) { const char *orig=*value, *tmpptr=NULL; - char *ptr; /* - * Sure would be nice to use tmpptr but it needs to be + char *ptr; /* + * Sure would be nice to use tmpptr but it needs to be * a constant so that the compiler will shut up when I * call pam_getenv and _pam_get_item_byname -- sigh */ - + /* No unexpanded variable can be bigger than BUF_SIZE */ char type, tmpval[BUF_SIZE]; @@ -546,11 +546,11 @@ static int _expand_arg(pam_handle_t *pamh, char **value) D(("Remember to initialize tmp!")); memset(tmp, 0, MAX_ENV); - /* + /* * (possibly non-existent) environment variables can be used as values * by prepending a "$" and wrapping in {} (ie: ${HOST}), can escape with "\" - * (possibly non-existent) PAM items can be used as values - * by prepending a "@" and wrapping in {} (ie: @{PAM_RHOST}, can escape + * (possibly non-existent) PAM items can be used as values + * by prepending a "@" and wrapping in {} (ie: @{PAM_RHOST}, can escape * */ D(("Expanding <%s>",orig)); @@ -559,7 +559,7 @@ static int _expand_arg(pam_handle_t *pamh, char **value) ++orig; if ('$' != *orig && '@' != *orig) { D(("Unrecognized escaped character: <%c> - ignoring", *orig)); - _log_err(LOG_ERR, "Unrecognized escaped character: <%c> - ignoring", + _log_err(LOG_ERR, "Unrecognized escaped character: <%c> - ignoring", *orig); } else if ((strlen(tmp) + 1) < MAX_ENV) { tmp[strlen(tmp)] = *orig++; /* Note the increment */ @@ -570,7 +570,7 @@ static int _expand_arg(pam_handle_t *pamh, char **value) tmp, tmpptr); } continue; - } + } if ('$' == *orig || '@' == *orig) { if ('{' != *(orig+1)) { D(("Expandable variables must be wrapped in {}" @@ -586,7 +586,7 @@ static int _expand_arg(pam_handle_t *pamh, char **value) type = *orig; orig+=2; /* skip the ${ or @{ characters */ ptr = strchr(orig, '}'); - if (ptr) { + if (ptr) { *ptr++ = '\0'; } else { D(("Unterminated expandable variable: <%s>", orig-2)); @@ -596,18 +596,18 @@ static int _expand_arg(pam_handle_t *pamh, char **value) strncpy(tmpval, orig, sizeof(tmpval)); tmpval[sizeof(tmpval)-1] = '\0'; orig=ptr; - /* - * so, we know we need to expand tmpval, it is either + /* + * so, we know we need to expand tmpval, it is either * an environment variable or a PAM_ITEM. type will tell us which */ switch (type) { - + case '$': D(("Expanding env var: <%s>",tmpval)); tmpptr = pam_getenv(pamh, tmpval); D(("Expanded to <%s>", tmpptr)); break; - + case '@': D(("Expanding pam item: <%s>",tmpval)); tmpptr = _pam_get_item_byname(pamh, tmpval); @@ -619,7 +619,7 @@ static int _expand_arg(pam_handle_t *pamh, char **value) _log_err(LOG_CRIT, "Impossible error, type == <%c>", type); return PAM_ABORT; } /* switch */ - + if (tmpptr) { if ((strlen(tmp) + strlen(tmpptr)) < MAX_ENV) { strcat(tmp, tmpptr); @@ -659,13 +659,13 @@ static int _expand_arg(pam_handle_t *pamh, char **value) static const char * _pam_get_item_byname(pam_handle_t *pamh, const char *name) { - /* + /* * This function just allows me to use names as given in the config * file and translate them into the appropriate PAM_ITEM macro */ int item; - const char *itemval; + const void *itemval; D(("Called.")); if (strcmp(name, "PAM_USER") == 0) { @@ -683,8 +683,8 @@ static const char * _pam_get_item_byname(pam_handle_t *pamh, const char *name) _log_err(LOG_ERR, "Unknown PAM_ITEM: <%s>", name); return NULL; } - - if (pam_get_item(pamh, item, (const void **)&itemval) != PAM_SUCCESS) { + + if (pam_get_item(pamh, item, &itemval) != PAM_SUCCESS) { D(("pam_get_item failed")); return NULL; /* let pam_get_item() log the error */ } @@ -695,10 +695,10 @@ static const char * _pam_get_item_byname(pam_handle_t *pamh, const char *name) static int _define_var(pam_handle_t *pamh, VAR *var) { /* We have a variable to define, this is a simple function */ - + char *envvar; int size, retval=PAM_SUCCESS; - + D(("Called.")); size = strlen(var->name)+strlen(var->value)+2; if ((envvar = malloc(size)) == NULL) { @@ -716,7 +716,7 @@ static int _define_var(pam_handle_t *pamh, VAR *var) static int _undefine_var(pam_handle_t *pamh, VAR *var) { /* We have a variable to undefine, this is a simple function */ - + D(("Called and exit.")); return pam_putenv(pamh, var->name); } @@ -724,13 +724,13 @@ static int _undefine_var(pam_handle_t *pamh, VAR *var) static void _clean_var(VAR *var) { if (var->name) { - free(var->name); + free(var->name); } if (var->defval && ("e != var->defval)) { - free(var->defval); + free(var->defval); } if (var->override && ("e != var->override)) { - free(var->override); + free(var->override); } var->name = NULL; var->value = NULL; /* never has memory specific to it */ @@ -746,12 +746,12 @@ static void _clean_var(VAR *var) PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, const char **argv) -{ +{ return PAM_IGNORE; } -PAM_EXTERN -int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, +PAM_EXTERN +int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, const char **argv) { int retval, ctrl, readenv=DEFAULT_READ_ENVFILE; @@ -760,7 +760,7 @@ int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, /* * this module sets environment variables read in from a file */ - + D(("Called.")); ctrl = _pam_parse(flags, argc, argv, &conf_file, &env_file, &readenv); @@ -770,40 +770,40 @@ int pam_sm_setcred(pam_handle_t *pamh, int flags, int argc, retval = _parse_env_file(pamh, ctrl, &env_file); /* indicate success or failure */ - + D(("Exit.")); return retval; } -PAM_EXTERN -int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, +PAM_EXTERN +int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) { _log_err(LOG_NOTICE, "pam_sm_acct_mgmt called inappropriatly"); return PAM_SERVICE_ERR; } - + PAM_EXTERN int pam_sm_open_session(pam_handle_t *pamh,int flags,int argc ,const char **argv) { int retval, ctrl, readenv=DEFAULT_READ_ENVFILE; char *conf_file=NULL, *env_file=NULL; - + /* * this module sets environment variables read in from a file */ - + D(("Called.")); ctrl = _pam_parse(flags, argc, argv, &conf_file, &env_file, &readenv); - + retval = _parse_config_file(pamh, ctrl, &conf_file); - + if(readenv && retval == PAM_SUCCESS) retval = _parse_env_file(pamh, ctrl, &env_file); /* indicate success or failure */ - + D(("Exit.")); return retval; } @@ -816,8 +816,8 @@ int pam_sm_close_session(pam_handle_t *pamh,int flags,int argc, return PAM_SUCCESS; } -PAM_EXTERN -int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, +PAM_EXTERN +int pam_sm_chauthtok(pam_handle_t *pamh, int flags, int argc, const char **argv) { _log_err(LOG_NOTICE, "pam_sm_chauthtok called inappropriatly"); |