WvStreams
wvuid.cc
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * Portable standins for getuid() and friends.  See wvuid.h.
00006  */ 
00007 #include "wvautoconf.h"
00008 #include "wvuid.h"
00009 #include <unistd.h>
00010 
00011 #if WIN32
00012 
00013 
00014 WvString wv_username_from_uid(wvuid_t uid)
00015 {
00016     // FIXME not implemented
00017     return WvString::null;
00018 }
00019 
00020 
00021 wvuid_t wv_uid_from_username(WvString username)
00022 {
00023     // FIXME not implemented
00024     return WVUID_INVALID;
00025 }
00026 
00027 
00028 wvuid_t wvgetuid()
00029 {
00030     // FIXME not implemented
00031     return WVUID_INVALID;
00032 }
00033 
00034 
00035 #else // not WIN32
00036 
00037 
00038 WvString wv_username_from_uid(wvuid_t uid)
00039 {
00040     char buf[1024];
00041     struct passwd pwbuf, *userinfo;
00042     
00043     if (getpwuid_r(uid, &pwbuf, buf, sizeof(buf), &userinfo) == 0)
00044         return userinfo->pw_name;
00045     else
00046         return WvString::null;
00047 }
00048 
00049 
00050 wvuid_t wv_uid_from_username(WvString username)
00051 {
00052     char buf[1024];
00053     struct passwd pwbuf, *userinfo;
00054     
00055     if (getpwnam_r(username, &pwbuf, buf, sizeof(buf), &userinfo) != 0)
00056         return userinfo->pw_uid;
00057     else
00058         return WVUID_INVALID;
00059 }
00060 
00061 
00062 wvuid_t wvgetuid()
00063 {
00064     return getuid();
00065 }
00066 
00067 
00068 #endif