Diff for /embedtools/src/wdog.c between versions 1.1.2.2 and 1.1.2.3

version 1.1.2.2, 2010/10/18 08:32:39 version 1.1.2.3, 2010/10/18 08:47:31
Line 22  Usage() Line 22  Usage()
                 "  Syntax: wdog [options] [exec_file]\n\n"                  "  Syntax: wdog [options] [exec_file]\n\n"
                 "\t-v\t\tVerbose ...\n"                  "\t-v\t\tVerbose ...\n"
                 "\t-c <dir>\tBefore execute chroot to dir [default=/]\n"                  "\t-c <dir>\tBefore execute chroot to dir [default=/]\n"
                   "\t-u <user>\tBefore execute change user\n"
                 "\n", compiled, compiledby, compilehost);                  "\n", compiled, compiledby, compilehost);
 }  }
   
Line 45  int Line 46  int
 main(int argc, char **argv)  main(int argc, char **argv)
 {  {
         char ch, szRun[MAXPATHLEN], szChroot[MAXPATHLEN] = "/";          char ch, szRun[MAXPATHLEN], szChroot[MAXPATHLEN] = "/";
        int status, ret = 1;        int status = 0, ret = 1;
         struct sigaction sa;          struct sigaction sa;
           struct passwd *pass = NULL;
           uid_t uid = getuid();
   
        while ((ch = getopt(argc, argv, "vhc:")) != -1)        while ((ch = getopt(argc, argv, "vhc:u:")) != -1)
                 switch (ch) {                  switch (ch) {
                         case 'v':                          case 'v':
                                 Verbose++;                                  Verbose++;
                                 break;                                  break;
                         case 'c':                          case 'c':
                                   if (uid) {
                                           printf("Error:: can`t chroot, please run as root!\n");
                                           goto end;
                                   }
                                 if (access(optarg, R_OK)) {                                  if (access(optarg, R_OK)) {
                                         printf("Error:: can`t chroot to %s #%d - %s\n", optarg,                                           printf("Error:: can`t chroot to %s #%d - %s\n", optarg, 
                                                         errno, strerror(errno));                                                          errno, strerror(errno));
                                         goto end;                                          goto end;
                                 } else                                  } else
                                         strlcpy(szChroot, optarg, MAXPATHLEN);                                          strlcpy(szChroot, optarg, MAXPATHLEN);
                                   status |= 1;
                                 break;                                  break;
                           case 'u':
                                   if (uid) {
                                           printf("Error:: can`t setuid, please run as root!\n");
                                           goto end;
                                   }
                                   pass = getpwnam(optarg);
                                   if (!pass) {
                                           printf("Error:: can`t find user %s\n", optarg);
                                           goto end;
                                   } else
                                           uid = pass->pw_uid;
                                   endpwent();
                                   status |= 2;
                                   break;
                         case 'h':                          case 'h':
                         default:                          default:
                                 Usage();                                  Usage();
Line 89  main(int argc, char **argv) Line 111  main(int argc, char **argv)
         sigaction(SIGSTOP, &sa, NULL);          sigaction(SIGSTOP, &sa, NULL);
         VERB(5) printf("Info:: Catched signals ...\n");          VERB(5) printf("Info:: Catched signals ...\n");
   
        if ((ret = chroot(szChroot)) == -1) {        if (status & 1 && (ret = chroot(szChroot)) == -1) {
                 printf("Error:: error in chroot to %s #%d - %s\n", szChroot, errno, strerror(errno));                  printf("Error:: error in chroot to %s #%d - %s\n", szChroot, errno, strerror(errno));
                 ret = 3;                  ret = 3;
                 goto end;                  goto end;
         } else          } else
                 VERB(1) printf("Info:: chrooted to %s\n", szChroot);                  VERB(1) printf("Info:: chrooted to %s\n", szChroot);
   
        while (!Kill)        if (status & 2 && setuid(uid) == -1) {
                 printf("Error:: error in setuid to %u #%d - %s\n", uid, errno, strerror(errno));
                 ret = 4;
                 goto end;
         } else
                 VERB(1) printf("Info:: setuid to %u\n", uid);
 
 //        while (!Kill)
                 switch ((ret = fork())) {                  switch ((ret = fork())) {
                         case -1:                          case -1:
                                 printf("Error:: error in fork #%d - %s\n", errno, strerror(errno));                                  printf("Error:: error in fork #%d - %s\n", errno, strerror(errno));
                                ret = 4;                                ret = 5;
                                 goto end;                                  goto end;
                         case 0:                          case 0:
                                 break;                                  break;

Removed from v.1.1.2.2  
changed lines
  Added in v.1.1.2.3


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>