2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 2N/A * Use is subject to license terms. 2N/A * This module fetches group and passwd structs for the caller. It 2N/A * uses a hash table to speed up retrieval of repeated entries. If 2N/A * the attempts to initialize the hash tables fail, this just 2N/A * continues the slow way. 2N/A#
define ERR_NOPWD "dup_pw_ent(): no passwd entry provided.\n" 2N/A * These indicate whether the hash table has been initialized for the four 2N/A * If there's a grnam cache, then update it with this new 2N/A * group, otherwise, skip it. 2N/A * Allocate space for the Item pointer, key and data. 2N/A /* Set length parameters. */ 2N/A/* Get the required group structure based upon the group name. */ 2N/A /* Attempt to initialize the grname cache. */ 2N/A /* First look in the cache. Failing that, do it the hard way. */ 2N/A /* Get the group by name. */ 2N/A /* A group by that name exists on this machine. */ 2N/A * Effectively no such group since struct 2N/A * couldn't be duplicated. 2N/A * If there's a grnam cache, then update it with this 2N/A * new group, otherwise, skip it. 2N/A * With that allocated, insert the 2N/A * group name as key and set the key 2N/A * Insert the data associated with 2N/A * the key and the data length. 2N/A /* Insert the Item into the cache. */ 2N/A }
else /* Found it in the cache. */ 2N/A /* First look in the cache. Failing that, do it the hard way. */ 2N/A /* Get the passwd by name. */ 2N/A /* A passwd by that name exists on this machine. */ 2N/A * Effectively no such passwd since struct 2N/A * couldn't be duplicated. 2N/A * If there's a pwnam cache, then update it with this 2N/A * new passwd, otherwise, skip it. 2N/A * Allocate space for the Item pointer, key 2N/A * With that allocated, insert the 2N/A * group name as key and set the key 2N/A * Insert the data associated with 2N/A * the key and the data length. 2N/A }
else /* Found it in the cache. */ 2N/A /* First look in the cache. Failing that, do it the hard way. */ 2N/A /* A group by that number exists on this machine. */ 2N/A * Effectively no such group since struct 2N/A * couldn't be duplicated. 2N/A * If there's a grnam cache, then update it with this 2N/A * new group, otherwise, skip it. 2N/A * With that allocated, insert the 2N/A * group name as key and set the key 2N/A * Insert the data associated with 2N/A * the key and the data length. 2N/A }
else /* Found it in the cache. */ 2N/A /* First look in the cache. Failing that, do it the hard way. */ 2N/A /* Get the passwd by number. */ 2N/A /* A passwd by that user ID exists on this machine. */ 2N/A * Effectively no such passwd since struct 2N/A * couldn't be duplicated. 2N/A * If there's a pwuid cache, then update it with this 2N/A * new passwd, otherwise, skip it. 2N/A * With that allocated, insert the 2N/A * group name as key and set the key 2N/A * Insert the data associated with 2N/A * the key and the data length. 2N/A }
else /* Found it in the cache. */ 2N/A * This function duplicates the group structure provided from kernel static 2N/A * memory. There is a lot of defensive coding here because there have been 2N/A * problems with the getgr*() functions. They will sometimes provide NULL 2N/A * values instead of pointers to NULL values. There has been no explanation 2N/A * for the reason behind this; but, this function takes a NULL to be an 2N/A * invalid (char *) and returns an error. 2N/A int nent = 0;
/* Number of entries in the member list. */ 2N/A "unknown",
"group");
2N/A * Allocate space for the member list and move the members 2N/A * First count the members. The nent variable will be 2N/A * the number of members + 1 for the terminator. 2N/A /* Now allocate room for the pointers. */ 2N/A * Now copy over the pointers and entries. It should 2N/A * be noted that if the structure is messed up here, 2N/A * the resulting member list will be truncated at the 2N/A * This function duplicates the passwd structure provided from kernel static 2N/A * memory. As in the above function, since there have been problems with the 2N/A * getpw*() functions, the structure provided is rigorously scrubbed. This 2N/A * function takes a NULL to be an invalid (char *) and returns an error if 2N/A "unknown",
"passwd");
2N/A * returns a pointer to the group structure if the group is found 2N/A * returns NULL if not found 2N/A * returns a pointer to the passwd structure if the passwd is found 2N/A * returns NULL if not found 2N/A * returns a pointer to the group structure if the group id is found 2N/A * returns NULL if not found 2N/A * returns a pointer to the passwd structure if the user id is found 2N/A * returns NULL if not found