/* * qnx_vc_name_attach * * Note that currently the only valid values for nid are 0 and the * local nid. */ int qnx_vc_name_attach(nid_t nid, unsigned length, char *name) { if (nid != 0 && nid != getnid()) { errno = EHOSTUNREACH; return -1; } if (nid == 0) nid = getnid(); return qnx_name_locate(nid, name, length, NULL); }
int FileSysNeedsCR( int handle ) { struct _fd_entry fd_info; struct _psinfo ps_info; pid_t dos_pid; if( qnx_fd_query( 0, 0, handle, &fd_info ) != handle ) return( 0 ); dos_pid = qnx_name_locate( fd_info.nid, "qnx/dosfsys", 0, NULL ); if( dos_pid == -1 ) return( 0 ); if( qnx_psinfo( PROC_PID, dos_pid, &ps_info, 0, NULL ) != dos_pid ) return( 0 ); if( ps_info.flags & _PPF_VID ) { qnx_vc_detach( dos_pid ); dos_pid = ps_info.un.vproc.remote_pid; } return( dos_pid == fd_info.pid ); }
int main(int argc, char **argv) { char crontab[11 + LOGIN_NAME_MAX] = "crontabs/";/* partial pathname */ struct passwd *pwent; /* passwd struct */ int ch; /* option character */ FILE *tab, *tmp = NULL; /* output/input files */ int action = CREATE; #ifdef __WATCOMC__ nid_t nid = 0, qnx_strtonid(); /* server node */ pid_t server; int local = 0; argv0 = basename(argv[0]); pwent = getpwuid(getuid()); umask(066); while ((ch = getopt(argc, argv, "d:en:lLru:")) != EOF) { switch (ch) { case 'L': nid = getnid(); local = !local; break; case 'n': nid = qnx_strtonid(optarg); local = !local; break; #else void * server = NULL; int fd; /* shm_open file handle */ int euid, egid; argv0 = basename(argv[0]); pwent = getpwuid(getuid()); umask(066); while ((ch = getopt(argc, argv, "d:elru:")) != EOF) { switch (ch) { #endif case 'd': crondir = optarg; break; case 'e': action = EDIT; break; case 'l': if (action == REMOVE) fatal_message("conflict: -r/-l"); action = LIST; break; case 'r': if (action == LIST) { fatal_message("conflict: -r/-l"); } action = REMOVE; break; case 'u': /* get name and uid/gid for user */ if ((pwent = getpwnam(optarg)) == 0) { long id = strtol(optarg, (char **) &pwent, 10); if (*(char *) pwent != 0) { fatal_message("%s %s", "invalid user", optarg); } if ((pwent = getpwuid(id)) == 0) { fatal_message("%s %s", "unknown user", optarg); } } break; default: exit(EXIT_FAILURE); } } /* make sure we're allowed to do anything with this crontab */ if (getuid() != pwent->pw_uid && getuid() != 0) { fatal_message("access denied to crontab for %s", pwent->pw_name); } /* Locate the server */ #ifdef __WATCOMC__ switch (nid) { case 0: if ((server = qnx_name_locate(0, cronsrv + 1, 0, 0)) != -1) { nid = getnid(); local++; break; } /* fallthru */ default: server = qnx_name_locate(nid, cronsrv + local, 0, 0); } if (server == -1) fprintf(stderr, "warning: cron has not been started\n"); if (local) { crondir = malloc(strlen(optarg = crondir) + 8); sprintf(crondir, "%s.%ld", optarg, nid); } #else /* check if cron server is running. */ if ((fd = shm_open(SHM_CRON, O_RDONLY, S_IRWXU )) == -1) { fprintf(stderr, "warning: cron has not been started\n"); } else if(MAP_FAILED == (server = mmap(0, sizeof(pid_t), PROT_READ, MAP_SHARED, fd, 0))) { fatal_message("mmapp: %s", strerror(errno)); } if(server && kill(*(pid_t *)server, 0) == -1) { fatal_message("cron stopped abnormally"); } close(fd); #endif strcat(crontab, pwent->pw_name); if (optind == argc) { if (action == CREATE || action == EDIT) { char work[] = "/tmp/cronXXXX"; mktemp(work); if (action == CREATE) { /* read replacement crontab from stdin */ tmp = fopen(work, "w+"); while ((ch = getchar()) != EOF) fputc(ch, tmp); } else { char *editor = getenv("EDITOR"); int status; if (editor == NULL) editor = "vi"; if (chdir(crondir) == -1) fatal_message("%s: %s", crondir, strerror(errno)); if ((tab = fopen(crontab, "r")) == 0 && errno != ENOENT) { fatal_message("%s/%s: %s", crondir, pwent->pw_name, strerror(errno)); } egid = getegid(); euid = geteuid(); setegid(getgid()); seteuid(getuid()); tmp = fopen(work, "w+"); if (tab) { while ((ch = fgetc(tab)) != EOF) fputc(ch, tmp); fflush(tmp); fclose(tab); } if ((status = spawnlp(P_WAIT, editor, editor, work, 0))) { remove(work); fatal_message(status == -1 ? "unable to start %s" : "%s exited %d", editor, status); } setegid(egid); seteuid(euid); } remove(work); rewind(tmp); } } else if (optind == argc - 1 && action == CREATE) { /* copy file onto crontab */ if (access(argv[optind], R_OK) != 0 || (tmp = fopen(argv[optind], "r")) == 0) { fatal_message("%s: %s", argv[optind], strerror(errno)); } } else { fatal_message("too many arguments"); } if(chdir(crondir) != 0) fatal_message("crontab %s: %s", strerror(errno), crondir); if (not_authorized(pwent->pw_name) && pwent->pw_uid != 0) { fprintf(stderr, "warning: no permission for cron: %s\n", pwent->pw_name); } if (action == LIST) { if ((tab = fopen(crontab, "r")) == 0) { if(errno == ENOENT) fatal_message("no crontab for %s", pwent->pw_name); fatal_message("%s: %s", pwent->pw_name, strerror(errno)); } else { while ((ch = fgetc(tab)) != EOF) putchar(ch); fclose(tab); } } else { /* drop and store euid/egid, use uid/gid */ egid = getegid(); euid = geteuid(); setegid(getgid()); seteuid(getuid()); chmod(crontab, S_IRWXU); /* -rw---- */ if (action == REMOVE) { if (remove(crontab) == -1 && errno != ENOENT) { fatal_message("%s: %s", strerror(errno), crontab); } } else if (action == CREATE || action == EDIT) { if ((tab = fopen(crontab, "w")) == NULL) { fatal_message("%s: %s", strerror(errno), crontab); } while ((ch = fgetc(tmp)) != EOF) fputc(ch, tab); fflush(tab); /* Changing write permissions later! */ fchown(fileno(tab), pwent->pw_uid, pwent->pw_gid); fchmod(fileno(tab), S_IRUSR); /* -r----- */ fclose(tab); fclose(tmp); } /* restore euid/egid for kill */ setegid(egid); seteuid(euid); /* Notify server */ #ifdef __WATCOMC__ if (server != -1 && Send(server, pwent->pw_name, 0, strlen(pwent->pw_name) + 1, 0) < 0) { #else if(server && kill(*(pid_t *)server, SIGUSR1) == -1) { #endif fatal_message("inform cron about update: %s", strerror(errno)); } } return EXIT_SUCCESS; }