/* * CDE - Common Desktop Environment * * Copyright (c) 1993-2012, The Open Group. All rights reserved. * * These libraries and programs are free software; you can * redistribute them and/or modify them under the terms of the GNU * Lesser General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) * any later version. * * These libraries and programs are distributed in the hope that * they will be useful, but WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR * PURPOSE. See the GNU Lesser General Public License for more * details. * * You should have received a copy of the GNU Lesser General Public * License along with these librararies and programs; if not, write * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth * Floor, Boston, MA 02110-1301 USA */ /* $XConsortium: struid.c /main/3 1995/11/01 18:51:23 rswiston $ */ /*************************************************************** * * * AT&T - PROPRIETARY * * * * THIS IS PROPRIETARY SOURCE CODE LICENSED BY * * AT&T CORP. * * * * Copyright (c) 1995 AT&T Corp. * * All Rights Reserved * * * * This software is licensed by AT&T Corp. * * under the terms and conditions of the license in * * http://www.research.att.com/orgs/ssr/book/reuse * * * * This software was created by the * * Software Engineering Research Department * * AT&T Bell Laboratories * * * * For further information contact * * gsf@research.att.com * * * ***************************************************************/ /* : : generated by proto : : */ #if !defined(__PROTO__) #if defined(__STDC__) || defined(__cplusplus) || defined(_proto) || defined(c_plusplus) #if defined(__cplusplus) #define __MANGLE__ "C" #else #define __MANGLE__ #endif #define __STDARG__ #define __PROTO__(x) x #define __OTORP__(x) #define __PARAM__(n,o) n #if !defined(__STDC__) && !defined(__cplusplus) #if !defined(c_plusplus) #define const #endif #define signed #define void int #define volatile #define __V_ char #else #define __V_ void #endif #else #define __PROTO__(x) () #define __OTORP__(x) x #define __PARAM__(n,o) o #define __MANGLE__ #define __V_ char #define const #define signed #define void int #define volatile #endif #if defined(__cplusplus) || defined(c_plusplus) #define __VARARG__ ... #else #define __VARARG__ #endif #if defined(__STDARG__) #define __VA_START__(p,a) va_start(p,a) #else #define __VA_START__(p,a) va_start(p) #endif #endif #if defined(__STDPP__directive) && defined(__STDPP__hide) __STDPP__directive pragma pp:hide getpwnam getpwuid #else #define getpwnam ______getpwnam #define getpwuid ______getpwuid #endif #include #include /* on linux pwd.h can include FILE without stdio.h which clashes with sfio_t */ #if defined(linux) #ifndef __FILE_defined #define __FILE_defined 1 #endif #endif #include #if defined(__STDPP__directive) && defined(__STDPP__hide) __STDPP__directive pragma pp:nohide getpwnam getpwuid #else #undef getpwnam #undef getpwuid #endif extern __MANGLE__ struct passwd* getpwnam __PROTO__((const char*)); extern __MANGLE__ struct passwd* getpwuid __PROTO__((uid_t)); typedef struct { HASH_HEADER; int id; } bucket; /* * return uid number given uid name * -1 on first error for a given name * -2 on subsequent errors for a given name */ int struid __PARAM__((const char* name), (name)) __OTORP__(const char* name;){ register struct passwd* pw; register bucket* b; char* e; static Hash_table_t* uidtab; if (!uidtab && !(uidtab = hashalloc(NiL, HASH_set, HASH_ALLOCATE, HASH_name, "uidnam", 0))) return(-1); if (b = (bucket*)hashlook(uidtab, name, HASH_LOOKUP|HASH_FIXED, (char*)sizeof(bucket))) return(b->id); if (!(b = (bucket*)hashlook(uidtab, NiL, HASH_CREATE|HASH_FIXED, (char*)sizeof(bucket)))) return(-1); if (pw = getpwnam(name)) return(b->id = pw->pw_uid); b->id = strtol(name, &e, 0); if (!*e && getpwuid(b->id)) return(b->id); b->id = -2; return(-1); }