17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5f48205beScasper * Common Development and Distribution License (the "License"). 6f48205beScasper * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*36e852a1SRaja Andra * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <nsswitch.h> 287c478bd9Sstevel@tonic-gate #include <stdlib.h> 297c478bd9Sstevel@tonic-gate #include <stdio.h> 307c478bd9Sstevel@tonic-gate #include <string.h> 317c478bd9Sstevel@tonic-gate #include <syslog.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate #include <unistd.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include "ns_sldap.h" 367c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h> 377c478bd9Sstevel@tonic-gate #include <nsswitch.h> 387c478bd9Sstevel@tonic-gate #include <pwd.h> 397c478bd9Sstevel@tonic-gate #include <shadow.h> 407c478bd9Sstevel@tonic-gate #include <rpcsvc/nis.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include "passwdutil.h" 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * name_to_int(rep) 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * Translate the repository to a bitmask. 487c478bd9Sstevel@tonic-gate * if we don't recognise the repository name, we return REP_ERANGE 497c478bd9Sstevel@tonic-gate */ 507c478bd9Sstevel@tonic-gate int 517c478bd9Sstevel@tonic-gate name_to_int(char *rep_name) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate int result = REP_ERANGE; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate if (strcmp(rep_name, "files") == 0) 567c478bd9Sstevel@tonic-gate result = REP_FILES; 577c478bd9Sstevel@tonic-gate else if (strcmp(rep_name, "nis") == 0) 587c478bd9Sstevel@tonic-gate result = REP_NIS; 597c478bd9Sstevel@tonic-gate else if (strcmp(rep_name, "ldap") == 0) 607c478bd9Sstevel@tonic-gate result = REP_LDAP; 617c478bd9Sstevel@tonic-gate else if (strcmp(rep_name, "compat") == 0) { 627c478bd9Sstevel@tonic-gate struct __nsw_switchconfig *cfg; 637c478bd9Sstevel@tonic-gate enum __nsw_parse_err pserr; 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate cfg = __nsw_getconfig("passwd_compat", &pserr); 667c478bd9Sstevel@tonic-gate if (cfg == NULL) { 677c478bd9Sstevel@tonic-gate result = REP_FILES | REP_NIS; 687c478bd9Sstevel@tonic-gate } else { 69*36e852a1SRaja Andra if (strcmp(cfg->lookups->service_name, "ldap") == 0) 707c478bd9Sstevel@tonic-gate result = REP_FILES | REP_LDAP; 717c478bd9Sstevel@tonic-gate else 727c478bd9Sstevel@tonic-gate result = REP_ERANGE; 737c478bd9Sstevel@tonic-gate __nsw_freeconfig(cfg); 747c478bd9Sstevel@tonic-gate } 757c478bd9Sstevel@tonic-gate } 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate return (result); 787c478bd9Sstevel@tonic-gate } 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Figure out which repository we use in compat mode. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate int 847c478bd9Sstevel@tonic-gate get_compat_mode(void) 857c478bd9Sstevel@tonic-gate { 867c478bd9Sstevel@tonic-gate struct __nsw_switchconfig *cfg; 877c478bd9Sstevel@tonic-gate enum __nsw_parse_err pserr; 887c478bd9Sstevel@tonic-gate int result = REP_COMPAT_NIS; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate if ((cfg = __nsw_getconfig("passwd_compat", &pserr)) != NULL) { 91*36e852a1SRaja Andra if (strcmp(cfg->lookups->service_name, "ldap") == 0) 927c478bd9Sstevel@tonic-gate result = REP_COMPAT_LDAP; 937c478bd9Sstevel@tonic-gate } 947c478bd9Sstevel@tonic-gate __nsw_freeconfig(cfg); 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate return (result); 977c478bd9Sstevel@tonic-gate } 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * get_ns(rep, accesstype) 1017c478bd9Sstevel@tonic-gate * 1027c478bd9Sstevel@tonic-gate * returns a bitmask of repositories to use based on either 1037c478bd9Sstevel@tonic-gate * 1. the repository that is given as argument 1047c478bd9Sstevel@tonic-gate * 2. the nsswitch.conf file 1057c478bd9Sstevel@tonic-gate * 3. the type of access requested 1067c478bd9Sstevel@tonic-gate * 1077c478bd9Sstevel@tonic-gate * "accesstype" indicates whether we are reading from or writing to the 1087c478bd9Sstevel@tonic-gate * repository. We need to know this since "compat" will translate into 1097c478bd9Sstevel@tonic-gate * REP_NSS (the nss-switch) for READ access (needed to decode 1107c478bd9Sstevel@tonic-gate * the black-magic '+' entries) but it translates into a bitmask 1117c478bd9Sstevel@tonic-gate * on WRITE access. 1127c478bd9Sstevel@tonic-gate * 1137c478bd9Sstevel@tonic-gate * If we detect read-access in compat mode, we augment the result 114*36e852a1SRaja Andra * with one of REP_COMPAT_{NIS,LDAP}. We need this in order to 1157c478bd9Sstevel@tonic-gate * implement ATTR_REP_NAME in nss_getpwnam. 1167c478bd9Sstevel@tonic-gate * 1177c478bd9Sstevel@tonic-gate * A return value of REP_NOREP indicates an error. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate int 1207c478bd9Sstevel@tonic-gate get_ns(pwu_repository_t *rep, int accesstype) 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate struct __nsw_switchconfig *conf = NULL; 1237c478bd9Sstevel@tonic-gate enum __nsw_parse_err pserr; 1247c478bd9Sstevel@tonic-gate struct __nsw_lookup *lkp; 1257c478bd9Sstevel@tonic-gate struct __nsw_lookup *lkp2; 1262b4a7802SBaban Kenkre struct __nsw_lookup *lkp3; 1272b4a7802SBaban Kenkre struct __nsw_lookup *lkpn; 1287c478bd9Sstevel@tonic-gate int result = REP_NOREP; 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate if (rep != PWU_DEFAULT_REP) { 1317c478bd9Sstevel@tonic-gate result = name_to_int(rep->type); 1327c478bd9Sstevel@tonic-gate return (result); 1337c478bd9Sstevel@tonic-gate } 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate conf = __nsw_getconfig("passwd", &pserr); 1367c478bd9Sstevel@tonic-gate if (conf == NULL) { 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * No config found. The user didn't supply a repository, 1397c478bd9Sstevel@tonic-gate * so we try to change the password in the default 1407c478bd9Sstevel@tonic-gate * repositories (files and nis) even though we cannot 1417c478bd9Sstevel@tonic-gate * find the name service switch entry. (Backward compat) 1427c478bd9Sstevel@tonic-gate */ 1437c478bd9Sstevel@tonic-gate syslog(LOG_ERR, "passwdutil.so: nameservice switch entry for " 1447c478bd9Sstevel@tonic-gate "passwd not found."); 1457c478bd9Sstevel@tonic-gate result = REP_FILES | REP_NIS; 1467c478bd9Sstevel@tonic-gate return (result); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate lkp = conf->lookups; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate /* 1522b4a7802SBaban Kenkre * Supported nsswitch.conf can have a maximum of 3 repositories. 1537c478bd9Sstevel@tonic-gate * If we encounter an unsupported nsswitch.conf, we return REP_NSS 1547c478bd9Sstevel@tonic-gate * to fall back to the nsswitch backend. 1552b4a7802SBaban Kenkre * 1562b4a7802SBaban Kenkre * Note that specifying 'ad' in the configuration is acceptable 1572b4a7802SBaban Kenkre * though changing AD users' passwords through passwd(1) is not. 1582b4a7802SBaban Kenkre * Therefore "ad" will be silently ignored. 1597c478bd9Sstevel@tonic-gate */ 1607c478bd9Sstevel@tonic-gate if (conf->num_lookups == 1) { 1617c478bd9Sstevel@tonic-gate /* files or compat */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if (strcmp(lkp->service_name, "files") == 0) { 1647c478bd9Sstevel@tonic-gate result = name_to_int(lkp->service_name); 1657c478bd9Sstevel@tonic-gate } else if (strcmp(lkp->service_name, "compat") == 0) { 1667c478bd9Sstevel@tonic-gate if (accesstype == PWU_READ) 1677c478bd9Sstevel@tonic-gate result = REP_NSS | get_compat_mode(); 1687c478bd9Sstevel@tonic-gate else 1697c478bd9Sstevel@tonic-gate result = name_to_int(lkp->service_name); 1707c478bd9Sstevel@tonic-gate } else 1717c478bd9Sstevel@tonic-gate result = REP_NSS; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate } else if (conf->num_lookups == 2) { 1747c478bd9Sstevel@tonic-gate lkp2 = lkp->next; 1757c478bd9Sstevel@tonic-gate if (strcmp(lkp->service_name, "files") == 0) { 1767c478bd9Sstevel@tonic-gate result = REP_FILES; 1777c478bd9Sstevel@tonic-gate if (strcmp(lkp2->service_name, "ldap") == 0) 1787c478bd9Sstevel@tonic-gate result |= REP_LDAP; 1797c478bd9Sstevel@tonic-gate else if (strcmp(lkp2->service_name, "nis") == 0) 1807c478bd9Sstevel@tonic-gate result |= REP_NIS; 1812b4a7802SBaban Kenkre else if (strcmp(lkp2->service_name, "ad") != 0) 1822b4a7802SBaban Kenkre result = REP_NSS; 1832b4a7802SBaban Kenkre /* AD is ignored */ 1842b4a7802SBaban Kenkre } else { 1852b4a7802SBaban Kenkre result = REP_NSS; 1862b4a7802SBaban Kenkre } 1872b4a7802SBaban Kenkre } else if (conf->num_lookups == 3) { 1882b4a7802SBaban Kenkre /* 1892b4a7802SBaban Kenkre * Valid configurations with 3 repositories are: 190*36e852a1SRaja Andra * files ad [nis | ldap ] OR 191*36e852a1SRaja Andra * files [nis | ldap ] ad 1922b4a7802SBaban Kenkre */ 1932b4a7802SBaban Kenkre lkp2 = lkp->next; 1942b4a7802SBaban Kenkre lkp3 = lkp2->next; 1952b4a7802SBaban Kenkre if (strcmp(lkp2->service_name, "ad") == 0) 1962b4a7802SBaban Kenkre lkpn = lkp3; 1972b4a7802SBaban Kenkre else if (strcmp(lkp3->service_name, "ad") == 0) 1982b4a7802SBaban Kenkre lkpn = lkp2; 1992b4a7802SBaban Kenkre else 2002b4a7802SBaban Kenkre lkpn = NULL; 2012b4a7802SBaban Kenkre if (strcmp(lkp->service_name, "files") == 0 && 2022b4a7802SBaban Kenkre lkpn != NULL) { 2032b4a7802SBaban Kenkre result = REP_FILES; 2042b4a7802SBaban Kenkre if (strcmp(lkpn->service_name, "ldap") == 0) 2052b4a7802SBaban Kenkre result |= REP_LDAP; 2062b4a7802SBaban Kenkre else if (strcmp(lkpn->service_name, "nis") == 0) 2072b4a7802SBaban Kenkre result |= REP_NIS; 2087c478bd9Sstevel@tonic-gate else 2097c478bd9Sstevel@tonic-gate result = REP_NSS; 2107c478bd9Sstevel@tonic-gate } else { 2117c478bd9Sstevel@tonic-gate result = REP_NSS; 2127c478bd9Sstevel@tonic-gate } 2137c478bd9Sstevel@tonic-gate } else { 2147c478bd9Sstevel@tonic-gate result = REP_NSS; 2157c478bd9Sstevel@tonic-gate } 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate __nsw_freeconfig(conf); 2187c478bd9Sstevel@tonic-gate return (result); 2197c478bd9Sstevel@tonic-gate } 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate static void 2227c478bd9Sstevel@tonic-gate nss_ldap_passwd(p) 2237c478bd9Sstevel@tonic-gate nss_db_params_t *p; 2247c478bd9Sstevel@tonic-gate { 2257c478bd9Sstevel@tonic-gate p->name = NSS_DBNAM_PASSWD; 2267c478bd9Sstevel@tonic-gate p->flags |= NSS_USE_DEFAULT_CONFIG; 2277c478bd9Sstevel@tonic-gate p->default_config = "ldap"; 2287c478bd9Sstevel@tonic-gate } 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate static void 2317c478bd9Sstevel@tonic-gate nss_ldap_shadow(p) 2327c478bd9Sstevel@tonic-gate nss_db_params_t *p; 2337c478bd9Sstevel@tonic-gate { 2347c478bd9Sstevel@tonic-gate p->name = NSS_DBNAM_SHADOW; 2357c478bd9Sstevel@tonic-gate p->config_name = NSS_DBNAM_PASSWD; /* Use config for "passwd" */ 2367c478bd9Sstevel@tonic-gate p->flags |= NSS_USE_DEFAULT_CONFIG; 2377c478bd9Sstevel@tonic-gate p->default_config = "ldap"; 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #ifdef PAM_NIS 2427c478bd9Sstevel@tonic-gate static void 2437c478bd9Sstevel@tonic-gate nss_nis_passwd(p) 2447c478bd9Sstevel@tonic-gate nss_db_params_t *p; 2457c478bd9Sstevel@tonic-gate { 2467c478bd9Sstevel@tonic-gate p->name = NSS_DBNAM_PASSWD; 2477c478bd9Sstevel@tonic-gate p->flags |= NSS_USE_DEFAULT_CONFIG; 2487c478bd9Sstevel@tonic-gate p->default_config = "nis"; 2497c478bd9Sstevel@tonic-gate } 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate static void 2527c478bd9Sstevel@tonic-gate nss_nis_shadow(p) 2537c478bd9Sstevel@tonic-gate nss_db_params_t *p; 2547c478bd9Sstevel@tonic-gate { 2557c478bd9Sstevel@tonic-gate p->name = NSS_DBNAM_SHADOW; 2567c478bd9Sstevel@tonic-gate p->config_name = NSS_DBNAM_PASSWD; /* Use config for "passwd" */ 2577c478bd9Sstevel@tonic-gate p->flags |= NSS_USE_DEFAULT_CONFIG; 2587c478bd9Sstevel@tonic-gate p->default_config = "nis"; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate #endif /* PAM_NIS */ 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate static char * 2637c478bd9Sstevel@tonic-gate gettok(nextpp) 2647c478bd9Sstevel@tonic-gate char **nextpp; 2657c478bd9Sstevel@tonic-gate { 2667c478bd9Sstevel@tonic-gate char *p = *nextpp; 2677c478bd9Sstevel@tonic-gate char *q = p; 2687c478bd9Sstevel@tonic-gate char c; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate if (p == 0) { 2717c478bd9Sstevel@tonic-gate return (0); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate while ((c = *q) != '\0' && c != ':') { 2747c478bd9Sstevel@tonic-gate q++; 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate if (c == '\0') { 2777c478bd9Sstevel@tonic-gate *nextpp = 0; 2787c478bd9Sstevel@tonic-gate } else { 2797c478bd9Sstevel@tonic-gate *q++ = '\0'; 2807c478bd9Sstevel@tonic-gate *nextpp = q; 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate return (p); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * Return values: 0 = success, 1 = parse error, 2 = erange ... 2877c478bd9Sstevel@tonic-gate * The structure pointer passed in is a structure in the caller's space 2887c478bd9Sstevel@tonic-gate * wherein the field pointers would be set to areas in the buffer if 2897c478bd9Sstevel@tonic-gate * need be. instring and buffer should be separate areas. 2907c478bd9Sstevel@tonic-gate */ 2917c478bd9Sstevel@tonic-gate static int 2927c478bd9Sstevel@tonic-gate str2passwd(const char *instr, int lenstr, void *ent, char *buffer, int buflen) 2937c478bd9Sstevel@tonic-gate { 2947c478bd9Sstevel@tonic-gate struct passwd *passwd = (struct passwd *)ent; 2957c478bd9Sstevel@tonic-gate char *p, *next; 2967c478bd9Sstevel@tonic-gate int black_magic; /* "+" or "-" entry */ 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate if (lenstr + 1 > buflen) { 2997c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_ERANGE); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate /* 3027c478bd9Sstevel@tonic-gate * We copy the input string into the output buffer and 3037c478bd9Sstevel@tonic-gate * operate on it in place. 3047c478bd9Sstevel@tonic-gate */ 3057c478bd9Sstevel@tonic-gate (void) memcpy(buffer, instr, lenstr); 3067c478bd9Sstevel@tonic-gate buffer[lenstr] = '\0'; 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate next = buffer; 3097c478bd9Sstevel@tonic-gate 3107c478bd9Sstevel@tonic-gate passwd->pw_name = p = gettok(&next); /* username */ 3117c478bd9Sstevel@tonic-gate if (*p == '\0') { 3127c478bd9Sstevel@tonic-gate /* Empty username; not allowed */ 3137c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate black_magic = (*p == '+' || *p == '-'); 3167c478bd9Sstevel@tonic-gate if (black_magic) { 3177c478bd9Sstevel@tonic-gate passwd->pw_uid = UID_NOBODY; 3187c478bd9Sstevel@tonic-gate passwd->pw_gid = GID_NOBODY; 3197c478bd9Sstevel@tonic-gate /* 3207c478bd9Sstevel@tonic-gate * pwconv tests pw_passwd and pw_age == NULL 3217c478bd9Sstevel@tonic-gate */ 3227c478bd9Sstevel@tonic-gate passwd->pw_passwd = ""; 3237c478bd9Sstevel@tonic-gate passwd->pw_age = ""; 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * the rest of the passwd entry is "optional" 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate passwd->pw_comment = ""; 3287c478bd9Sstevel@tonic-gate passwd->pw_gecos = ""; 3297c478bd9Sstevel@tonic-gate passwd->pw_dir = ""; 3307c478bd9Sstevel@tonic-gate passwd->pw_shell = ""; 3317c478bd9Sstevel@tonic-gate } 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate passwd->pw_passwd = p = gettok(&next); /* password */ 3347c478bd9Sstevel@tonic-gate if (p == 0) { 3357c478bd9Sstevel@tonic-gate if (black_magic) 3367c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 3377c478bd9Sstevel@tonic-gate else 3387c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate for (; *p != '\0'; p++) { /* age */ 3417c478bd9Sstevel@tonic-gate if (*p == ',') { 3427c478bd9Sstevel@tonic-gate *p++ = '\0'; 3437c478bd9Sstevel@tonic-gate break; 3447c478bd9Sstevel@tonic-gate } 3457c478bd9Sstevel@tonic-gate } 3467c478bd9Sstevel@tonic-gate passwd->pw_age = p; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate p = next; /* uid */ 3497c478bd9Sstevel@tonic-gate if (p == 0 || *p == '\0') { 3507c478bd9Sstevel@tonic-gate if (black_magic) 3517c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 3527c478bd9Sstevel@tonic-gate else 3537c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate if (!black_magic) { 3567c478bd9Sstevel@tonic-gate passwd->pw_uid = strtol(p, &next, 10); 3577c478bd9Sstevel@tonic-gate if (next == p) { 3587c478bd9Sstevel@tonic-gate /* uid field should be nonempty */ 3597c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate /* 3627c478bd9Sstevel@tonic-gate * The old code (in 2.0 thru 2.5) would check 3637c478bd9Sstevel@tonic-gate * for the uid being negative, or being greater 3647c478bd9Sstevel@tonic-gate * than 60001 (the rfs limit). If it met either of 3657c478bd9Sstevel@tonic-gate * these conditions, the uid was translated to 60001. 3667c478bd9Sstevel@tonic-gate * 367f48205beScasper * Now we just check for ephemeral uids; anything else 3687c478bd9Sstevel@tonic-gate * is administrative policy 3697c478bd9Sstevel@tonic-gate */ 370f48205beScasper if (passwd->pw_uid > MAXUID) 3717c478bd9Sstevel@tonic-gate passwd->pw_uid = UID_NOBODY; 3727c478bd9Sstevel@tonic-gate } 3737c478bd9Sstevel@tonic-gate if (*next++ != ':') { 3747c478bd9Sstevel@tonic-gate if (black_magic) 3757c478bd9Sstevel@tonic-gate p = gettok(&next); 3767c478bd9Sstevel@tonic-gate else 3777c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate p = next; /* gid */ 3807c478bd9Sstevel@tonic-gate if (p == 0 || *p == '\0') { 3817c478bd9Sstevel@tonic-gate if (black_magic) 3827c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 3837c478bd9Sstevel@tonic-gate else 3847c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate if (!black_magic) { 3877c478bd9Sstevel@tonic-gate passwd->pw_gid = strtol(p, &next, 10); 3887c478bd9Sstevel@tonic-gate if (next == p) { 3897c478bd9Sstevel@tonic-gate /* gid field should be nonempty */ 3907c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate /* 3937c478bd9Sstevel@tonic-gate * gid should be non-negative; anything else 3947c478bd9Sstevel@tonic-gate * is administrative policy. 3957c478bd9Sstevel@tonic-gate */ 396f48205beScasper if (passwd->pw_gid > MAXUID) 3977c478bd9Sstevel@tonic-gate passwd->pw_gid = GID_NOBODY; 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate if (*next++ != ':') { 4007c478bd9Sstevel@tonic-gate if (black_magic) 4017c478bd9Sstevel@tonic-gate p = gettok(&next); 4027c478bd9Sstevel@tonic-gate else 4037c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate passwd->pw_gecos = passwd->pw_comment = p = gettok(&next); 4077c478bd9Sstevel@tonic-gate if (p == 0) { 4087c478bd9Sstevel@tonic-gate if (black_magic) 4097c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 4107c478bd9Sstevel@tonic-gate else 4117c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate passwd->pw_dir = p = gettok(&next); 4157c478bd9Sstevel@tonic-gate if (p == 0) { 4167c478bd9Sstevel@tonic-gate if (black_magic) 4177c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 4187c478bd9Sstevel@tonic-gate else 4197c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate passwd->pw_shell = p = gettok(&next); 4237c478bd9Sstevel@tonic-gate if (p == 0) { 4247c478bd9Sstevel@tonic-gate if (black_magic) 4257c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 4267c478bd9Sstevel@tonic-gate else 4277c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 4287c478bd9Sstevel@tonic-gate } 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate /* Better not be any more fields... */ 4317c478bd9Sstevel@tonic-gate if (next == 0) { 4327c478bd9Sstevel@tonic-gate /* Successfully parsed and stored */ 4337c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 4347c478bd9Sstevel@tonic-gate } 4357c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 4367c478bd9Sstevel@tonic-gate } 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate typedef const char *constp; 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate /* 4417c478bd9Sstevel@tonic-gate * Return value 1 means success and more input, 0 means error or no more 4427c478bd9Sstevel@tonic-gate */ 4437c478bd9Sstevel@tonic-gate static int 4447c478bd9Sstevel@tonic-gate getfield(nextp, limit, uns, valp) 4457c478bd9Sstevel@tonic-gate constp *nextp; 4467c478bd9Sstevel@tonic-gate constp limit; 4477c478bd9Sstevel@tonic-gate int uns; 4487c478bd9Sstevel@tonic-gate void *valp; 4497c478bd9Sstevel@tonic-gate { 4507c478bd9Sstevel@tonic-gate constp p = *nextp; 4517c478bd9Sstevel@tonic-gate char *endfield; 4527c478bd9Sstevel@tonic-gate char numbuf[12]; /* Holds -2^31 and trailing ':' */ 4537c478bd9Sstevel@tonic-gate int len; 4547c478bd9Sstevel@tonic-gate long x; 4557c478bd9Sstevel@tonic-gate unsigned long ux; 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate if (p == 0 || p >= limit) { 4587c478bd9Sstevel@tonic-gate return (0); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate if (*p == ':') { 4617c478bd9Sstevel@tonic-gate p++; 4627c478bd9Sstevel@tonic-gate *nextp = p; 4637c478bd9Sstevel@tonic-gate return (p < limit); 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate if ((len = limit - p) > sizeof (numbuf) - 1) { 4667c478bd9Sstevel@tonic-gate len = sizeof (numbuf) - 1; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate /* 4697c478bd9Sstevel@tonic-gate * We want to use strtol() and we have a readonly non-zero-terminated 4707c478bd9Sstevel@tonic-gate * string, so first we copy and terminate the interesting bit. 4717c478bd9Sstevel@tonic-gate * Ugh. (It's convenient to terminate with a colon rather than \0). 4727c478bd9Sstevel@tonic-gate */ 4737c478bd9Sstevel@tonic-gate if ((endfield = memccpy(numbuf, p, ':', len)) == 0) { 4747c478bd9Sstevel@tonic-gate if (len != limit - p) { 4757c478bd9Sstevel@tonic-gate /* Error -- field is too big to be a legit number */ 4767c478bd9Sstevel@tonic-gate return (0); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate numbuf[len] = ':'; 4797c478bd9Sstevel@tonic-gate p = limit; 4807c478bd9Sstevel@tonic-gate } else { 4817c478bd9Sstevel@tonic-gate p += (endfield - numbuf); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate if (uns) { 4847c478bd9Sstevel@tonic-gate ux = strtoul(numbuf, &endfield, 10); 4857c478bd9Sstevel@tonic-gate if (*endfield != ':') { 4867c478bd9Sstevel@tonic-gate /* Error -- expected <integer><colon> */ 4877c478bd9Sstevel@tonic-gate return (0); 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate *((unsigned int *)valp) = (unsigned int)ux; 4907c478bd9Sstevel@tonic-gate } else { 4917c478bd9Sstevel@tonic-gate x = strtol(numbuf, &endfield, 10); 4927c478bd9Sstevel@tonic-gate if (*endfield != ':') { 4937c478bd9Sstevel@tonic-gate /* Error -- expected <integer><colon> */ 4947c478bd9Sstevel@tonic-gate return (0); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate *((int *)valp) = (int)x; 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate *nextp = p; 4997c478bd9Sstevel@tonic-gate return (p < limit); 5007c478bd9Sstevel@tonic-gate } 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * str2spwd() -- convert a string to a shadow passwd entry. The parser is 5047c478bd9Sstevel@tonic-gate * more liberal than the passwd or group parsers; since it's legitimate 5057c478bd9Sstevel@tonic-gate * for almost all the fields here to be blank, the parser lets one omit 5067c478bd9Sstevel@tonic-gate * any number of blank fields at the end of the entry. The acceptable 5077c478bd9Sstevel@tonic-gate * forms for '+' and '-' entries are the same as those for normal entries. 5087c478bd9Sstevel@tonic-gate * === Is this likely to do more harm than good? 5097c478bd9Sstevel@tonic-gate * 5107c478bd9Sstevel@tonic-gate * Return values: 0 = success, 1 = parse error, 2 = erange ... 5117c478bd9Sstevel@tonic-gate * The structure pointer passed in is a structure in the caller's space 5127c478bd9Sstevel@tonic-gate * wherein the field pointers would be set to areas in the buffer if 5137c478bd9Sstevel@tonic-gate * need be. instring and buffer should be separate areas. 5147c478bd9Sstevel@tonic-gate */ 5157c478bd9Sstevel@tonic-gate int 5167c478bd9Sstevel@tonic-gate str2spwd(instr, lenstr, ent, buffer, buflen) 5177c478bd9Sstevel@tonic-gate const char *instr; 5187c478bd9Sstevel@tonic-gate int lenstr; 5197c478bd9Sstevel@tonic-gate void *ent; /* really (struct spwd *) */ 5207c478bd9Sstevel@tonic-gate char *buffer; 5217c478bd9Sstevel@tonic-gate int buflen; 5227c478bd9Sstevel@tonic-gate { 5237c478bd9Sstevel@tonic-gate struct spwd *shadow = (struct spwd *)ent; 5247c478bd9Sstevel@tonic-gate const char *p = instr, *limit; 5257c478bd9Sstevel@tonic-gate char *bufp; 5267c478bd9Sstevel@tonic-gate int lencopy, black_magic; 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate limit = p + lenstr; 5297c478bd9Sstevel@tonic-gate if ((p = memchr(instr, ':', lenstr)) == 0 || 5307c478bd9Sstevel@tonic-gate ++p >= limit || 5317c478bd9Sstevel@tonic-gate (p = memchr(p, ':', limit - p)) == 0) { 5327c478bd9Sstevel@tonic-gate lencopy = lenstr; 5337c478bd9Sstevel@tonic-gate p = 0; 5347c478bd9Sstevel@tonic-gate } else { 5357c478bd9Sstevel@tonic-gate lencopy = p - instr; 5367c478bd9Sstevel@tonic-gate p++; 5377c478bd9Sstevel@tonic-gate } 5387c478bd9Sstevel@tonic-gate if (lencopy + 1 > buflen) { 5397c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_ERANGE); 5407c478bd9Sstevel@tonic-gate } 5417c478bd9Sstevel@tonic-gate (void) memcpy(buffer, instr, lencopy); 5427c478bd9Sstevel@tonic-gate buffer[lencopy] = 0; 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate black_magic = (*instr == '+' || *instr == '-'); 5457c478bd9Sstevel@tonic-gate shadow->sp_namp = bufp = buffer; 5467c478bd9Sstevel@tonic-gate shadow->sp_pwdp = 0; 5477c478bd9Sstevel@tonic-gate shadow->sp_lstchg = -1; 5487c478bd9Sstevel@tonic-gate shadow->sp_min = -1; 5497c478bd9Sstevel@tonic-gate shadow->sp_max = -1; 5507c478bd9Sstevel@tonic-gate shadow->sp_warn = -1; 5517c478bd9Sstevel@tonic-gate shadow->sp_inact = -1; 5527c478bd9Sstevel@tonic-gate shadow->sp_expire = -1; 5537c478bd9Sstevel@tonic-gate shadow->sp_flag = 0; 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate if ((bufp = strchr(bufp, ':')) == 0) { 5567c478bd9Sstevel@tonic-gate if (black_magic) 5577c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5587c478bd9Sstevel@tonic-gate else 5597c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate *bufp++ = '\0'; 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate shadow->sp_pwdp = bufp; 5647c478bd9Sstevel@tonic-gate if (instr == 0) { 5657c478bd9Sstevel@tonic-gate if ((bufp = strchr(bufp, ':')) == 0) { 5667c478bd9Sstevel@tonic-gate if (black_magic) 5677c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5687c478bd9Sstevel@tonic-gate else 5697c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 5707c478bd9Sstevel@tonic-gate } 5717c478bd9Sstevel@tonic-gate *bufp++ = '\0'; 5727c478bd9Sstevel@tonic-gate p = bufp; 5737c478bd9Sstevel@tonic-gate } /* else p was set when we copied name and passwd into the buffer */ 5747c478bd9Sstevel@tonic-gate 5757c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_lstchg)) 5767c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5777c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_min)) 5787c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5797c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_max)) 5807c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5817c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_warn)) 5827c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5837c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_inact)) 5847c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5857c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 0, &shadow->sp_expire)) 5867c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5877c478bd9Sstevel@tonic-gate if (!getfield(&p, limit, 1, &shadow->sp_flag)) 5887c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5897c478bd9Sstevel@tonic-gate if (p != limit) { 5907c478bd9Sstevel@tonic-gate /* Syntax error -- garbage at end of line */ 5917c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_PARSE); 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate return (NSS_STR_PARSE_SUCCESS); 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate static nss_XbyY_buf_t *buffer; 5977c478bd9Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root); 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate #define GETBUF() \ 6007c478bd9Sstevel@tonic-gate NSS_XbyY_ALLOC(&buffer, sizeof (struct passwd), NSS_BUFLEN_PASSWD) 6017c478bd9Sstevel@tonic-gate 6027c478bd9Sstevel@tonic-gate #pragma fini(endutilpwent) 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate static void 6057c478bd9Sstevel@tonic-gate endutilpwent(void) 6067c478bd9Sstevel@tonic-gate { 6077c478bd9Sstevel@tonic-gate NSS_XbyY_FREE(&buffer); 6087c478bd9Sstevel@tonic-gate nss_delete(&db_root); 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate 611*36e852a1SRaja Andra /*ARGSUSED*/ 6127c478bd9Sstevel@tonic-gate struct passwd * 6137c478bd9Sstevel@tonic-gate getpwnam_from(const char *name, pwu_repository_t *rep, int reptype) 6147c478bd9Sstevel@tonic-gate { 6157c478bd9Sstevel@tonic-gate nss_XbyY_buf_t *b = GETBUF(); 6167c478bd9Sstevel@tonic-gate nss_XbyY_args_t arg; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate if (b == 0) 6197c478bd9Sstevel@tonic-gate return (0); 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate NSS_XbyY_INIT(&arg, b->result, b->buffer, b->buflen, str2passwd); 6227c478bd9Sstevel@tonic-gate arg.key.name = name; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate switch (reptype) { 6257c478bd9Sstevel@tonic-gate case REP_LDAP: 6267c478bd9Sstevel@tonic-gate (void) nss_search(&db_root, nss_ldap_passwd, 6277c478bd9Sstevel@tonic-gate NSS_DBOP_PASSWD_BYNAME, &arg); 6287c478bd9Sstevel@tonic-gate break; 6297c478bd9Sstevel@tonic-gate #ifdef PAM_NIS 6307c478bd9Sstevel@tonic-gate case REP_NIS: 6317c478bd9Sstevel@tonic-gate (void) nss_search(&db_root, nss_nis_passwd, 6327c478bd9Sstevel@tonic-gate NSS_DBOP_PASSWD_BYNAME, &arg); 6337c478bd9Sstevel@tonic-gate break; 6347c478bd9Sstevel@tonic-gate #endif 6357c478bd9Sstevel@tonic-gate default: 6367c478bd9Sstevel@tonic-gate return (NULL); 6377c478bd9Sstevel@tonic-gate } 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate return (struct passwd *)NSS_XbyY_FINI(&arg); 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6437c478bd9Sstevel@tonic-gate struct passwd * 6447c478bd9Sstevel@tonic-gate getpwuid_from(uid_t uid, pwu_repository_t *rep, int reptype) 6457c478bd9Sstevel@tonic-gate { 6467c478bd9Sstevel@tonic-gate nss_XbyY_buf_t *b = GETBUF(); 6477c478bd9Sstevel@tonic-gate nss_XbyY_args_t arg; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate if (b == 0) 6507c478bd9Sstevel@tonic-gate return (0); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate NSS_XbyY_INIT(&arg, b->result, b->buffer, b->buflen, str2passwd); 6537c478bd9Sstevel@tonic-gate arg.key.uid = uid; 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate switch (reptype) { 6567c478bd9Sstevel@tonic-gate case REP_LDAP: 6577c478bd9Sstevel@tonic-gate (void) nss_search(&db_root, nss_ldap_passwd, 6587c478bd9Sstevel@tonic-gate NSS_DBOP_PASSWD_BYUID, &arg); 6597c478bd9Sstevel@tonic-gate break; 6607c478bd9Sstevel@tonic-gate #ifdef PAM_NIS 6617c478bd9Sstevel@tonic-gate case REP_NIS: 6627c478bd9Sstevel@tonic-gate (void) nss_search(&db_root, nss_nis_passwd, 6637c478bd9Sstevel@tonic-gate NSS_DBOP_PASSWD_BYUID, &arg); 6647c478bd9Sstevel@tonic-gate break; 6657c478bd9Sstevel@tonic-gate #endif 6667c478bd9Sstevel@tonic-gate default: 6677c478bd9Sstevel@tonic-gate return (NULL); 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate return (struct passwd *)NSS_XbyY_FINI(&arg); 6717c478bd9Sstevel@tonic-gate } 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate static nss_XbyY_buf_t *spbuf; 6747c478bd9Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(spdb_root); 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate #define GETSPBUF() \ 6777c478bd9Sstevel@tonic-gate NSS_XbyY_ALLOC(&spbuf, sizeof (struct spwd), NSS_BUFLEN_SHADOW) 6787c478bd9Sstevel@tonic-gate 6797c478bd9Sstevel@tonic-gate #pragma fini(endutilspent) 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate static void 6827c478bd9Sstevel@tonic-gate endutilspent(void) 6837c478bd9Sstevel@tonic-gate { 6847c478bd9Sstevel@tonic-gate NSS_XbyY_FREE(&spbuf); 6857c478bd9Sstevel@tonic-gate nss_delete(&spdb_root); 6867c478bd9Sstevel@tonic-gate } 6877c478bd9Sstevel@tonic-gate 688*36e852a1SRaja Andra /*ARGSUSED*/ 6897c478bd9Sstevel@tonic-gate struct spwd * 6907c478bd9Sstevel@tonic-gate getspnam_from(const char *name, pwu_repository_t *rep, int reptype) 6917c478bd9Sstevel@tonic-gate { 6927c478bd9Sstevel@tonic-gate nss_XbyY_buf_t *b = GETSPBUF(); 6937c478bd9Sstevel@tonic-gate nss_XbyY_args_t arg; 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate if (b == 0) 6967c478bd9Sstevel@tonic-gate return (0); 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate NSS_XbyY_INIT(&arg, b->result, b->buffer, b->buflen, str2spwd); 6997c478bd9Sstevel@tonic-gate arg.key.name = name; 7007c478bd9Sstevel@tonic-gate switch (reptype) { 7017c478bd9Sstevel@tonic-gate case REP_LDAP: 7027c478bd9Sstevel@tonic-gate (void) nss_search(&spdb_root, nss_ldap_shadow, 7037c478bd9Sstevel@tonic-gate NSS_DBOP_SHADOW_BYNAME, &arg); 7047c478bd9Sstevel@tonic-gate break; 7057c478bd9Sstevel@tonic-gate #ifdef PAM_NIS 7067c478bd9Sstevel@tonic-gate case REP_NIS: 7077c478bd9Sstevel@tonic-gate (void) nss_search(&spdb_root, nss_nis_shadow, 7087c478bd9Sstevel@tonic-gate NSS_DBOP_SHADOW_BYNAME, &arg); 7097c478bd9Sstevel@tonic-gate break; 7107c478bd9Sstevel@tonic-gate #endif 7117c478bd9Sstevel@tonic-gate default: 7127c478bd9Sstevel@tonic-gate return (NULL); 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate return (struct spwd *)NSS_XbyY_FINI(&arg); 7157c478bd9Sstevel@tonic-gate } 716