1 karl 1.61 //%2006////////////////////////////////////////////////////////////////////////
|
2 mike 1.13 //
|
3 karl 1.42 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
4 // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
|
6 karl 1.32 // IBM Corp.; EMC Corporation, The Open Group.
|
7 karl 1.42 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
8 // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
|
9 karl 1.45 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
10 // EMC Corporation; VERITAS Software Corporation; The Open Group.
|
11 karl 1.61 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
12 // EMC Corporation; Symantec Corporation; The Open Group.
|
13 mike 1.13 //
14 // Permission is hereby granted, free of charge, to any person obtaining a copy
|
15 mike 1.14 // of this software and associated documentation files (the "Software"), to
16 // deal in the Software without restriction, including without limitation the
17 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
18 mike 1.13 // sell copies of the Software, and to permit persons to whom the Software is
19 // furnished to do so, subject to the following conditions:
|
20 karl 1.61 //
|
21 mike 1.14 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
|
22 mike 1.13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
23 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
24 mike 1.14 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
25 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
27 mike 1.13 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30 //==============================================================================
31 //
32 //%/////////////////////////////////////////////////////////////////////////////
33
34 #include "System.h"
35
|
36 mike 1.64 #include "Network.h"
|
37 mike 1.65 #include "Mutex.h"
|
38 mike 1.21 #include <fcntl.h>
|
39 mike 1.13 #include <sys/types.h>
40 #include <time.h>
41 #include <sys/timeb.h>
42 #include <io.h>
|
43 tony 1.33 #include <conio.h>
|
44 mike 1.13 #include <direct.h>
45 #include <sys/types.h>
|
46 mday 1.19 #include <windows.h>
|
47 kumpf 1.18 #include <process.h>
|
48 kumpf 1.38 #include <lm.h>
|
49 mike 1.13
|
50 h.sterling 1.52 #define SECURITY_WIN32
51 #include <security.h>
|
52 h.sterling 1.50
|
53 kumpf 1.36 PEGASUS_NAMESPACE_BEGIN
54
|
55 se.gupta 1.41 #define PEGASUS_ACCESS_EXISTS 0
56 #define PEGASUS_ACCESS_WRITE 2
57 #define PEGASUS_ACCESS_READ 4
58 #define PEGASUS_ACCESS_READ_AND_WRITE 6
|
59 mike 1.13
|
60 tony 1.33 #define PW_BUFF_LEN 65
61
|
62 mike 1.13 void System::getCurrentTime(Uint32& seconds, Uint32& milliseconds)
63 {
64 FILETIME ft;
65 GetSystemTimeAsFileTime(&ft);
66 ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
67 largeInt.QuadPart -= 0x19db1ded53e8000;
68 seconds = long(largeInt.QuadPart / (10000 * 1000));
69 milliseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
|
70 karl 1.23 // This is a real hack. Added the following line after timevalue was
71 // corrected and this apparently wrong. ks 7 apri 2002
72 milliseconds = milliseconds / 1000;
|
73 mike 1.13 }
74
|
75 jim.wunderlich 1.60 void System::getCurrentTimeUsec(Uint32& seconds, Uint32& microseconds)
76 {
77 FILETIME ft;
78 GetSystemTimeAsFileTime(&ft);
79 ULARGE_INTEGER largeInt = { ft.dwLowDateTime, ft.dwHighDateTime };
80 largeInt.QuadPart -= 0x19db1ded53e8000;
81 seconds = long(largeInt.QuadPart / (10000 * 1000));
82 microseconds = long((largeInt.QuadPart % (10000 * 1000)) / 10);
83 }
84
|
85 mike 1.13 String System::getCurrentASCIITime()
86 {
87 char tmpbuf[128];
|
88 kumpf 1.28 _strdate( tmpbuf );
89 String date = tmpbuf;
|
90 mike 1.13 _strtime( tmpbuf );
|
91 kumpf 1.28 date.append("-");
92 date.append(tmpbuf);
93 return date;
|
94 mike 1.13 }
95
96 void System::sleep(Uint32 seconds)
97 {
98 Sleep(seconds * 1000);
99 }
100
101 Boolean System::exists(const char* path)
102 {
|
103 se.gupta 1.41 return _access(path, PEGASUS_ACCESS_EXISTS) == 0;
|
104 mike 1.13 }
105
106 Boolean System::canRead(const char* path)
107 {
|
108 se.gupta 1.41 return _access(path, PEGASUS_ACCESS_READ) == 0;
|
109 mike 1.13 }
110
111 Boolean System::canWrite(const char* path)
112 {
|
113 se.gupta 1.41 return _access(path, PEGASUS_ACCESS_WRITE) == 0;
|
114 mike 1.13 }
115
116 Boolean System::getCurrentDirectory(char* path, Uint32 size)
117 {
118 return GetCurrentDirectory(size, path) != 0;
119 }
120
121 Boolean System::isDirectory(const char* path)
122 {
123 struct stat st;
124
125 if (stat(path, &st) != 0)
|
126 david.dillard 1.49 return false;
|
127 mike 1.13
128 return (st.st_mode & _S_IFDIR) != 0;
129 }
130
131 Boolean System::changeDirectory(const char* path)
132 {
133 return chdir(path) == 0;
134 }
135
136 Boolean System::makeDirectory(const char* path)
137 {
138 return _mkdir(path) == 0;
139 }
140
141 Boolean System::getFileSize(const char* path, Uint32& size)
142 {
143 struct stat st;
144
145 if (stat(path, &st) != 0)
|
146 david.dillard 1.49 return false;
|
147 mike 1.13
148 size = st.st_size;
149 return true;
150 }
151
152 Boolean System::removeDirectory(const char* path)
153 {
|
154 david.dillard 1.49 return rmdir(path) == 0;
|
155 mike 1.13 }
156
157 Boolean System::removeFile(const char* path)
158 {
|
159 david.dillard 1.49 return unlink(path) == 0;
|
160 mike 1.13 }
161
162 Boolean System::renameFile(const char* oldPath, const char* newPath)
163 {
164 return rename(oldPath, newPath) == 0;
165 }
166
167 String System::getHostName()
168 {
|
169 kumpf 1.55 static char hostname[PEGASUS_MAXHOSTNAMELEN + 1];
|
170 mike 1.13
171 if (!*hostname)
|
172 kumpf 1.55 {
|
173 mike 1.13 gethostname(hostname, sizeof(hostname));
|
174 kumpf 1.55 }
175 hostname[sizeof(hostname)-1] = 0;
|
176 mike 1.13
177 return hostname;
|
178 kumpf 1.16 }
179
|
180 kumpf 1.22 String System::getFullyQualifiedHostName ()
181 {
|
182 kumpf 1.56 static char FQHostName[PEGASUS_MAXHOSTNAMELEN + 1];
|
183 a.arora 1.40
184 if (!*FQHostName)
185 {
186 String hostname = getHostName();
187 struct hostent* hostEnt;
188
189 hostEnt = gethostbyname((const char *)hostname.getCString());
190 if (hostEnt == NULL)
191 {
192 return String::EMPTY;
193 }
|
194 kumpf 1.56 strncpy(FQHostName, hostEnt->h_name, sizeof(FQHostName)-1);
|
195 a.arora 1.40 }
|
196 david.dillard 1.49
|
197 a.arora 1.40 return FQHostName;
|
198 kumpf 1.22 }
199
200 String System::getSystemCreationClassName ()
201 {
|
202 karl 1.39 return "CIM_ComputerSystem";
|
203 kumpf 1.22 }
204
|
205 kumpf 1.16 Uint32 System::lookupPort(
206 const char * serviceName,
207 Uint32 defaultPort)
208 {
209 Uint32 localPort;
210
211 struct servent *serv;
212
213 //
|
214 david.dillard 1.48 // Get the port number.
|
215 kumpf 1.16 //
|
216 david.dillard 1.49 if ( (serv = getservbyname(serviceName, TCP)) != NULL )
|
217 kumpf 1.16 {
|
218 david.dillard 1.48 localPort = ntohs(serv->s_port);
|
219 kumpf 1.16 }
220 else
221 {
222 localPort = defaultPort;
223 }
224
225 return localPort;
|
226 mike 1.13 }
227
|
228 mike 1.14 String System::getPassword(const char* prompt)
229 {
|
230 david.dillard 1.49 char password[PW_BUFF_LEN] = {0};
231 int num_chars = 0;
232 int ch;
|
233 tony 1.33
|
234 david.dillard 1.49 fputs(prompt, stderr);
|
235 tony 1.33
|
236 david.dillard 1.49 while ((ch = _getch()) != '\r' &&
237 num_chars < PW_BUFF_LEN)
|
238 tony 1.33 {
|
239 david.dillard 1.49 // EOF
240 if (ch == EOF)
|
241 tony 1.33 {
|
242 david.dillard 1.49 fputs("[EOF]\n", stderr);
243 return String::EMPTY;
|
244 tony 1.33 }
|
245 david.dillard 1.49 // Backspace or Delete
246 else if ((ch == '\b' || ch == 127) &&
247 num_chars > 0)
|
248 tony 1.33 {
|
249 david.dillard 1.49 password[--num_chars] = '\0';
250 fputs("\b \b", stderr);
|
251 tony 1.33 }
|
252 david.dillard 1.49 // CTRL+C
253 else if (ch == 3)
|
254 tony 1.33 {
|
255 david.dillard 1.49 // _getch() does not catch CTRL+C
256 fputs("^C\n", stderr);
257 exit(-1);
|
258 tony 1.33 }
|
259 david.dillard 1.49 // CTRL+Z
260 else if (ch == 26)
|
261 tony 1.33 {
|
262 david.dillard 1.49 fputs("^Z\n", stderr);
263 return String::EMPTY;
|
264 tony 1.33 }
|
265 david.dillard 1.49 // Esc
266 else if (ch == 27)
|
267 tony 1.33 {
|
268 david.dillard 1.49 fputc('\n', stderr);
269 fputs(prompt, stderr);
270 num_chars = 0;
271 }
272 // Function keys (0 or E0) are a guards for a Function key codes
273 else if (ch == 0 || ch == 0xE0)
274 {
275 ch = (ch << 4) | _getch();
276 // Handle DELETE, left arrow, keypad DEL, and keypad left arrow
277 if ((ch == 0xE53 || ch == 0xE4B || ch == 0x053 || ch == 0x04b) &&
278 num_chars > 0)
|
279 tony 1.33 {
|
280 david.dillard 1.49 password[--num_chars] = '\0';
281 fputs("\b \b", stderr);
|
282 tony 1.33 }
|
283 david.dillard 1.49 else
|
284 tony 1.33 {
|
285 david.dillard 1.49 fputc('\a', stderr);
|
286 tony 1.33 }
287 }
|
288 david.dillard 1.49 else if ((num_chars < sizeof(password) - 1) &&
289 !iscntrl(((unsigned char)(ch))))
|
290 tony 1.33 {
|
291 david.dillard 1.49 password[num_chars++] = ch;
292 fputc('*', stderr);
|
293 tony 1.33 }
|
294 david.dillard 1.49 else
|
295 tony 1.33 {
|
296 david.dillard 1.49 fputc('\a', stderr);
|
297 tony 1.33 }
298 }
|
299 mike 1.14
|
300 david.dillard 1.49 fputc('\n', stderr);
301 password[num_chars] = '\0';
|
302 tony 1.33
|
303 david.dillard 1.49 return String(password);
|
304 mike 1.14 }
305
|
306 kumpf 1.24 String System::getEffectiveUserName()
|
307 mike 1.14 {
|
308 h.sterling 1.52 #if (_MSC_VER >= 1300) || defined(PEGASUS_WINDOWS_SDK_HOME)
309
310 //Bug 3076 fix
|
311 h.sterling 1.57 wchar_t fullUserName[UNLEN+1];
|
312 h.sterling 1.59 DWORD userNameSize = sizeof(fullUserName)/sizeof(fullUserName[0]);
|
313 h.sterling 1.57 wchar_t computerName[MAX_COMPUTERNAME_LENGTH+1];
|
314 h.sterling 1.59 DWORD computerNameSize = sizeof(computerName)/sizeof(computerName[0]);
|
315 h.sterling 1.57 wchar_t userName[UNLEN+1];
316 wchar_t userDomain[UNLEN+1];
|
317 h.sterling 1.50 String userId;
318
|
319 h.sterling 1.57 if (!GetUserNameExW(NameSamCompatible, fullUserName, &userNameSize))
|
320 h.sterling 1.50 {
321 return String();
322 }
323
|
324 h.sterling 1.57 wchar_t* index = wcschr(fullUserName, '\\');
325 *index = 0;
326 wcscpy(userDomain, fullUserName);
327 wcscpy(userName, index + 1);
|
328 h.sterling 1.50
329 //The above function will return the system name as the domain if
330 //the user is not on a real domain. Strip this out so that the rest of
331 //our windows user functions work. What if the system name and the domain
332 //name are the same?
|
333 h.sterling 1.57 GetComputerNameW(computerName, &computerNameSize);
|
334 h.sterling 1.50
|
335 h.sterling 1.57 if (wcscmp(computerName, userDomain) != 0)
|
336 h.sterling 1.50 {
|
337 h.sterling 1.57 //userId.append(userDomain);
338 Uint32 n = wcslen(userDomain);
339 for(unsigned long i = 0; i < n; i++)
340 {
341 userId.append(Char16(userDomain[i]));
342 }
|
343 h.sterling 1.50 userId.append("\\");
|
344 h.sterling 1.57 //userId.append(userName);
345 n = wcslen(userName);
346 for(unsigned long i = 0; i < n; i++)
347 {
348 userId.append(Char16(userName[i]));
349 }
350
|
351 h.sterling 1.50 } else
352 {
|
353 h.sterling 1.57 //userId.append(userName);
354 Uint32 n = wcslen(userName);
355 for(unsigned long i = 0; i < n; i++)
356 {
357 userId.append(Char16(userName[i]));
358 }
359
|
360 h.sterling 1.50 }
361
362 return userId;
|
363 h.sterling 1.52
364 #else //original getEffectiveUserName function
365
|
366 david.dillard 1.49 int retcode = 0;
|
367 tony 1.33
|
368 david.dillard 1.49 // UNLEN (256) is the limit, not including null
|
369 h.sterling 1.57 wchar_t pUserName[256+1] = {0};
|
370 h.sterling 1.59 DWORD nSize = sizeof(pUserName)/sizeof(pUserName[0]);
|
371 mike 1.14
|
372 h.sterling 1.57 retcode = GetUserNameW(pUserName, &nSize);
|
373 david.dillard 1.49 if (retcode == 0)
|
374 tony 1.33 {
|
375 david.dillard 1.49 // zero is failure
376 return String();
|
377 tony 1.33 }
|
378 h.sterling 1.58 String userId;
|
379 h.sterling 1.57 Uint32 n = wcslen(pUserName);
380 for(unsigned long i = 0; i < n; i++)
381 {
382 userId.append(Char16(pUserName[i]));
383 }
384
|
385 david.dillard 1.49
|
386 h.sterling 1.57 return userId;
|
387 h.sterling 1.52 #endif
|
388 mike 1.14 }
389
390 String System::encryptPassword(const char* password, const char* salt)
391 {
|
392 david.dillard 1.49 BYTE pbBuffer[PW_BUFF_LEN] = {0};
393 DWORD dwByteCount;
394 char pcSalt[3] = {0};
395
396 strncpy(pcSalt, salt, 2);
397 dwByteCount = strlen(password);
398 memcpy(pbBuffer, password, dwByteCount);
399 for (DWORD i=0; (i<dwByteCount) || (i>=PW_BUFF_LEN); i++)
400 (i%2 == 0) ? pbBuffer[i] ^= pcSalt[1] : pbBuffer[i] ^= pcSalt[0];
401
402 return String(pcSalt) + String((char *)pbBuffer);
|
403 mike 1.14 }
404
|
405 a.dunfey 1.62 String processUserName;
406 Mutex processUserNameMut;
407
|
408 kumpf 1.26 Boolean System::isSystemUser(const char* userName)
|
409 mike 1.14 {
|
410 a.dunfey 1.62 if(processUserName.size() == 0)
411 {
412 // Lock and recheck the processUserName length in case two threads
413 // enter this block simultaneously
414 AutoMutex mut(processUserNameMut);
415 if(processUserName.size() == 0)
416 {
417 processUserName = getEffectiveUserName();
418 }
419 }
420 if(processUserName == userName)
421 {
422 return true;
423 }
424
|
425 h.sterling 1.46 Boolean isSystemUser = false;
426
427 char mUserName[UNLEN+1];
428 char mDomainName[UNLEN+1];
|
429 david.dillard 1.51 char tUserName[UNLEN+1];
|
430 h.sterling 1.46 wchar_t wUserName[UNLEN+1];
431 wchar_t wDomainName[UNLEN+1];
432 char* pbs;
433 bool usingDomain = false;
|
434 david.dillard 1.49
|
435 h.sterling 1.46 LPBYTE pComputerName=NULL;
436 DWORD dwLevel = 1;
437 LPUSER_INFO_1 pUserInfo = NULL;
438 NET_API_STATUS nStatus = NULL;
439
|
440 david.dillard 1.51 // Make a copy of the specified username, it cannot be used directly because it's
441 // declared as const and strchr() may modify the string.
442 strncpy(tUserName, userName, sizeof(tUserName) - 1);
|
443 david.dillard 1.54 tUserName[sizeof(tUserName)- 1] = '\0';
|
444 david.dillard 1.51
|
445 david.dillard 1.49 //separate the domain and user name if both are present.
|
446 david.dillard 1.51 if (NULL != (pbs = strchr(tUserName, '\\')))
|
447 h.sterling 1.46 {
448 *pbs = '\0';
|
449 david.dillard 1.51 strcpy(mDomainName, tUserName);
|
450 h.sterling 1.46 strcpy(mUserName, pbs+1);
451 usingDomain = true;
452
|
453 david.dillard 1.51 } else if ((NULL != (pbs = (strchr(tUserName, '@')))) ||
454 (NULL != (pbs = (strchr(tUserName, '.')))))
|
455 h.sterling 1.46 {
456 *pbs = '\0';
457 strcpy(mDomainName, pbs+1);
|
458 david.dillard 1.51 strcpy(mUserName, tUserName);
|
459 h.sterling 1.46 usingDomain = true;
|
460 david.dillard 1.49
|
461 h.sterling 1.46 } else
462 {
463 strcpy(mDomainName, ".");
|
464 david.dillard 1.51 strcpy(mUserName, tUserName);
|
465 h.sterling 1.46 }
466
467 //convert domain name to unicode
468 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))
469 {
470 return false;
471 }
472
473 //convert username to unicode
474 if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1))
475 {
476 return false;
477 }
|
478 david.dillard 1.49
|
479 h.sterling 1.46 if (usingDomain)
480 {
481 //get domain controller
482 DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);
|
483 david.dillard 1.49 if (rc == NERR_Success)
|
484 h.sterling 1.46 {
485 wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\"
|
486 david.dillard 1.49 }
|
487 h.sterling 1.46 /*
488 else
489 {
490 // failover
491 // ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005
492 // This needs to be more thoroughly tested when we uncomment it out.
|
493 david.dillard 1.49
|
494 h.sterling 1.46 PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;
495
496 //this function does not take wide strings
497 rc = DsGetDcName(NULL,
498 mDomainName,
499 NULL,
500 NULL,
501 DS_DIRECTORY_SERVICE_REQUIRED, //not sure what flags we want here
502 &DomainControllerInfo);
503
504 if (rc == ERROR_SUCCESS && DomainControllerInfo)
505 {
506 strcpy(mDomainName, DomainControllerInfo->DomainName);
507 NetApiBufferFree(DomainControllerInfo);
508
509 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))
510 {
511 return false;
512 }
513 }
514 }
515 h.sterling 1.46 */
516 }
517
518 //get user info
519 nStatus = NetUserGetInfo(wDomainName,
520 wUserName,
521 dwLevel,
522 (LPBYTE *)&pUserInfo);
523
524 if (nStatus == NERR_Success)
525 {
526 isSystemUser = true;
527 }
|
528 david.dillard 1.49
529 if (pComputerName != NULL)
|
530 h.sterling 1.46 {
531 NetApiBufferFree(pComputerName);
532 }
533
534 if (pUserInfo != NULL)
535 {
536 NetApiBufferFree(pUserInfo);
537 }
538
539 return isSystemUser;
|
540 mike 1.14 }
541
|
542 h.sterling 1.46
|
543 david.dillard 1.43 Boolean System::isPrivilegedUser(const String& userName)
|
544 mike 1.14 {
|
545 h.sterling 1.46 Boolean isPrivileged = false;
546
547 char mUserName[UNLEN+1];
548 char mDomainName[UNLEN+1];
549 wchar_t wUserName[UNLEN+1];
550 wchar_t wDomainName[UNLEN+1];
551 char* pbs;
552 char userStr[UNLEN+1];
553 bool usingDomain = false;
554
555 LPBYTE pComputerName=NULL;
556 DWORD dwLevel = 1;
557 LPUSER_INFO_1 pUserInfo = NULL;
558 NET_API_STATUS nStatus = NULL;
559
560 //get the username in the correct format
561 strcpy(userStr, (const char*)userName.getCString());
562
|
563 david.dillard 1.49 //separate the domain and user name if both are present.
|
564 h.sterling 1.46 if (NULL != (pbs = strchr(userStr, '\\')))
565 {
566 *pbs = '\0';
567 strcpy(mDomainName, userStr);
568 strcpy(mUserName, pbs+1);
569 usingDomain = true;
570
571 } else if ((NULL != (pbs = (strchr(userStr, '@')))) ||
572 (NULL != (pbs = (strchr(userStr, '.')))))
573 {
574 *pbs = '\0';
575 strcpy(mDomainName, pbs+1);
576 strcpy(mUserName, userStr);
577 usingDomain = true;
|
578 david.dillard 1.49
|
579 h.sterling 1.46 } else
580 {
581 strcpy(mDomainName, ".");
582 strcpy(mUserName, userStr);
583 }
584
585 //convert domain name to unicode
586 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))
587 {
588 return false;
589 }
590
591 //convert username to unicode
592 if (!MultiByteToWideChar(CP_ACP, 0, mUserName, -1, wUserName, strlen(mUserName)+1))
593 {
594 return false;
595 }
596
597 if (usingDomain)
598 {
599 //get domain controller
600 h.sterling 1.46 DWORD rc = NetGetDCName(NULL, wDomainName, &pComputerName);
|
601 david.dillard 1.49 if (rc == NERR_Success)
|
602 h.sterling 1.46 {
603 wcscpy(wDomainName, (LPWSTR) pComputerName); //this is automatically prefixed with "\\"
|
604 david.dillard 1.49 }
|
605 h.sterling 1.46 /*
606 else
607 {
608 // failover
609 // ATTN: This is commented out until there is resolution on Bugzilla 2236. -hns 2/2005
610 // This needs to be more thoroughly tested when we uncomment it out.
|
611 david.dillard 1.49
|
612 h.sterling 1.46 PDOMAIN_CONTROLLER_INFO DomainControllerInfo = NULL;
613
614 //this function does not take wide strings
615 rc = DsGetDcName(NULL,
616 mDomainName,
617 NULL,
618 NULL,
619 DS_DIRECTORY_SERVICE_REQUIRED, //not sure what flags we want here
620 &DomainControllerInfo);
621
622 if (rc == ERROR_SUCCESS && DomainControllerInfo)
623 {
624 strcpy(mDomainName, DomainControllerInfo->DomainName);
625 NetApiBufferFree(DomainControllerInfo);
626
627 if (!MultiByteToWideChar(CP_ACP, 0, mDomainName, -1, wDomainName, strlen(mDomainName)+1))
628 {
629 return false;
630 }
631 }
632 }
633 h.sterling 1.46 */
634 }
635
636 //get privileges
637 nStatus = NetUserGetInfo(wDomainName,
638 wUserName,
639 dwLevel,
640 (LPBYTE *)&pUserInfo);
641
|
642 david.dillard 1.49 if ((nStatus == NERR_Success) &&
|
643 h.sterling 1.46 (pUserInfo != NULL) &&
644 (pUserInfo->usri1_priv == USER_PRIV_ADMIN))
645 {
646 isPrivileged = true;
647 }
648
|
649 david.dillard 1.49 if (pComputerName != NULL)
|
650 h.sterling 1.46 {
651 NetApiBufferFree(pComputerName);
652 }
653
654 if (pUserInfo != NULL)
655 {
656 NetApiBufferFree(pUserInfo);
657 }
658
659 return isPrivileged;
|
660 mike 1.14 }
|
661 kumpf 1.20
662 String System::getPrivilegedUserName()
663 {
664 // ATTN-NB-03-20000304: Implement better way to get the privileged
665 // user on the system.
666
667 return (String("Administrator"));
668 }
|
669 kumpf 1.37
670 Boolean System::isGroupMember(const char* userName, const char* groupName)
671 {
|
672 david.dillard 1.49 Boolean retVal = false;
|
673 kumpf 1.38
|
674 david.dillard 1.49 LPLOCALGROUP_USERS_INFO_0 pBuf = NULL;
675 DWORD dwLevel = 0;
676 DWORD dwFlags = LG_INCLUDE_INDIRECT ;
677 DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
678 DWORD dwEntriesRead = 0;
679 DWORD dwTotalEntries = 0;
680 NET_API_STATUS nStatus;
681
682
683 //
684 // Call the NetUserGetLocalGroups function
685 // specifying information level 0.
686 //
687 // The LG_INCLUDE_INDIRECT flag specifies that the
688 // function should also return the names of the local
689 // groups in which the user is indirectly a member.
690 //
691 nStatus = NetUserGetLocalGroups(NULL,
|
692 kumpf 1.38 (LPCWSTR)userName,
693 dwLevel,
694 dwFlags,
695 (LPBYTE *) &pBuf,
696 dwPrefMaxLen,
697 &dwEntriesRead,
698 &dwTotalEntries);
699
|
700 david.dillard 1.49 //
701 // If the call succeeds,
702 //
703 if (nStatus == NERR_Success)
704 {
705 LPLOCALGROUP_USERS_INFO_0 pTmpBuf;
706 DWORD i;
707 DWORD dwTotalCount = 0;
708
709 if ((pTmpBuf = pBuf) != NULL)
710 {
|
711 kumpf 1.38 //
|
712 david.dillard 1.49 // Loop through the local groups that the user belongs
713 // and find the matching group name.
|
714 kumpf 1.38 //
|
715 david.dillard 1.49 for (i = 0; i < dwEntriesRead; i++)
|
716 kumpf 1.38 {
|
717 david.dillard 1.49 //
718 // Compare the user's group name to groupName.
719 //
720 if ( strcmp ((char *)pTmpBuf->lgrui0_name, groupName) == 0 )
721 {
722 // User is a member of the group.
723 retVal = true;
724 break;
725 }
726
727 pTmpBuf++;
728 dwTotalCount++;
|
729 kumpf 1.38 }
|
730 david.dillard 1.49 }
731 }
|
732 kumpf 1.38
|
733 david.dillard 1.49 //
734 // Free the allocated memory.
735 //
736 if (pBuf != NULL)
737 NetApiBufferFree(pBuf);
738
739 //
740 // If the given user and group are not found in the local group
741 // then try on the global groups.
742 //
743 if (!retVal)
744 {
745 LPGROUP_USERS_INFO_0 pBuf = NULL;
746 dwLevel = 0;
747 dwPrefMaxLen = MAX_PREFERRED_LENGTH;
748 dwEntriesRead = 0;
749 dwTotalEntries = 0;
750
751 //
752 // Call the NetUserGetGroups function, specifying level 0.
753 //
754 david.dillard 1.49 nStatus = NetUserGetGroups(NULL,
|
755 kumpf 1.38 (LPCWSTR)userName,
756 dwLevel,
757 (LPBYTE*)&pBuf,
758 dwPrefMaxLen,
759 &dwEntriesRead,
760 &dwTotalEntries);
|
761 david.dillard 1.49 //
762 // If the call succeeds,
763 //
764 if (nStatus == NERR_Success)
765 {
766 LPGROUP_USERS_INFO_0 pTmpBuf;
767 DWORD i;
768 DWORD dwTotalCount = 0;
769
770 if ((pTmpBuf = pBuf) != NULL)
771 {
|
772 kumpf 1.38 //
|
773 david.dillard 1.49 // Loop through the global groups to which the user belongs
774 // and find the matching group name.
|
775 kumpf 1.38 //
|
776 david.dillard 1.49 for (i = 0; i < dwEntriesRead; i++)
|
777 kumpf 1.38 {
|
778 david.dillard 1.49 //
779 // Compare the user's group name to groupName.
780 //
781 if ( strcmp ((char *)pTmpBuf->grui0_name, groupName) == 0 )
782 {
783 // User is a member of the group.
784 retVal = true;
785 break;
786 }
787
788 pTmpBuf++;
789 dwTotalCount++;
|
790 kumpf 1.38 }
|
791 david.dillard 1.49 }
792 }
|
793 kumpf 1.38
|
794 david.dillard 1.49 //
795 // Free the allocated buffer.
796 //
797 if (pBuf != NULL)
798 NetApiBufferFree(pBuf);
799 }
|
800 kumpf 1.38
|
801 david.dillard 1.49 return retVal;
|
802 kumpf 1.37 }
|
803 kumpf 1.44
|
804 kumpf 1.63 Boolean System::lookupUserId(
805 const char* userName,
806 PEGASUS_UID_T& uid,
807 PEGASUS_GID_T& gid)
808 {
809 // ATTN: Implement this method to look up the specified user
810 return false;
811 }
812
813 Boolean System::changeUserContext(
814 const PEGASUS_UID_T& uid,
815 const PEGASUS_GID_T& gid)
|
816 kumpf 1.44 {
817 // ATTN: Implement this method to change the process user context to the
818 // specified user
819 return false;
820 }
821
|
822 kumpf 1.15 Uint32 System::getPID()
823 {
|
824 kumpf 1.18 return _getpid();
|
825 mike 1.21 }
826
827 Boolean System::truncateFile(
|
828 david.dillard 1.49 const char* path,
|
829 mike 1.21 size_t newSize)
830 {
|
831 david.dillard 1.49
832 Boolean rv = false;
|
833 mike 1.21 int fd = open(path, O_RDWR);
|
834 david.dillard 1.49 if (fd != -1)
835 {
836 if (chsize(fd, newSize) == 0)
837 {
838 rv = true;
839 }
|
840 mike 1.21
|
841 david.dillard 1.49 close(fd);
842 }
|
843 mike 1.21
|
844 david.dillard 1.49 return rv;
|
845 kumpf 1.15 }
846
|
847 tony 1.27 // Is absolute path?
848 Boolean System::is_absolute_path(const char *path)
849 {
|
850 david.dillard 1.49 char full[_MAX_PATH];
851 char path_slash[_MAX_PATH];
852 char *p;
853
854 strncpy(path_slash, path, _MAX_PATH);
855 path_slash[_MAX_PATH-1] = '\0';
856
857 for(p = path_slash; p < path_slash + strlen(path_slash); p++)
858 if (*p == '/')
859 *p = '\\';
860
861 return (strcasecmp(_fullpath( full, path_slash, _MAX_PATH ), path_slash) == 0) ? true : false;
|
862 kumpf 1.34 }
863
864 // Changes file permissions on the given file.
865 Boolean System::changeFilePermissions(const char* path, mode_t mode)
866 {
867 // ATTN: File permissions are not currently defined in Windows
868 return true;
|
869 tony 1.27 }
|
870 david 1.29
|
871 kumpf 1.44 Boolean System::verifyFileOwnership(const char* path)
872 {
873 // ATTN: Implement this to check that the owner of the specified file is
874 // the same as the effective user for this process.
875 return true;
876 }
877
|
878 kumpf 1.53 void System::syslog(const String& ident, Uint32 severity, const char* message)
|
879 david 1.29 {
|
880 kumpf 1.53 // Not implemented
|
881 david 1.29 }
882
883 // System ID constants for Logger::put and Logger::trace
884 const String System::CIMSERVER = "cimserver"; // Server system ID
|
885 tony 1.27
|
886 marek 1.68 // check if a given IP address is defined on the local network interfaces
887 Boolean System::isIpOnNetworkInterface(Uint32 inIP)
888 {
889 SOCKET sock;
890 int interfaces = 0;
891 int errcode;
892
893 if ( SOCKET_ERROR != ( sock = WSASocket(AF_INET,
894 SOCK_RAW, 0, NULL, 0, 0) ) )
895 {
896 unsigned long *bytes_returned=0;
897 char *output_buf = (char *)calloc(1, 256);
898 int buf_size = 256;
899
900 if ( 0 == (errcode = WSAIoctl(sock,
901 SIO_ADDRESS_LIST_QUERY,
902 NULL,
903 0,
904 output_buf,
905 256,
906 bytes_returned,
907 marek 1.68 NULL,
908 NULL)) )
909 {
910 SOCKET_ADDRESS_LIST *addr_list;
911 SOCKET_ADDRESS *addr;
912 Uint32 ip;
913 struct sockaddr_in *sin;
914
915 addr_list = (SOCKET_ADDRESS_LIST *)output_buf;
916 addr = addr_list->Address;
917
918 sin = (struct sockaddr_in *)addr->lpSockaddr;
919
920 for( ; interfaces < addr_list->iAddressCount; interfaces++)
921 {
922 ip = sin->sin_addr.s_addr;
923 addr++;
924 sin = (struct sockaddr_in *)addr->lpSockaddr;
925 if (ip == inIP)
926 {
927 free(output_buf);
928 marek 1.68 closesocket(sock);
929 return(true);
930 }
931 }
932 } else {
933 free(output_buf);
934 return false;
935 }
936 free(output_buf);
937 closesocket(sock);
938 }
939 return false;
940 }
941
942
|
943 kumpf 1.67
944 ///////////////////////////////////////////////////////////////////////////////
945 // AutoFileLock class
946 ///////////////////////////////////////////////////////////////////////////////
947
948 AutoFileLock::AutoFileLock(const char* fileName)
949 {
950 // ATTN: Not implemented
951 }
952
953 AutoFileLock::~AutoFileLock()
954 {
955 // ATTN: Not implemented
956 }
957
|
958 mike 1.13 PEGASUS_NAMESPACE_END
|