10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52388Smj162486 * Common Development and Distribution License (the "License"). 62388Smj162486 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 222388Smj162486 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <syslog.h> 290Sstevel@tonic-gate #include "ldap_common.h" 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* netgroup attributes filters */ 320Sstevel@tonic-gate #define _N_TRIPLE "nisnetgrouptriple" 330Sstevel@tonic-gate #define _N_MEMBER "membernisnetgroup" 340Sstevel@tonic-gate 350Sstevel@tonic-gate #define PRINT_VAL(a) (((a).argc == 0) || ((a).argv == NULL) || \ 360Sstevel@tonic-gate ((a).argv[0] == NULL)) ? "*" : (a).argv[0] 370Sstevel@tonic-gate #define ISNULL(a) (a == NULL ? "<NULL>" : a) 380Sstevel@tonic-gate #define MAX_DOMAIN_LEN 1024 390Sstevel@tonic-gate #define MAX_TRIPLE_LEN (MAXHOSTNAMELEN + LOGNAME_MAX + \ 400Sstevel@tonic-gate MAX_DOMAIN_LEN + 5) 410Sstevel@tonic-gate 420Sstevel@tonic-gate #define _F_SETMEMBER "(&(objectClass=nisNetGroup)(cn=%s))" 430Sstevel@tonic-gate #define _F_SETMEMBER_SSD "(&(%%s)(cn=%s))" 440Sstevel@tonic-gate 450Sstevel@tonic-gate #define N_HASH 257 462388Smj162486 #define COMMA ',' 470Sstevel@tonic-gate 480Sstevel@tonic-gate static const char *netgrent_attrs[] = { 490Sstevel@tonic-gate _N_TRIPLE, 500Sstevel@tonic-gate _N_MEMBER, 510Sstevel@tonic-gate (char *)NULL 520Sstevel@tonic-gate }; 530Sstevel@tonic-gate 540Sstevel@tonic-gate typedef struct netgroup_name { 550Sstevel@tonic-gate char *name; 560Sstevel@tonic-gate struct netgroup_name *next; 570Sstevel@tonic-gate struct netgroup_name *next_hash; 580Sstevel@tonic-gate } netgroup_name_t; 590Sstevel@tonic-gate 600Sstevel@tonic-gate typedef struct { 610Sstevel@tonic-gate netgroup_name_t *hash_list[N_HASH]; 620Sstevel@tonic-gate netgroup_name_t *to_do; 630Sstevel@tonic-gate netgroup_name_t *done; 640Sstevel@tonic-gate } netgroup_table_t; 650Sstevel@tonic-gate 660Sstevel@tonic-gate typedef struct { 670Sstevel@tonic-gate ns_ldap_result_t *results; 680Sstevel@tonic-gate ns_ldap_entry_t *entry; 690Sstevel@tonic-gate char **attrs; 700Sstevel@tonic-gate void *cookie; 710Sstevel@tonic-gate char *netgroup; 720Sstevel@tonic-gate netgroup_table_t tab; 730Sstevel@tonic-gate } getnetgrent_cookie_t; 740Sstevel@tonic-gate 750Sstevel@tonic-gate typedef struct { 760Sstevel@tonic-gate struct nss_innetgr_args *ia; 770Sstevel@tonic-gate const char *ssd_filter; 780Sstevel@tonic-gate const char *netgrname; 790Sstevel@tonic-gate const char *membername; 800Sstevel@tonic-gate netgroup_table_t tab; 810Sstevel@tonic-gate } innetgr_cookie_t; 820Sstevel@tonic-gate 830Sstevel@tonic-gate typedef unsigned int hash_t; 840Sstevel@tonic-gate 850Sstevel@tonic-gate static hash_t 860Sstevel@tonic-gate get_hash(const char *s) 870Sstevel@tonic-gate { 880Sstevel@tonic-gate unsigned int sum = 0; 890Sstevel@tonic-gate unsigned int i; 900Sstevel@tonic-gate 910Sstevel@tonic-gate for (i = 0; s[i] != '\0'; i++) 920Sstevel@tonic-gate sum += ((unsigned char *)s)[i]; 930Sstevel@tonic-gate 940Sstevel@tonic-gate return ((sum + i) % N_HASH); 950Sstevel@tonic-gate } 960Sstevel@tonic-gate 970Sstevel@tonic-gate /* 980Sstevel@tonic-gate * Adds a name to the netgroup table 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * Returns 1010Sstevel@tonic-gate * 0 if successfully added or already present 1020Sstevel@tonic-gate * -1 if memory allocation error 1030Sstevel@tonic-gate */ 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate static int 1060Sstevel@tonic-gate add_netgroup_name(const char *name, netgroup_table_t *tab) 1070Sstevel@tonic-gate { 1080Sstevel@tonic-gate hash_t h; 1090Sstevel@tonic-gate netgroup_name_t *ng; 1100Sstevel@tonic-gate netgroup_name_t *ng_new; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate if (tab == NULL || name == NULL || *name == '\0') 1130Sstevel@tonic-gate return (NULL); 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate h = get_hash(name); 1160Sstevel@tonic-gate ng = tab->hash_list[h]; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate while (ng != NULL) { 1190Sstevel@tonic-gate if (strcmp(name, ng->name) == 0) 1200Sstevel@tonic-gate break; 1210Sstevel@tonic-gate ng = ng->next_hash; 1220Sstevel@tonic-gate } 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate if (ng == NULL) { 1250Sstevel@tonic-gate ng_new = (netgroup_name_t *) 1260Sstevel@tonic-gate calloc(1, sizeof (netgroup_name_t)); 1270Sstevel@tonic-gate if (ng_new == NULL) 1280Sstevel@tonic-gate return (-1); 1290Sstevel@tonic-gate ng_new->name = strdup(name); 1300Sstevel@tonic-gate if (ng_new->name == NULL) { 1310Sstevel@tonic-gate free(ng_new); 1320Sstevel@tonic-gate return (-1); 1330Sstevel@tonic-gate } 1340Sstevel@tonic-gate ng_new->next_hash = tab->hash_list[h]; 1350Sstevel@tonic-gate tab->hash_list[h] = ng_new; 1360Sstevel@tonic-gate ng_new->next = tab->to_do; 1370Sstevel@tonic-gate tab->to_do = ng_new; 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate return (0); 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate 1420Sstevel@tonic-gate static netgroup_name_t * 1430Sstevel@tonic-gate get_next_netgroup(netgroup_table_t *tab) 1440Sstevel@tonic-gate { 1450Sstevel@tonic-gate netgroup_name_t *ng; 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate if (tab == NULL) 1480Sstevel@tonic-gate return (NULL); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate ng = tab->to_do; 1510Sstevel@tonic-gate if (ng != NULL) { 1520Sstevel@tonic-gate tab->to_do = ng->next; 1530Sstevel@tonic-gate ng->next = tab->done; 1540Sstevel@tonic-gate tab->done = ng; 1550Sstevel@tonic-gate } 1560Sstevel@tonic-gate return (ng); 1570Sstevel@tonic-gate } 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate static void 1600Sstevel@tonic-gate free_netgroup_table(netgroup_table_t *tab) 1610Sstevel@tonic-gate { 1620Sstevel@tonic-gate netgroup_name_t *ng, *next; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if (tab == NULL) 1650Sstevel@tonic-gate return; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate for (ng = tab->to_do; ng != NULL; ng = next) { 1680Sstevel@tonic-gate if (ng->name != NULL) 1690Sstevel@tonic-gate free(ng->name); 1700Sstevel@tonic-gate next = ng->next; 1710Sstevel@tonic-gate free(ng); 1720Sstevel@tonic-gate } 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate for (ng = tab->done; ng != NULL; ng = next) { 1750Sstevel@tonic-gate if (ng->name != NULL) 1760Sstevel@tonic-gate free(ng->name); 1770Sstevel@tonic-gate next = ng->next; 1780Sstevel@tonic-gate free(ng); 1790Sstevel@tonic-gate } 1800Sstevel@tonic-gate (void) memset(tab, 0, sizeof (*tab)); 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate /* 1840Sstevel@tonic-gate * domain comparing routine 1850Sstevel@tonic-gate * n1: See if n1 is n2 or an ancestor of it 1860Sstevel@tonic-gate * n2: (in string terms, n1 is a suffix of n2) 1870Sstevel@tonic-gate * Returns ZERO for success, -1 for failure. 1880Sstevel@tonic-gate */ 1890Sstevel@tonic-gate static int 1900Sstevel@tonic-gate domcmp(const char *n1, const char *n2) 1910Sstevel@tonic-gate { 1920Sstevel@tonic-gate #define PASS 0 1930Sstevel@tonic-gate #define FAIL -1 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate size_t l1, l2; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate if ((n1 == NULL) || (n2 == NULL)) 1980Sstevel@tonic-gate return (FAIL); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate l1 = strlen(n1); 2010Sstevel@tonic-gate l2 = strlen(n2); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* Turn a blind eye to the presence or absence of trailing periods */ 2040Sstevel@tonic-gate if (l1 != 0 && n1[l1 - 1] == '.') { 2050Sstevel@tonic-gate --l1; 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate if (l2 != 0 && n2[l2 - 1] == '.') { 2080Sstevel@tonic-gate --l2; 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate if (l1 > l2) { /* Can't be a suffix */ 2110Sstevel@tonic-gate return (FAIL); 2120Sstevel@tonic-gate } else if (l1 == 0) { /* Trivially a suffix; */ 2130Sstevel@tonic-gate /* (do we want this case?) */ 2140Sstevel@tonic-gate return (PASS); 2150Sstevel@tonic-gate } 2160Sstevel@tonic-gate /* So 0 < l1 <= l2 */ 2170Sstevel@tonic-gate if (l1 < l2 && n2[l2 - l1 - 1] != '.') { 2180Sstevel@tonic-gate return (FAIL); 2190Sstevel@tonic-gate } 2200Sstevel@tonic-gate if (strncasecmp(n1, &n2[l2 - l1], l1) == 0) { 2210Sstevel@tonic-gate return (PASS); 2220Sstevel@tonic-gate } else { 2230Sstevel@tonic-gate return (FAIL); 2240Sstevel@tonic-gate } 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate static int 2280Sstevel@tonic-gate split_triple(char *triple, char **hostname, char **username, char **domain) 2290Sstevel@tonic-gate { 2300Sstevel@tonic-gate int i, syntax_err; 2310Sstevel@tonic-gate char *splittriple[3]; 2320Sstevel@tonic-gate char *p = triple; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate #ifdef DEBUG 2350Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: split_triple]\n"); 2360Sstevel@tonic-gate #endif /* DEBUG */ 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate if (triple == NULL) 2390Sstevel@tonic-gate return (-1); 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate p++; 2420Sstevel@tonic-gate syntax_err = 0; 2430Sstevel@tonic-gate for (i = 0; i < 3; i++) { 2440Sstevel@tonic-gate char *start; 2450Sstevel@tonic-gate char *limit; 2460Sstevel@tonic-gate const char *terminators = ",) \t"; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate if (i == 2) { 2490Sstevel@tonic-gate /* Don't allow comma */ 2500Sstevel@tonic-gate terminators++; 2510Sstevel@tonic-gate } 2520Sstevel@tonic-gate while (isspace(*p)) { 2530Sstevel@tonic-gate p++; 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate start = p; 2560Sstevel@tonic-gate limit = strpbrk(start, terminators); 2570Sstevel@tonic-gate if (limit == 0) { 2580Sstevel@tonic-gate syntax_err++; 2590Sstevel@tonic-gate break; 2600Sstevel@tonic-gate } 2610Sstevel@tonic-gate p = limit; 2620Sstevel@tonic-gate while (isspace(*p)) { 2630Sstevel@tonic-gate p++; 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate if (*p == terminators[0]) { 2660Sstevel@tonic-gate /* 2670Sstevel@tonic-gate * Successfully parsed this name and 2680Sstevel@tonic-gate * the separator after it (comma or 2690Sstevel@tonic-gate * right paren); leave p ready for 2700Sstevel@tonic-gate * next parse. 2710Sstevel@tonic-gate */ 2720Sstevel@tonic-gate p++; 2730Sstevel@tonic-gate if (start == limit) { 2740Sstevel@tonic-gate /* Wildcard */ 2750Sstevel@tonic-gate splittriple[i] = NULL; 2760Sstevel@tonic-gate } else { 2770Sstevel@tonic-gate *limit = '\0'; 2780Sstevel@tonic-gate splittriple[i] = start; 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate } else { 2810Sstevel@tonic-gate syntax_err++; 2820Sstevel@tonic-gate break; 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate if (syntax_err != 0) 2870Sstevel@tonic-gate return (-1); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate *hostname = splittriple[0]; 2900Sstevel@tonic-gate *username = splittriple[1]; 2910Sstevel@tonic-gate *domain = splittriple[2]; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate return (0); 2940Sstevel@tonic-gate } 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate /* 2972388Smj162486 * Test membership in triple 2982388Smj162486 * return 0 = no match 2992388Smj162486 * return 1 = match 3000Sstevel@tonic-gate */ 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate static int 3030Sstevel@tonic-gate match_triple_entry(struct nss_innetgr_args *ia, const ns_ldap_entry_t *entry) 3040Sstevel@tonic-gate { 3050Sstevel@tonic-gate int ndomains; 3060Sstevel@tonic-gate char **pdomains; 3070Sstevel@tonic-gate int nhost; 3080Sstevel@tonic-gate char **phost; 3090Sstevel@tonic-gate int nusers; 3100Sstevel@tonic-gate char **pusers; 3110Sstevel@tonic-gate char **attr; 3120Sstevel@tonic-gate char triple[MAX_TRIPLE_LEN]; 3130Sstevel@tonic-gate char *tuser, *thost, *tdomain; 3140Sstevel@tonic-gate int i; 3152388Smj162486 char *current, *limit; 3162388Smj162486 int pulen, phlen; 3172388Smj162486 char *pusers0, *phost0; 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate nhost = ia->arg[NSS_NETGR_MACHINE].argc; 3200Sstevel@tonic-gate phost = (char **)ia->arg[NSS_NETGR_MACHINE].argv; 3212388Smj162486 if (phost == NULL || *phost == NULL) { 3220Sstevel@tonic-gate nhost = 0; 3232388Smj162486 } else { 3242388Smj162486 phost0 = phost[0]; 3252388Smj162486 phlen = strlen(phost0); 3262388Smj162486 } 3270Sstevel@tonic-gate nusers = ia->arg[NSS_NETGR_USER].argc; 3280Sstevel@tonic-gate pusers = (char **)ia->arg[NSS_NETGR_USER].argv; 3292388Smj162486 if (pusers == NULL || *pusers == NULL) { 3300Sstevel@tonic-gate nusers = 0; 3312388Smj162486 } else { 3322388Smj162486 pusers0 = pusers[0]; 3332388Smj162486 pulen = strlen(pusers0); 3342388Smj162486 } 3350Sstevel@tonic-gate ndomains = ia->arg[NSS_NETGR_DOMAIN].argc; 3360Sstevel@tonic-gate pdomains = (char **)ia->arg[NSS_NETGR_DOMAIN].argv; 3370Sstevel@tonic-gate if (pdomains == NULL || *pdomains == NULL) 3380Sstevel@tonic-gate ndomains = 0; 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate attr = __ns_ldap_getAttr(entry, _N_TRIPLE); 3410Sstevel@tonic-gate if (attr == NULL || *attr == NULL) 3420Sstevel@tonic-gate return (0); 3430Sstevel@tonic-gate 3442388Smj162486 /* Special cases for speedup */ 3452388Smj162486 if (nusers == 1 && nhost == 0 && ndomains == 0) { 3462388Smj162486 /* Special case for finding a single user in a netgroup */ 3472388Smj162486 for (; *attr; attr++) { 3482388Smj162486 /* jump to first comma and check next character */ 3492388Smj162486 current = *attr; 3502388Smj162486 if ((current = strchr(current, COMMA)) == NULL) 3512388Smj162486 continue; 3522388Smj162486 current++; 3532388Smj162486 3542388Smj162486 /* skip whitespaces */ 3552388Smj162486 while (isspace(*current)) 3562388Smj162486 current++; 3572388Smj162486 3582388Smj162486 /* if user part is null, then treat as wildcard */ 3592388Smj162486 if (*current == COMMA) 3602388Smj162486 return (1); 3612388Smj162486 3622388Smj162486 /* compare first character */ 3632388Smj162486 if (*pusers0 != *current) 3642388Smj162486 continue; 3652388Smj162486 3662388Smj162486 /* limit username to COMMA */ 3672388Smj162486 if ((limit = strchr(current, COMMA)) == NULL) 3682388Smj162486 continue; 3692388Smj162486 *limit = '\0'; 3702388Smj162486 3712388Smj162486 /* remove blanks before COMMA */ 3722388Smj162486 if ((limit = strpbrk(current, " \t")) != NULL) 3732388Smj162486 *limit = '\0'; 3742388Smj162486 3752388Smj162486 /* compare size of username */ 3762388Smj162486 if (pulen != strlen(current)) { 3772388Smj162486 continue; 3782388Smj162486 } 3792388Smj162486 3802388Smj162486 /* do actual compare */ 3812388Smj162486 if (strncmp(pusers0, current, pulen) == 0) { 3822388Smj162486 return (1); 3832388Smj162486 } else { 3842388Smj162486 continue; 3852388Smj162486 } 3862388Smj162486 } 3872388Smj162486 } else if (nusers == 0 && nhost == 1 && ndomains == 0) { 3882388Smj162486 /* Special case for finding a single host in a netgroup */ 3892388Smj162486 for (; *attr; attr++) { 3902388Smj162486 3912388Smj162486 /* jump to first character and check */ 3922388Smj162486 current = *attr; 3932388Smj162486 current++; 3942388Smj162486 3952388Smj162486 /* skip whitespaces */ 3962388Smj162486 while (isspace(*current)) 3972388Smj162486 current++; 3982388Smj162486 3992388Smj162486 /* if host part is null, then treat as wildcard */ 4002388Smj162486 if (*current == COMMA) 4012388Smj162486 return (1); 4022388Smj162486 4032388Smj162486 /* limit hostname to COMMA */ 4042388Smj162486 if ((limit = strchr(current, COMMA)) == NULL) 4052388Smj162486 continue; 4062388Smj162486 *limit = '\0'; 4072388Smj162486 4082388Smj162486 /* remove blanks before COMMA */ 4092388Smj162486 if ((limit = strpbrk(current, " \t")) != NULL) 4102388Smj162486 *limit = '\0'; 4112388Smj162486 4122388Smj162486 /* compare size of hostname */ 4132388Smj162486 if (phlen != strlen(current)) { 4142388Smj162486 continue; 4152388Smj162486 } 4162388Smj162486 4172388Smj162486 /* do actual compare */ 4182388Smj162486 if (strncasecmp(phost0, current, phlen) == 0) { 4192388Smj162486 return (1); 4202388Smj162486 } else { 4212388Smj162486 continue; 4222388Smj162486 } 4232388Smj162486 } 4242388Smj162486 } else { 4252388Smj162486 for (; *attr; attr++) { 4262388Smj162486 if (strlcpy(triple, *attr, 4272388Smj162486 sizeof (triple)) >= sizeof (triple)) 4282388Smj162486 continue; 4292388Smj162486 if (split_triple(triple, &thost, &tuser, &tdomain) != 0) 4302388Smj162486 continue; 4312388Smj162486 if (thost != NULL && *thost != '\0' && nhost != 0) { 4322388Smj162486 for (i = 0; i < nhost; i++) 4332388Smj162486 if (strcasecmp(thost, phost[i]) == 0) 4342388Smj162486 break; 4352388Smj162486 if (i == nhost) 4362388Smj162486 continue; 4372388Smj162486 } 4382388Smj162486 if (tuser != NULL && *tuser != '\0' && nusers != 0) { 4392388Smj162486 for (i = 0; i < nusers; i++) 4402388Smj162486 if (strcmp(tuser, pusers[i]) == 0) 4412388Smj162486 break; 4422388Smj162486 if (i == nusers) 4432388Smj162486 continue; 4442388Smj162486 } 4452388Smj162486 if (tdomain != NULL && *tdomain != '\0' && 4462388Smj162486 ndomains != 0) { 4472388Smj162486 for (i = 0; i < ndomains; i++) 4482388Smj162486 if (domcmp(tdomain, pdomains[i]) == 0) 4492388Smj162486 break; 4502388Smj162486 if (i == ndomains) 4512388Smj162486 continue; 4522388Smj162486 } 4532388Smj162486 return (1); 4542388Smj162486 } 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate 4570Sstevel@tonic-gate return (0); 4580Sstevel@tonic-gate } 4590Sstevel@tonic-gate 4600Sstevel@tonic-gate static int 4610Sstevel@tonic-gate match_triple(struct nss_innetgr_args *ia, ns_ldap_result_t *result) 4620Sstevel@tonic-gate { 4630Sstevel@tonic-gate ns_ldap_entry_t *entry; 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) 4660Sstevel@tonic-gate if (match_triple_entry(ia, entry) == 1) 4670Sstevel@tonic-gate return (1); 4680Sstevel@tonic-gate 4690Sstevel@tonic-gate return (0); 4700Sstevel@tonic-gate } 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate static int 4730Sstevel@tonic-gate add_netgroup_member_entry(ns_ldap_entry_t *entry, netgroup_table_t *tab) 4740Sstevel@tonic-gate { 4750Sstevel@tonic-gate char **attrs; 4760Sstevel@tonic-gate char **a; 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate attrs = __ns_ldap_getAttr(entry, _N_MEMBER); 4790Sstevel@tonic-gate if (attrs == NULL || *attrs == NULL) 4800Sstevel@tonic-gate return (0); 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate for (a = attrs; *a != NULL; a++) {} 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate do { 4850Sstevel@tonic-gate a--; 4860Sstevel@tonic-gate if (add_netgroup_name(*a, tab) != 0) 4870Sstevel@tonic-gate return (-1); 4880Sstevel@tonic-gate } while (a > attrs); 4890Sstevel@tonic-gate return (0); 4900Sstevel@tonic-gate } 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate static int 4930Sstevel@tonic-gate add_netgroup_member(ns_ldap_result_t *result, netgroup_table_t *tab) 4940Sstevel@tonic-gate { 4950Sstevel@tonic-gate ns_ldap_entry_t *entry; 4960Sstevel@tonic-gate int ret = 0; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate for (entry = result->entry; entry != NULL; entry = entry->next) { 4990Sstevel@tonic-gate ret = add_netgroup_member_entry(entry, tab); 5000Sstevel@tonic-gate if (ret != 0) 5010Sstevel@tonic-gate break; 5020Sstevel@tonic-gate } 5030Sstevel@tonic-gate return (ret); 5040Sstevel@tonic-gate } 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate /* 5070Sstevel@tonic-gate * top_down_search checks only checks the netgroup specified in netgrname 5080Sstevel@tonic-gate */ 5090Sstevel@tonic-gate static nss_status_t 5100Sstevel@tonic-gate top_down_search(struct nss_innetgr_args *ia, char *netgrname) 5110Sstevel@tonic-gate { 5120Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 5130Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 5140Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 5150Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 5160Sstevel@tonic-gate ns_ldap_error_t *error = NULL; 5170Sstevel@tonic-gate int rc; 5180Sstevel@tonic-gate void *cookie = NULL; 5190Sstevel@tonic-gate nss_status_t status = NSS_NOTFOUND; 5200Sstevel@tonic-gate netgroup_table_t tab; 5210Sstevel@tonic-gate netgroup_name_t *ng; 5220Sstevel@tonic-gate int ret; 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate (void) memset(&tab, 0, sizeof (tab)); 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate if (add_netgroup_name(netgrname, &tab) != 0) 5270Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate while ((ng = get_next_netgroup(&tab)) != NULL) { 5300Sstevel@tonic-gate if (_ldap_filter_name(name, ng->name, sizeof (name)) != 0) 5310Sstevel@tonic-gate break; 5320Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), _F_SETMEMBER, 5330Sstevel@tonic-gate name); 5340Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 5350Sstevel@tonic-gate break; 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), _F_SETMEMBER_SSD, name); 5380Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 5390Sstevel@tonic-gate break; 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate rc = __ns_ldap_firstEntry(_NETGROUP, searchfilter, 5420Sstevel@tonic-gate _merge_SSD_filter, netgrent_attrs, NULL, 0, &cookie, &result, 5430Sstevel@tonic-gate &error, userdata); 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 5460Sstevel@tonic-gate while (rc == NS_LDAP_SUCCESS && result != NULL) { 5470Sstevel@tonic-gate if (match_triple(ia, result) == 1) { 5480Sstevel@tonic-gate /* We found a match */ 5490Sstevel@tonic-gate ia->status = NSS_NETGR_FOUND; 5500Sstevel@tonic-gate status = NSS_SUCCESS; 5510Sstevel@tonic-gate break; 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate rc = add_netgroup_member(result, &tab); 5550Sstevel@tonic-gate (void) __ns_ldap_freeResult(&result); 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate if (rc != NS_LDAP_SUCCESS) 5580Sstevel@tonic-gate break; 5590Sstevel@tonic-gate rc = __ns_ldap_nextEntry(cookie, &result, &error); 5600Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 5610Sstevel@tonic-gate } 5620Sstevel@tonic-gate (void) __ns_ldap_freeResult(&result); 5630Sstevel@tonic-gate (void) __ns_ldap_endEntry(&cookie, &error); 5640Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate if (status == NSS_SUCCESS || 5670Sstevel@tonic-gate (rc != NS_LDAP_SUCCESS && rc != NS_LDAP_NOTFOUND)) 5680Sstevel@tonic-gate break; 5690Sstevel@tonic-gate } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate (void) __ns_ldap_freeResult(&result); 5720Sstevel@tonic-gate (void) __ns_ldap_endEntry(&cookie, &error); 5730Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 5740Sstevel@tonic-gate free_netgroup_table(&tab); 5750Sstevel@tonic-gate return (status); 5760Sstevel@tonic-gate } 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate /* 5790Sstevel@tonic-gate * __netgr_in checks only checks the netgroup specified in ngroup 5800Sstevel@tonic-gate */ 5810Sstevel@tonic-gate static nss_status_t 5820Sstevel@tonic-gate __netgr_in(void *a, char *netgrname) 5830Sstevel@tonic-gate { 5840Sstevel@tonic-gate struct nss_innetgr_args *ia = (struct nss_innetgr_args *)a; 5850Sstevel@tonic-gate nss_status_t status = NSS_NOTFOUND; 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate #ifdef DEBUG 5880Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: netgr_in]\n"); 5890Sstevel@tonic-gate (void) fprintf(stdout, "\tmachine: argc[%d]='%s' user: " 5900Sstevel@tonic-gate "argc[%d]='%s',\n\tdomain:argc[%d]='%s' " 5910Sstevel@tonic-gate "netgroup: argc[%d]='%s'\n", 5920Sstevel@tonic-gate NSS_NETGR_MACHINE, 5930Sstevel@tonic-gate PRINT_VAL(ia->arg[NSS_NETGR_MACHINE]), 5940Sstevel@tonic-gate NSS_NETGR_USER, 5950Sstevel@tonic-gate PRINT_VAL(ia->arg[NSS_NETGR_USER]), 5960Sstevel@tonic-gate NSS_NETGR_DOMAIN, 5970Sstevel@tonic-gate PRINT_VAL(ia->arg[NSS_NETGR_DOMAIN]), 5980Sstevel@tonic-gate NSS_NETGR_N, 5990Sstevel@tonic-gate PRINT_VAL(ia->arg[NSS_NETGR_N])); 6000Sstevel@tonic-gate (void) fprintf(stdout, "\tgroups='%s'\n", netgrname); 6010Sstevel@tonic-gate #endif /* DEBUG */ 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate ia->status = NSS_NETGR_NO; 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate if (netgrname == NULL) 6060Sstevel@tonic-gate return (status); 6070Sstevel@tonic-gate 6082388Smj162486 return (top_down_search(ia, netgrname)); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate /*ARGSUSED0*/ 6120Sstevel@tonic-gate static nss_status_t 6130Sstevel@tonic-gate netgr_in(ldap_backend_ptr be, void *a) 6140Sstevel@tonic-gate { 6150Sstevel@tonic-gate struct nss_innetgr_args *ia = (struct nss_innetgr_args *)a; 6160Sstevel@tonic-gate int i; 6170Sstevel@tonic-gate nss_status_t rc = (nss_status_t)NSS_NOTFOUND; 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate ia->status = NSS_NETGR_NO; 6200Sstevel@tonic-gate for (i = 0; i < ia->groups.argc; i++) { 6210Sstevel@tonic-gate rc = __netgr_in(a, ia->groups.argv[i]); 6220Sstevel@tonic-gate if (ia->status == NSS_NETGR_FOUND) 6230Sstevel@tonic-gate return (NSS_SUCCESS); 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate return (rc); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate /* 6290Sstevel@tonic-gate * 6300Sstevel@tonic-gate */ 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate static nss_status_t 6330Sstevel@tonic-gate getnetgr_ldap_setent(ldap_backend_ptr be, void *a) 6340Sstevel@tonic-gate { 6350Sstevel@tonic-gate const char *netgroup = (const char *) a; 6360Sstevel@tonic-gate getnetgrent_cookie_t *cookie; 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate #ifdef DEBUG 6390Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: getnetgr_ldap_setent]\n"); 6400Sstevel@tonic-gate #endif /* DEBUG */ 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate cookie = (getnetgrent_cookie_t *)be->netgroup_cookie; 6430Sstevel@tonic-gate if (cookie != NULL && cookie->netgroup != NULL) { 6440Sstevel@tonic-gate /* is this another set on the same netgroup */ 6450Sstevel@tonic-gate if (strcmp(cookie->netgroup, netgroup) == 0) 6460Sstevel@tonic-gate return ((nss_status_t)NSS_SUCCESS); 6470Sstevel@tonic-gate } 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate return (NSS_NOTFOUND); 6500Sstevel@tonic-gate } 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate static void 6530Sstevel@tonic-gate free_getnetgrent_cookie(getnetgrent_cookie_t **cookie) 6540Sstevel@tonic-gate { 6550Sstevel@tonic-gate ns_ldap_error_t *error = NULL; 6560Sstevel@tonic-gate getnetgrent_cookie_t *p = *cookie; 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate #ifdef DEBUG 6590Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: free_getnetgrent_cookie]\n"); 6600Sstevel@tonic-gate #endif /* DEBUG */ 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate if (p == NULL) 6630Sstevel@tonic-gate return; 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate (void) __ns_ldap_freeResult(&p->results); 6660Sstevel@tonic-gate (void) __ns_ldap_endEntry(&p->cookie, &error); 6670Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 6680Sstevel@tonic-gate free_netgroup_table(&p->tab); 6690Sstevel@tonic-gate free(p->netgroup); 6700Sstevel@tonic-gate free(p); 6710Sstevel@tonic-gate *cookie = NULL; 6720Sstevel@tonic-gate } 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /*ARGSUSED1*/ 6750Sstevel@tonic-gate static nss_status_t 6760Sstevel@tonic-gate getnetgr_ldap_endent(ldap_backend_ptr be, void *a) 6770Sstevel@tonic-gate { 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate #ifdef DEBUG 6800Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: getnetgr_ldap_endent]\n"); 6810Sstevel@tonic-gate #endif /* DEBUG */ 6820Sstevel@tonic-gate 6830Sstevel@tonic-gate free_getnetgrent_cookie((getnetgrent_cookie_t **)&be->netgroup_cookie); 6840Sstevel@tonic-gate 6850Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 6860Sstevel@tonic-gate } 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate /*ARGSUSED1*/ 6900Sstevel@tonic-gate static nss_status_t 6910Sstevel@tonic-gate getnetgr_ldap_destr(ldap_backend_ptr be, void *a) 6920Sstevel@tonic-gate { 6930Sstevel@tonic-gate 6940Sstevel@tonic-gate #ifdef DEBUG 6950Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: getnetgr_ldap_destr]\n"); 6960Sstevel@tonic-gate #endif /* DEBUG */ 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate free_getnetgrent_cookie((getnetgrent_cookie_t **)&be->netgroup_cookie); 6990Sstevel@tonic-gate free(be); 7000Sstevel@tonic-gate 7010Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 7020Sstevel@tonic-gate } 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate static nss_status_t 7060Sstevel@tonic-gate getnetgr_ldap_getent(ldap_backend_ptr be, void *a) 7070Sstevel@tonic-gate { 7080Sstevel@tonic-gate struct nss_getnetgrent_args *args; 7090Sstevel@tonic-gate getnetgrent_cookie_t *p; 7100Sstevel@tonic-gate char searchfilter[SEARCHFILTERLEN]; 7110Sstevel@tonic-gate char userdata[SEARCHFILTERLEN]; 7120Sstevel@tonic-gate char name[SEARCHFILTERLEN]; 7130Sstevel@tonic-gate int rc; 7140Sstevel@tonic-gate void *cookie = NULL; 7150Sstevel@tonic-gate ns_ldap_result_t *result = NULL; 7160Sstevel@tonic-gate ns_ldap_error_t *error = NULL; 7170Sstevel@tonic-gate char **attrs; 7180Sstevel@tonic-gate char *hostname, *username, *domain; 7190Sstevel@tonic-gate char *buffer; 7200Sstevel@tonic-gate nss_status_t status = NSS_SUCCESS; 7210Sstevel@tonic-gate netgroup_name_t *ng; 7220Sstevel@tonic-gate int ret; 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate #ifdef DEBUG 7250Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: getnetgr_ldap_getent]\n"); 7260Sstevel@tonic-gate #endif /* DEBUG */ 7270Sstevel@tonic-gate 7280Sstevel@tonic-gate args = (struct nss_getnetgrent_args *)a; 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate args->status = NSS_NETGR_NO; 7310Sstevel@tonic-gate 7320Sstevel@tonic-gate p = (getnetgrent_cookie_t *)be->netgroup_cookie; 7330Sstevel@tonic-gate if (p == NULL) 7340Sstevel@tonic-gate return ((nss_status_t)NSS_SUCCESS); 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate for (;;) { 7370Sstevel@tonic-gate while (p->cookie == NULL) { 7380Sstevel@tonic-gate ng = get_next_netgroup(&p->tab); 7390Sstevel@tonic-gate if (ng == NULL) /* no more */ 7400Sstevel@tonic-gate break; 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate if (_ldap_filter_name(name, ng->name, sizeof (name)) != 0) 7430Sstevel@tonic-gate break; 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate ret = snprintf(searchfilter, sizeof (searchfilter), 7460Sstevel@tonic-gate _F_SETMEMBER, name); 7470Sstevel@tonic-gate if (ret >= sizeof (searchfilter) || ret < 0) 7480Sstevel@tonic-gate break; 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate ret = snprintf(userdata, sizeof (userdata), _F_SETMEMBER_SSD, 7510Sstevel@tonic-gate name); 7520Sstevel@tonic-gate if (ret >= sizeof (userdata) || ret < 0) 7530Sstevel@tonic-gate break; 7540Sstevel@tonic-gate 7550Sstevel@tonic-gate result = NULL; 7560Sstevel@tonic-gate rc = __ns_ldap_firstEntry(_NETGROUP, searchfilter, 7570Sstevel@tonic-gate _merge_SSD_filter, netgrent_attrs, NULL, 0, &cookie, 7580Sstevel@tonic-gate &result, &error, userdata); 7590Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS && result != NULL) { 7620Sstevel@tonic-gate p->cookie = cookie; 7630Sstevel@tonic-gate p->results = result; 7640Sstevel@tonic-gate break; 7650Sstevel@tonic-gate } 7660Sstevel@tonic-gate (void) __ns_ldap_freeResult(&result); 7670Sstevel@tonic-gate (void) __ns_ldap_endEntry(&cookie, &error); 7680Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 7690Sstevel@tonic-gate } 7700Sstevel@tonic-gate if (p->cookie == NULL) 7710Sstevel@tonic-gate break; 7720Sstevel@tonic-gate if (p->results == NULL) { 7730Sstevel@tonic-gate result = NULL; 7740Sstevel@tonic-gate rc = __ns_ldap_nextEntry(p->cookie, &result, &error); 7750Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 7760Sstevel@tonic-gate if (rc == NS_LDAP_SUCCESS && result != NULL) 7770Sstevel@tonic-gate p->results = result; 7780Sstevel@tonic-gate else { 7790Sstevel@tonic-gate (void) __ns_ldap_freeResult(&result); 7800Sstevel@tonic-gate (void) __ns_ldap_endEntry(&p->cookie, &error); 7810Sstevel@tonic-gate (void) __ns_ldap_freeError(&error); 7820Sstevel@tonic-gate p->cookie = NULL; 7830Sstevel@tonic-gate } 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate if (p->results == NULL) 7860Sstevel@tonic-gate continue; 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate if (p->entry == NULL) 7890Sstevel@tonic-gate p->entry = p->results->entry; 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate if (p->entry == NULL) 7920Sstevel@tonic-gate continue; 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate if (p->attrs == NULL) { 7950Sstevel@tonic-gate attrs = __ns_ldap_getAttr(p->entry, _N_TRIPLE); 7960Sstevel@tonic-gate if (attrs != NULL && *attrs != NULL) 7970Sstevel@tonic-gate p->attrs = attrs; 7980Sstevel@tonic-gate } 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate if (p->attrs != NULL) { 8010Sstevel@tonic-gate attrs = p->attrs; 8020Sstevel@tonic-gate buffer = args->buffer; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate if (strlcpy(buffer, *attrs, args->buflen) >= args->buflen) { 8050Sstevel@tonic-gate status = NSS_STR_PARSE_ERANGE; 8060Sstevel@tonic-gate break; 8070Sstevel@tonic-gate } 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate rc = split_triple(buffer, &hostname, &username, &domain); 8100Sstevel@tonic-gate attrs++; 8110Sstevel@tonic-gate if (attrs != NULL && *attrs != NULL) 8120Sstevel@tonic-gate p->attrs = attrs; 8130Sstevel@tonic-gate else 8140Sstevel@tonic-gate p->attrs = NULL; 8150Sstevel@tonic-gate if (rc == 0) { 8160Sstevel@tonic-gate args->retp[NSS_NETGR_MACHINE] = hostname; 8170Sstevel@tonic-gate args->retp[NSS_NETGR_USER] = username; 8180Sstevel@tonic-gate args->retp[NSS_NETGR_DOMAIN] = domain; 8190Sstevel@tonic-gate args->status = NSS_NETGR_FOUND; 8200Sstevel@tonic-gate if (p->attrs != NULL) 8210Sstevel@tonic-gate break; 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate } 8240Sstevel@tonic-gate 8250Sstevel@tonic-gate if (p->attrs == NULL) { 8260Sstevel@tonic-gate rc = add_netgroup_member_entry(p->entry, &p->tab); 8270Sstevel@tonic-gate if (rc != 0) { 8280Sstevel@tonic-gate args->status = NSS_NETGR_NO; 8290Sstevel@tonic-gate break; 8300Sstevel@tonic-gate } 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate p->entry = p->entry->next; 8330Sstevel@tonic-gate if (p->entry == NULL) 8340Sstevel@tonic-gate (void) __ns_ldap_freeResult(&p->results); 8350Sstevel@tonic-gate if (args->status == NSS_NETGR_FOUND) 8360Sstevel@tonic-gate break; 8370Sstevel@tonic-gate } 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate return (status); 8410Sstevel@tonic-gate } 8420Sstevel@tonic-gate 8430Sstevel@tonic-gate static ldap_backend_op_t getnetgroup_ops[] = { 8440Sstevel@tonic-gate getnetgr_ldap_destr, 8450Sstevel@tonic-gate getnetgr_ldap_endent, 8460Sstevel@tonic-gate getnetgr_ldap_setent, 8470Sstevel@tonic-gate getnetgr_ldap_getent, 8480Sstevel@tonic-gate }; 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate /* 8510Sstevel@tonic-gate * 8520Sstevel@tonic-gate */ 8530Sstevel@tonic-gate 8540Sstevel@tonic-gate static nss_status_t 8550Sstevel@tonic-gate netgr_set(ldap_backend_ptr be, void *a) 8560Sstevel@tonic-gate { 8570Sstevel@tonic-gate struct nss_setnetgrent_args *args = 8580Sstevel@tonic-gate (struct nss_setnetgrent_args *)a; 8590Sstevel@tonic-gate ldap_backend_ptr get_be; 8600Sstevel@tonic-gate getnetgrent_cookie_t *p; 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate #ifdef DEBUG 8630Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: netgr_set]\n"); 8640Sstevel@tonic-gate (void) fprintf(stdout, 8650Sstevel@tonic-gate "\targs->netgroup: %s\n", ISNULL(args->netgroup)); 8660Sstevel@tonic-gate #endif /* DEBUG */ 8670Sstevel@tonic-gate 8680Sstevel@tonic-gate if (args->netgroup == NULL) 8690Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate free_getnetgrent_cookie((getnetgrent_cookie_t **)&be->netgroup_cookie); 8720Sstevel@tonic-gate p = (getnetgrent_cookie_t *)calloc(1, sizeof (getnetgrent_cookie_t)); 8730Sstevel@tonic-gate if (p == NULL) 8740Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 8750Sstevel@tonic-gate p->netgroup = strdup(args->netgroup); 8760Sstevel@tonic-gate if (p->netgroup == NULL) { 8770Sstevel@tonic-gate free(p); 8780Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 8790Sstevel@tonic-gate } 8800Sstevel@tonic-gate if (add_netgroup_name(args->netgroup, &p->tab) == -1) { 8810Sstevel@tonic-gate free_getnetgrent_cookie(&p); 8820Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate 8850Sstevel@tonic-gate /* now allocate and return iteration backend structure */ 8860Sstevel@tonic-gate if ((get_be = (ldap_backend_ptr)malloc(sizeof (*get_be))) == NULL) 8870Sstevel@tonic-gate return (NSS_UNAVAIL); 8880Sstevel@tonic-gate get_be->ops = getnetgroup_ops; 8890Sstevel@tonic-gate get_be->nops = sizeof (getnetgroup_ops) / sizeof (getnetgroup_ops[0]); 8900Sstevel@tonic-gate get_be->tablename = NULL; 8910Sstevel@tonic-gate get_be->attrs = netgrent_attrs; 8920Sstevel@tonic-gate get_be->result = NULL; 893*2830Sdjl get_be->ldapobj2str = NULL; 8940Sstevel@tonic-gate get_be->setcalled = 1; 8950Sstevel@tonic-gate get_be->filter = NULL; 8960Sstevel@tonic-gate get_be->toglue = NULL; 8970Sstevel@tonic-gate get_be->enumcookie = NULL; 8980Sstevel@tonic-gate get_be->netgroup_cookie = p; 8990Sstevel@tonic-gate args->iterator = (nss_backend_t *)get_be; 9000Sstevel@tonic-gate 9010Sstevel@tonic-gate (void) __ns_ldap_freeResult(&be->result); 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate return (NSS_SUCCESS); 9040Sstevel@tonic-gate } 9050Sstevel@tonic-gate 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate /*ARGSUSED1*/ 9080Sstevel@tonic-gate static nss_status_t 9090Sstevel@tonic-gate netgr_ldap_destr(ldap_backend_ptr be, void *a) 9100Sstevel@tonic-gate { 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate #ifdef DEBUG 9130Sstevel@tonic-gate (void) fprintf(stdout, "\n[getnetgrent.c: netgr_ldap_destr]\n"); 9140Sstevel@tonic-gate #endif /* DEBUG */ 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate (void) _clean_ldap_backend(be); 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate return ((nss_status_t)NSS_NOTFOUND); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate 9240Sstevel@tonic-gate static ldap_backend_op_t netgroup_ops[] = { 9250Sstevel@tonic-gate netgr_ldap_destr, 9260Sstevel@tonic-gate 0, 9270Sstevel@tonic-gate 0, 9280Sstevel@tonic-gate 0, 9290Sstevel@tonic-gate netgr_in, /* innetgr() */ 9300Sstevel@tonic-gate netgr_set /* setnetgrent() */ 9310Sstevel@tonic-gate }; 9320Sstevel@tonic-gate 9330Sstevel@tonic-gate 9340Sstevel@tonic-gate /* 9350Sstevel@tonic-gate * _nss_ldap_netgroup_constr is where life begins. This function calls the 9360Sstevel@tonic-gate * generic ldap constructor function to define and build the abstract data 9370Sstevel@tonic-gate * types required to support ldap operations. 9380Sstevel@tonic-gate */ 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate /*ARGSUSED0*/ 9410Sstevel@tonic-gate nss_backend_t * 9420Sstevel@tonic-gate _nss_ldap_netgroup_constr(const char *dummy1, const char *dummy2, 9430Sstevel@tonic-gate const char *dummy3) 9440Sstevel@tonic-gate { 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate #ifdef DEBUG 9470Sstevel@tonic-gate (void) fprintf(stdout, 9480Sstevel@tonic-gate "\n[getnetgrent.c: _nss_ldap_netgroup_constr]\n"); 9490Sstevel@tonic-gate #endif /* DEBUG */ 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate return ((nss_backend_t *)_nss_ldap_constr(netgroup_ops, 9520Sstevel@tonic-gate sizeof (netgroup_ops)/sizeof (netgroup_ops[0]), _NETGROUP, 9530Sstevel@tonic-gate netgrent_attrs, NULL)); 9540Sstevel@tonic-gate } 955