BSD 3 development
[unix-history] / usr / src / cmd / atrun.c
index e997fad..401862a 100644 (file)
@@ -20,9 +20,10 @@ char **argv;
 {
        int tt, day, year, uniq;
        struct direct dirent;
 {
        int tt, day, year, uniq;
        struct direct dirent;
-       char file[DIRSIZ+1];
        FILE *dirf;
 
        FILE *dirf;
 
+       setuid(0);
+       setgid(0);
        chdir(DIR);
        makenowtime();
        if ((dirf = fopen(".", "r")) == NULL) {
        chdir(DIR);
        makenowtime();
        if ((dirf = fopen(".", "r")) == NULL) {
@@ -32,9 +33,7 @@ char **argv;
        while (fread((char *)&dirent, sizeof(dirent), 1, dirf) == 1) {
                if (dirent.d_ino==0)
                        continue;
        while (fread((char *)&dirent, sizeof(dirent), 1, dirf) == 1) {
                if (dirent.d_ino==0)
                        continue;
-               strncpy(file, dirent.d_name, DIRSIZ);
-               file[DIRSIZ] = '\0';
-               if (sscanf(file, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
+               if (sscanf(dirent.d_name, "%2d.%3d.%4d.%2d", &year, &day, &tt, &uniq) != 4)
                        continue;
                if (nowyear < year)
                        continue;
                        continue;
                if (nowyear < year)
                        continue;
@@ -42,7 +41,7 @@ char **argv;
                        continue;
                if (nowyear==year && nowdate==day && nowtime < tt)
                        continue;
                        continue;
                if (nowyear==year && nowdate==day && nowtime < tt)
                        continue;
-               run(file);
+               run(dirent.d_name);
        }
        fclose(dirf);
        updatetime(nowtime);
        }
        fclose(dirf);
        updatetime(nowtime);
@@ -81,6 +80,7 @@ char *file;
        register pid, i;
        char sbuf[64];
 
        register pid, i;
        char sbuf[64];
 
+       /* printf("running %s\n", file); */
        if (fork()!=0)
                return;
        for (i=0; i<15; i++)
        if (fork()!=0)
                return;
        for (i=0; i<15; i++)
@@ -91,8 +91,6 @@ char *file;
        chdir(PDIR);
        if (stat(file, &stbuf) == -1)
                exit(1);
        chdir(PDIR);
        if (stat(file, &stbuf) == -1)
                exit(1);
-       setgid(stbuf.st_gid);
-       setuid(stbuf.st_uid);
        if (pid = fork()) {
                if (pid == -1)
                        exit(1);
        if (pid = fork()) {
                if (pid == -1)
                        exit(1);
@@ -100,6 +98,8 @@ char *file;
                unlink(file);
                exit(0);
        }
                unlink(file);
                exit(0);
        }
+       setgid(stbuf.st_gid);
+       setuid(stbuf.st_uid);
        nice(3);
        execl("/bin/sh", "sh", file, 0);
        execl("/usr/bin/sh", "sh", file, 0);
        nice(3);
        execl("/bin/sh", "sh", file, 0);
        execl("/usr/bin/sh", "sh", file, 0);