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