diff options
author | Philip Prindeville <philipp@redfish-solutions.com> | 2017-11-14 10:52:07 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-14 10:52:07 -0700 |
commit | d9a6d4bb831a04c63ae146d23da2b4619d3bb710 (patch) | |
tree | e5530231071cd3fc63e9dfd3ea0a7b3fda6789dc | |
parent | 27647d1b44c889eebe43df92b4b1b476e5766c87 (diff) | |
parent | 310326e1fd32d403650123182926b6b22e0fd1cf (diff) | |
download | pam_tacplus-d9a6d4bb831a04c63ae146d23da2b4619d3bb710.tar.gz pam_tacplus-d9a6d4bb831a04c63ae146d23da2b4619d3bb710.zip |
Merge pull request #100 from martin-belanger/simplified_vsa
A few improvements
-rw-r--r-- | pam_tacplus.c | 36 |
1 files changed, 16 insertions, 20 deletions
diff --git a/pam_tacplus.c b/pam_tacplus.c index 324cd5d..198d096 100644 --- a/pam_tacplus.c +++ b/pam_tacplus.c @@ -654,33 +654,29 @@ int pam_sm_acct_mgmt(pam_handle_t * pamh, int flags, int argc, attr = arep.attr; while (attr != NULL) { - char attribute[attr->attr_len]; - char value[attr->attr_len]; - char *sep; - - sep = index(attr->attr, '='); - if (sep == NULL) - sep = index(attr->attr, '*'); - if (sep != NULL) { - bcopy(attr->attr, attribute, attr->attr_len - strlen(sep)); - attribute[attr->attr_len - strlen(sep)] = '\0'; - bcopy(sep, value, strlen(sep)); - value[strlen(sep)] = '\0'; + size_t len = strcspn(attr->attr, "=*"); + if (len < attr->attr_len) { + char avpair[attr->attr_len+1]; + bcopy(attr->attr, avpair, attr->attr_len+1); /* Also copy terminating NUL */ + if (ctrl & PAM_TAC_DEBUG) + syslog(LOG_DEBUG, "%s: returned attribute `%s' from server", + __FUNCTION__, avpair); + + avpair[len] = '='; // replace '*' by '=' size_t i; - for (i = 0; attribute[i] != '\0'; i++) { - attribute[i] = toupper(attribute[i]); - if (attribute[i] == '-') - attribute[i] = '_'; + for (i = 0; i < len; i++) { + avpair[i] = toupper(avpair[i]); + if (avpair[i] == '-') + avpair[i] = '_'; } if (ctrl & PAM_TAC_DEBUG) - syslog(LOG_DEBUG, "%s: returned attribute `%s%s' from server", - __FUNCTION__, attribute, value); + syslog(LOG_DEBUG, "%s: setting PAM environment `%s'", + __FUNCTION__, avpair); /* make returned attributes available for other PAM modules via PAM environment */ - if (pam_putenv(pamh, - strncat(attribute, value, strlen(value))) != PAM_SUCCESS) + if (pam_putenv(pamh, avpair) != PAM_SUCCESS) syslog(LOG_WARNING, "%s: unable to set PAM environment", __FUNCTION__); |