/*ARGSUSED*/ int files_getpwnam(char *name, attrlist *items, pwu_repository_t *rep, void **buf) { attrlist *p; struct pwbuf *pwbuf; int err = PWU_SUCCESS; *buf = calloc(1, sizeof (struct pwbuf)); pwbuf = (struct pwbuf *)*buf; if (pwbuf == NULL) return (PWU_NOMEM); /* * determine which password structure (/etc/passwd or /etc/shadow) * we need for the items we need to update */ for (p = items; p != NULL; p = p->next) { switch (p->type) { case ATTR_NAME: case ATTR_UID: case ATTR_GID: case ATTR_AGE: case ATTR_COMMENT: case ATTR_GECOS: case ATTR_HOMEDIR: case ATTR_SHELL: if (pwbuf->pwd == NULL) { pwbuf->pwd = malloc(sizeof (struct passwd)); if (pwbuf->pwd == NULL) { err = PWU_NOMEM; goto error; } } break; case ATTR_PASSWD: case ATTR_PASSWD_SERVER_POLICY: case ATTR_LSTCHG: case ATTR_MIN: case ATTR_MAX: case ATTR_WARN: case ATTR_INACT: case ATTR_EXPIRE: case ATTR_FLAG: case ATTR_LOCK_ACCOUNT: case ATTR_EXPIRE_PASSWORD: case ATTR_FAILED_LOGINS: case ATTR_INCR_FAILED_LOGINS: case ATTR_RST_FAILED_LOGINS: case ATTR_NOLOGIN_ACCOUNT: case ATTR_UNLOCK_ACCOUNT: if (pwbuf->spwd == NULL) { pwbuf->spwd = malloc(sizeof (struct spwd)); if (pwbuf->spwd == NULL) { err = PWU_NOMEM; goto error; } } break; default: /* * Some other repository might have different values * so we ignore those. */ break; } } if (pwbuf->pwd) { if ((pwbuf->pwd_scratch = malloc(PWD_SCRATCH_SIZE)) == NULL) { err = PWU_NOMEM; goto error; } if (private_getpwnam_r(name, pwbuf->pwd, pwbuf->pwd_scratch, PWD_SCRATCH_SIZE) == NULL) { err = PWU_NOT_FOUND; goto error; } } if (pwbuf->spwd) { if ((pwbuf->spwd_scratch = malloc(SPW_SCRATCH_SIZE)) == NULL) { err = PWU_NOMEM; goto error; } if (private_getspnam_r(name, pwbuf->spwd, pwbuf->spwd_scratch, SPW_SCRATCH_SIZE) == NULL) { err = PWU_NOT_FOUND; goto error; } } return (PWU_SUCCESS); error: if (pwbuf->pwd) free(pwbuf->pwd); if (pwbuf->pwd_scratch) free(pwbuf->pwd_scratch); if (pwbuf->spwd) free(pwbuf->spwd); if (pwbuf->spwd_scratch) free(pwbuf->spwd_scratch); free(pwbuf); *buf = NULL; return (err); }
/*ARGSUSED*/ int nss_getpwnam(char *name, attrlist *items, pwu_repository_t *rep, void **buf) { attrlist *p; struct pwbuf *pwbuf; int repositories = REP_ERANGE; /* changed if ATTR_REP_NAME is set */ int err = PWU_SUCCESS; *buf = calloc(1, sizeof (struct pwbuf)); pwbuf = (struct pwbuf *)*buf; /* * determine which password structure (/etc/passwd or /etc/shadow) * we need for the items we need to update */ for (p = items; p != NULL; p = p->next) { switch (p->type) { case ATTR_NAME: case ATTR_UID: case ATTR_GID: case ATTR_AGE: case ATTR_COMMENT: case ATTR_GECOS: case ATTR_HOMEDIR: case ATTR_SHELL: if (pwbuf->pwd == NULL) pwbuf->pwd = (struct passwd *) malloc(sizeof (struct passwd)); if (pwbuf->pwd == NULL) { errno = ENOMEM; if (pwbuf->spwd) free(pwbuf->spwd); return (PWU_NOMEM); } break; case ATTR_PASSWD: case ATTR_PASSWD_SERVER_POLICY: case ATTR_LSTCHG: case ATTR_MIN: case ATTR_MAX: case ATTR_WARN: case ATTR_INACT: case ATTR_EXPIRE: case ATTR_FLAG: case ATTR_LOCK_ACCOUNT: case ATTR_EXPIRE_PASSWORD: case ATTR_FAILED_LOGINS: if (pwbuf->spwd == NULL) pwbuf->spwd = (struct spwd *) malloc(sizeof (struct spwd)); if (pwbuf->spwd == NULL) { errno = ENOMEM; if (pwbuf->pwd) free(pwbuf->pwd); return (PWU_NOMEM); } break; case ATTR_REP_NAME: /* get the compat names (REP_COMPAT_*) */ repositories = get_ns(rep, PWU_READ); break; default: /* * Some other repository might have different values * so we ignore those. */ break; } } if (pwbuf->pwd) { if ((pwbuf->pwd_scratch = malloc(PWD_SCRATCH_SIZE)) == NULL) { err = PWU_NOMEM; goto error; } if (getpwnam_r(name, pwbuf->pwd, pwbuf->pwd_scratch, PWD_SCRATCH_SIZE) == NULL) { err = PWU_NOT_FOUND; goto error; } } if (pwbuf->spwd) { if ((pwbuf->spwd_scratch = malloc(SPW_SCRATCH_SIZE)) == NULL) { err = PWU_NOMEM; goto error; } if (getspnam_r(name, pwbuf->spwd, pwbuf->spwd_scratch, SPW_SCRATCH_SIZE) == NULL) { err = PWU_NOT_FOUND; goto error; } } /* pwbuf->rep_name tells us where the user in fact comes from */ if (repositories != REP_ERANGE) { struct passwd pwd; char pwd_scratch[PWD_SCRATCH_SIZE]; /* can we find the user locally? */ if (private_getpwnam_r(name, &pwd, pwd_scratch, PWD_SCRATCH_SIZE) != NULL) pwbuf->rep_name = "files"; else if (repositories & REP_COMPAT_NISPLUS) pwbuf->rep_name = "nisplus"; else if (repositories & REP_COMPAT_LDAP) pwbuf->rep_name = "ldap"; else if (repositories & REP_COMPAT_NIS) pwbuf->rep_name = "nis"; else pwbuf->rep_name = "nss"; } else pwbuf->rep_name = "nss"; return (PWU_SUCCESS); error: if (pwbuf->pwd) free(pwbuf->pwd); if (pwbuf->pwd_scratch) free(pwbuf->pwd_scratch); if (pwbuf->spwd) free(pwbuf->spwd); if (pwbuf->spwd_scratch) free(pwbuf->spwd_scratch); free(pwbuf); *buf = NULL; return (err); }