From: Zoran V. <vas...@us...> - 2005-02-26 13:21:41
|
Update of /cvsroot/naviserver/naviserver/nsd In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2925/nsd Modified Files: unix.c Log Message: Added Ns_GetNameForUid(), Ns_GetNameForGid() Index: unix.c =================================================================== RCS file: /cvsroot/naviserver/naviserver/nsd/unix.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** unix.c 16 Feb 2005 08:40:15 -0000 1.1.1.1 --- unix.c 26 Feb 2005 13:21:22 -0000 1.2 *************** *** 1,7 **** /* ! * The contents of this file are subject to the AOLserver Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at ! * http://aolserver.com/. * * Software distributed under the License is distributed on an "AS IS" --- 1,7 ---- /* ! * The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at ! * http://mozilla.org/. * * Software distributed under the License is distributed on an "AS IS" *************** *** 32,36 **** * unix.c -- * ! * Unix specific routines. */ --- 32,36 ---- * unix.c -- * ! * Unix specific routines. */ *************** *** 50,61 **** * FatalSignalHandler -- * ! * Ensure that we drop core on fatal signals like SIGBUS and ! * SIGSEGV. * * Results: ! * None. * * Side effects: ! * A core file will be left wherever the server was running. * *---------------------------------------------------------------------- --- 50,61 ---- * FatalSignalHandler -- * ! * Ensure that we drop core on fatal signals like SIGBUS and ! * SIGSEGV. * * Results: ! * None. * * Side effects: ! * A core file will be left wherever the server was running. * *---------------------------------------------------------------------- *************** *** 85,95 **** * NsBlockSignals -- * ! * Block signals at startup. * * Results: ! * None. * * Side effects: ! * Signals will be pending until NsHandleSignals. * *---------------------------------------------------------------------- --- 85,95 ---- * NsBlockSignals -- * ! * Block signals at startup. * * Results: ! * None. * * Side effects: ! * Signals will be pending until NsHandleSignals. * *---------------------------------------------------------------------- *************** *** 139,143 **** * NsRestoreSignals -- * ! * Restore all signals to their default value. * * Results: --- 139,143 ---- * NsRestoreSignals -- * ! * Restore all signals to their default value. * * Results: *************** *** 153,158 **** NsRestoreSignals(void) { ! sigset_t set; ! int sig; for (sig = 1; sig < NSIG; ++sig) { --- 153,158 ---- NsRestoreSignals(void) { ! sigset_t set; ! int sig; for (sig = 1; sig < NSIG; ++sig) { *************** *** 169,180 **** * NsHandleSignals -- * ! * Loop forever processing signals until a term signal ! * is received. * * Results: ! * None. * * Side effects: ! * HUP callbacks may be called. * *---------------------------------------------------------------------- --- 169,180 ---- * NsHandleSignals -- * ! * Loop forever processing signals until a term signal ! * is received. * * Results: ! * None. * * Side effects: ! * HUP callbacks may be called. * *---------------------------------------------------------------------- *************** *** 198,210 **** } do { ! do { ! err = ns_sigwait(&set, &sig); ! } while (err == EINTR); ! if (err != 0) { ! Ns_Fatal("signal: ns_sigwait failed: %s", strerror(errno)); ! } ! if (sig == SIGHUP) { ! NsRunSignalProcs(); ! } } while (sig == SIGHUP); --- 198,210 ---- } do { ! do { ! err = ns_sigwait(&set, &sig); ! } while (err == EINTR); ! if (err != 0) { ! Ns_Fatal("signal: ns_sigwait failed: %s", strerror(errno)); ! } ! if (sig == SIGHUP) { ! NsRunSignalProcs(); ! } } while (sig == SIGHUP); *************** *** 222,232 **** * NsSendSignal -- * ! * Send a signal to the main thread. * * Results: ! * None. * * Side effects: ! * Main thread in NsHandleSignals will wakeup. * *---------------------------------------------------------------------- --- 222,232 ---- * NsSendSignal -- * ! * Send a signal to the main thread. * * Results: ! * None. * * Side effects: ! * Main thread in NsHandleSignals will wakeup. * *---------------------------------------------------------------------- *************** *** 236,241 **** NsSendSignal(int sig) { ! if (kill(Ns_InfoPid(), sig) != 0) { ! Ns_Fatal("unix: kill() failed: '%s'", strerror(errno)); } } --- 236,241 ---- NsSendSignal(int sig) { ! if (kill(Ns_InfoPid(), sig) != 0) { ! Ns_Fatal("unix: kill() failed: '%s'", strerror(errno)); } } *************** *** 263,273 **** if (sockpair) { ! err = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); } else { ! err = pipe(fds); } if (!err) { ! fcntl(fds[0], F_SETFD, 1); ! fcntl(fds[1], F_SETFD, 1); } return err; --- 263,273 ---- if (sockpair) { ! err = socketpair(AF_UNIX, SOCK_STREAM, 0, fds); } else { ! err = pipe(fds); } if (!err) { ! fcntl(fds[0], F_SETFD, 1); ! fcntl(fds[1], F_SETFD, 1); } return err; *************** *** 289,302 **** /* *---------------------------------------------------------------------- ! * Ns_GetUserHome -- * ! * Get the home directory name for a user name * * Results: ! * Return NS_TRUE if user name is found in /etc/passwd file and ! * NS_FALSE otherwise. * * Side effects: ! * None. * *---------------------------------------------------------------------- --- 289,301 ---- /* *---------------------------------------------------------------------- ! * Ns_GetNameForUid -- * ! * Get the user name given the id * * Results: ! * NS_TRUE if id is found; NS_FALSE otherwise. * * Side effects: ! * None. * *---------------------------------------------------------------------- *************** *** 304,322 **** int ! Ns_GetUserHome(Ns_DString *pds, char *user) { ! struct passwd *pw; ! int retcode; Ns_MutexLock(&lock); ! pw = getpwnam(user); ! if (pw == NULL) { ! retcode = NS_FALSE; ! } else { ! Ns_DStringAppend(pds, pw->pw_dir); ! retcode = NS_TRUE; } Ns_MutexUnlock(&lock); ! return retcode; } --- 303,317 ---- int ! Ns_GetNameForUid(Ns_DString *dsPtr, int uid) { ! struct passwd *pw = NULL; Ns_MutexLock(&lock); ! pw = getpwuid((uid_t)uid); ! if (pw != NULL && dsPtr) { ! Ns_DStringAppend(dsPtr, pw->pw_name); } Ns_MutexUnlock(&lock); ! return (pw != NULL) ? NS_TRUE : NS_FALSE; } *************** *** 324,333 **** /* *---------------------------------------------------------------------- ! * Ns_GetGid -- * ! * Get the group id from a group name. * * Results: ! * Group id or -1 if not found. * * Side effects: --- 319,328 ---- /* *---------------------------------------------------------------------- ! * Ns_GetNameForGid -- * ! * Get the group name given the id * * Results: ! * NS_TRUE if id is found; NS_FALSE otherwise. * * Side effects: *************** *** 338,355 **** int ! Ns_GetGid(char *group) { ! int retcode; ! struct group *grent; Ns_MutexLock(&lock); ! grent = getgrnam(group); ! if (grent == NULL) { ! retcode = -1; ! } else { ! retcode = grent->gr_gid; } Ns_MutexUnlock(&lock); ! return retcode; } --- 333,380 ---- int ! Ns_GetNameForGid(Ns_DString *dsPtr, int gid) { ! struct group *gr = NULL; Ns_MutexLock(&lock); ! gr = getgrgid((gid_t)gid); ! if (gr != NULL && dsPtr) { ! Ns_DStringAppend(dsPtr, gr->gr_name); } Ns_MutexUnlock(&lock); ! ! return (gr != NULL) ? NS_TRUE : NS_FALSE; ! } ! ! ! /* ! *---------------------------------------------------------------------- ! * Ns_GetUserHome -- ! * ! * Get the home directory name for a user name ! * ! * Results: ! * Return NS_TRUE if user name is found in /etc/passwd file and ! * NS_FALSE otherwise. ! * ! * Side effects: ! * None. ! * ! *---------------------------------------------------------------------- ! */ ! ! int ! Ns_GetUserHome(Ns_DString *ds, char *user) ! { ! struct passwd *pw = NULL; ! ! Ns_MutexLock(&lock); ! pw = getpwnam(user); ! if (pw != NULL) { ! Ns_DStringAppend(ds, pw->pw_dir); ! } ! Ns_MutexUnlock(&lock); ! ! return (pw != NULL) ? NS_TRUE : NS_FALSE; } *************** *** 362,367 **** * * Results: ! * Returns group id of the user name found in /etc/passwd or -1 ! * otherwise. * * Side effects: --- 387,391 ---- * * Results: ! * Group id or -1 if not found. * * Side effects: *************** *** 374,379 **** Ns_GetUserGid(char *user) { ! struct passwd *pw; ! int retcode; Ns_MutexLock(&lock); --- 398,403 ---- Ns_GetUserGid(char *user) { ! struct passwd *pw; ! int retcode; Ns_MutexLock(&lock); *************** *** 382,386 **** retcode = -1; } else { ! retcode = pw->pw_gid; } Ns_MutexUnlock(&lock); --- 406,410 ---- retcode = -1; } else { ! retcode = (int) pw->pw_gid; } Ns_MutexUnlock(&lock); *************** *** 396,401 **** * * Results: ! * Return NS_TRUE if user name is found in /etc/passwd file and ! * NS_FALSE otherwise. * * Side effects: --- 420,424 ---- * * Results: ! * User id or -1 if not found. * * Side effects: *************** *** 408,412 **** Ns_GetUid(char *user) { ! struct passwd *pw; int retcode; --- 431,435 ---- Ns_GetUid(char *user) { ! struct passwd *pw; int retcode; *************** *** 416,422 **** retcode = -1; } else { ! retcode = (unsigned) pw->pw_uid; } Ns_MutexUnlock(&lock); return retcode; } --- 439,479 ---- retcode = -1; } else { ! retcode = (int) pw->pw_uid; } Ns_MutexUnlock(&lock); + + return retcode; + } + + /* + *---------------------------------------------------------------------- + * Ns_GetGid -- + * + * Get the group id from a group name. + * + * Results: + * Group id or -1 if not found. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------- + */ + + int + Ns_GetGid(char *group) + { + struct group *gr; + int retcode; + + Ns_MutexLock(&lock); + gr = getgrnam(group); + if (gr == NULL) { + retcode = -1; + } else { + retcode = (int) gr->gr_gid; + } + Ns_MutexUnlock(&lock); + return retcode; } |