1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 23 /* All Rights Reserved */ 24 25 26 #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */ 27 /* 28 * convert uid to login name; interface to getpwuid that keeps up to USIZE1 29 * names to avoid unnecessary accesses to passwd file 30 * returns ptr to NSZ-byte name (not necessarily null-terminated) 31 * returns ptr to "?" if cannot convert 32 */ 33 34 #include <stdio.h> 35 #include <sys/types.h> 36 #include <sys/param.h> 37 #include "acctdef.h" 38 #include <pwd.h> 39 40 static usize1; 41 static struct ulist { 42 char uname[NSZ]; 43 uid_t uuid; 44 } ul[USIZE1]; 45 46 char *strncpy(); 47 48 char * 49 uidtonam(uid) 50 uid_t uid; 51 { 52 register struct ulist *up; 53 struct passwd *getpwuid(); 54 register struct passwd *pp; 55 56 for (up = ul; up < &ul[usize1]; up++) 57 if (uid == up->uuid) 58 return(up->uname); 59 setpwent(); 60 if ((pp = getpwuid(uid)) == NULL) 61 return("?"); 62 else { 63 if (usize1 < USIZE1) { 64 up->uuid = uid; 65 CPYN(up->uname, pp->pw_name); 66 usize1++; 67 } 68 return(pp->pw_name); 69 } 70 } 71