File: become_a_nobody.c

package info (click to toggle)
ganglia-monitor-core 2.5.7-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,300 kB
  • ctags: 3,900
  • sloc: ansic: 27,889; sh: 8,492; makefile: 148
file content (32 lines) | stat: -rw-r--r-- 685 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* $Id: become_a_nobody.c,v 1.2 2002/06/20 03:23:24 massie Exp $ */
#include <ganglia/become_a_nobody.h>
#include <ganglia/error.h>
#include <stdio.h>

void
become_a_nobody( const char *username )
{
   int rval;
   struct passwd *pw;
 
   pw = getpwnam(username);
   if ( pw == NULL )
     {
       err_quit("user '%s' does not exist\n\n", username);
     }

   rval = getuid();
   if ( rval != pw->pw_uid )  
     {
       if ( rval != 0 )
         {
           err_quit("Must be root to setuid to \"%s\"\n\n", username);
         }

       rval = setuid(pw->pw_uid); 
       if ( rval < 0 )
         {
           err_quit("exiting. setuid '%s' error", username);
         }
     }
}