s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

s6-setuidgid.c (1010B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 
      5 #include <skalibs/strerr.h>
      6 #include <skalibs/exec.h>
      7 
      8 #include <s6/config.h>
      9 
     10 #define USAGE "s6-setuidgid username prog..."
     11 #define dieusage() strerr_dieusage(100, USAGE)
     12 
     13 int main (int argc, char const *const *argv)
     14 {
     15   char const *newargv[argc + 7] ;
     16   char *colon ;
     17   unsigned int m = 0 ;
     18   PROG = "s6-setuidgid" ;
     19   if (argc < 3) dieusage() ;
     20   argv++ ;
     21   if (!argv[0][0]) xexec(argv+1) ;
     22   colon = strchr(argv[0], ':') ;
     23   if (colon)
     24   {
     25     *colon = 0 ;
     26     newargv[m++] = S6_BINPREFIX "s6-applyuidgid" ;
     27     newargv[m++] = "-u" ;
     28     newargv[m++] = argv[0] ;
     29     newargv[m++] = "-g" ;
     30     newargv[m++] = colon + 1 ;
     31     newargv[m++] = "-G" ;
     32     newargv[m++] = "" ;
     33     argv++ ;
     34   }
     35   else
     36   {
     37     newargv[m++] = S6_BINPREFIX "s6-envuidgid" ;
     38     newargv[m++] = *argv++ ;
     39     newargv[m++] = S6_BINPREFIX "s6-applyuidgid" ;
     40     newargv[m++] = "-Uz" ;
     41   }
     42   newargv[m++] = "--" ;
     43   while (*argv) newargv[m++] = *argv++ ;
     44   newargv[m++] = 0 ;
     45   xexec(newargv) ;
     46 }