6
* This file contains hes_getpwnam, for retrieving passwd information about
9
* For copying and distribution information, see the file
10
* <lt> mit-copyright.h <gt>
12
* Original version by Steve Dyer, IBM/Project Athena.
14
* WSHelper DNS/Hesiod Library for WINSOCK
19
/* This file contains hes_getpwnam, for retrieving passwd information about
22
* For copying and distribution information, see the file <mit-copyright.h>
24
* Original version by Steve Dyer, IBM/Project Athena.
29
#include <string.h> /*s*/
38
extern DWORD dwHesPwNamIndex;
39
extern DWORD dwHesPwUidIndex;
41
#define MAX_PW_BUFFER_LENGTH 64
44
_NextPWField(char *ptr);
46
struct passwd * GetPasswdStruct(struct passwd* pw, char* buf);
52
Given a UID this function will return the pwd information, eg username, uid,
53
gid, fullname, office location, phone number, home directory, and default shell
56
\param uid The user ID
57
\retval NULL if there was an error or a pointer to the passwd structure. The caller must
58
never attempt to modify this structure or to free any of its components.
59
Furthermore, only one copy of this structure is allocated per call per thread, so the application should copy any information it needs before
60
issuing another hes_getpwuid call
67
struct passwd* pw = NULL;
71
sprintf(nam, "%d", uid);
73
pp = hes_resolve(nam, "uid");
74
if (pp == NULL || *pp == NULL)
77
pw = (struct passwd*)(TlsGetValue(dwHesPwUidIndex));
79
LPVOID lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct passwd));
80
if (lpvData != NULL) {
81
TlsSetValue(dwHesPwUidIndex, lpvData);
82
pw = (struct passwd*)lpvData;
89
return GetPasswdStruct(pw, buf);
94
Given a username this function will return the pwd information, eg
95
username, uid, gid, fullname, office location, phone number, home
96
directory, and default shell
100
\param nam a pointer to the username
102
\retval NULL if there was an error or a pointer to the passwd structure. The caller must
103
never attempt to modify this structure or to free any of its components.
104
Furthermore, only one copy of this structure is allocated per call per thread, so the application should copy any information it needs before
105
issuing another hes_getpwnam call
110
hes_getpwnam(char *nam)
114
struct passwd* pw = NULL;
117
pp = hes_resolve(nam, "passwd");
118
if (pp == NULL || *pp == NULL)
121
pw = (struct passwd*)(TlsGetValue(dwHesPwNamIndex));
123
LPVOID lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct passwd));
124
if (lpvData != NULL) {
125
TlsSetValue(dwHesPwNamIndex, lpvData);
126
pw = (struct passwd*)lpvData;
133
return GetPasswdStruct(pw, buf);
137
struct passwd* GetPasswdStruct(struct passwd* pw, char* buf)
142
if (pw->pw_name == NULL)
143
pw->pw_name = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
144
if (pw->pw_passwd == NULL)
145
pw->pw_passwd = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
146
if (pw->pw_comment == NULL)
147
pw->pw_comment = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
148
if (pw->pw_gecos == NULL)
149
pw->pw_gecos = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
150
if (pw->pw_dir == NULL)
151
pw->pw_dir = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
152
if (pw->pw_shell == NULL)
153
pw->pw_shell = LocalAlloc(LPTR, MAX_PW_BUFFER_LENGTH);
154
/* choose only the first response (only 1 expected) */
158
strcpy(pw->pw_name, temp);
161
strcpy(pw->pw_passwd, temp);
162
pw->pw_uid = atoi(p);
164
pw->pw_gid = atoi(p);
166
strcpy(pw->pw_comment, "");
170
strcpy(pw->pw_gecos, temp);
173
strcpy(pw->pw_dir, temp);
175
while (*p && *p != '\n')
178
strcpy(pw->pw_shell, temp);
184
/* Move the pointer forward to the next colon-separated field in the
189
_NextPWField(char *ptr)
191
while (*ptr && *ptr != '\n' && *ptr != ':')