295
295
numRead = read(cmdFd, cmdLineTemp, sizeof cmdLineTemp - sizeof(char));
301
for (replaceLoop = 0 ; replaceLoop < (numRead - 1) ; replaceLoop++) {
302
if ('\0' == cmdLineTemp[replaceLoop]) {
303
cmdLineTemp[replaceLoop] = ' ';
299
for (replaceLoop = 0 ; replaceLoop < (numRead - 1) ; replaceLoop++) {
300
if ('\0' == cmdLineTemp[replaceLoop]) {
301
cmdLineTemp[replaceLoop] = ' ';
306
* Some procs don't have a command line text, so read a name from
307
* the 'status' file (should be the first line). If unable to get a name,
308
* the process is still real, so it should be included in the list, just
314
if (snprintf(cmdFilePath,
317
ent->d_name) != -1) {
318
cmdFd = open(cmdFilePath, O_RDONLY);
321
numRead = read(cmdFd, cmdLineTemp, sizeof(cmdLineTemp) - sizeof(char));
325
cmdLineTemp[0] = '\0';
327
cmdLineTemp[numRead] = '\0';
332
* Extract the part with just the name, by reading until the first
333
* space, then reading the next non-space word after that, and
334
* ignoring everything else. The format looks like this:
335
* "^Name:[ \t]*(.*)$"
339
const char* nameStart = NULL;
340
char* copyItr = NULL;
342
/* Skip non-whitespace. */
343
for (nameStart = cmdLineTemp; *nameStart &&
345
*nameStart != '\t' &&
346
*nameStart != '\n'; ++nameStart);
347
/* Skip whitespace. */
349
(*nameStart == ' ' ||
350
*nameStart == '\t' ||
351
*nameStart == '\n'); ++nameStart);
352
/* Copy the name to the start of the string and null term it. */
353
for (copyItr = cmdLineTemp; *nameStart && *nameStart != '\n';) {
354
*(copyItr++) = *(nameStart++);
313
366
* bytes from /proc/#/cmdline -- we left just enough space to add
314
367
* NUL termination at the end.
316
cmdLineTemp[numRead] = '\0';
370
cmdLineTemp[0] = '\0';
372
cmdLineTemp[numRead] = '\0';
319
376
* Get the inode information for this process. This gives us
1336
ret = setresuid(ppw->pw_gid, ppw->pw_gid, 0);
1393
ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
1338
1395
Warning("Failed to setresuid() for user %s\n", user);
1391
1448
// first change back user
1392
ret = setresuid(ppw->pw_gid, ppw->pw_gid, 0);
1449
ret = setresuid(ppw->pw_uid, ppw->pw_uid, 0);
1394
1451
Warning("Failed to setresuid() for root\n");