/* connect to PH server and initialize options */ int server_init(PH **newph, char *server) { int i, debug, ph_open_flags = PH_OPEN_DONTID; char *fields = NULL; char buf[NPH_BUF_SIZE]; /* set flags */ if (strchr(server, '/') != NULL) ph_open_flags |= PH_OPEN_LOCAL; else if (geteuid() == 0) { get_option("usereservedport", &i); if (i) ph_open_flags |= PH_OPEN_PRIVPORT; } get_option("debug", &debug); /* open connection */ if (ph_open(newph, server, ph_open_flags, (debug ? send_debug : NULL), (debug ? recv_debug : NULL), NULL) == -1) { nph_printf(1, "ph_open(): %s\n", strerror(errno)); return -1; } nph_printf(1, "connected to PH server %s\n", server); /* send id */ snprintf(buf, sizeof(buf), "nph-%s", PACKAGE_VERSION); if (ph_id(*newph, buf) == -1) { nph_printf(1, "ph_id(): %s\n", strerror(errno)); return -1; } /* validate field list */ get_option("returnfields", &fields); if (fields != NULL && check_fields(*newph, fields)) { nph_printf(1, "unsetting invalid \"returnfields\" option\n"); set_option("returnfields", ""); } return 0; }
/* * This is /usr/sbin/mount: the generic command that in turn * execs the appropriate /usr/lib/fs/{fstype}/mount. * The -F flag and argument are NOT passed. * If the usr file system is not mounted a duplicate copy * can be found in /sbin and this version execs the * appropriate /etc/fs/{fstype}/mount * * If the -F fstype, special or directory are missing, * /etc/vfstab is searched to fill in the missing arguments. * * -V will print the built command on the stdout. * It isn't passed either. */ int main(int argc, char *argv[]) { char *special, /* argument of special/resource */ *mountp, /* argument of mount directory */ *fstype, /* wherein the fstype name is filled */ *newargv[ARGV_MAX], /* arg list for specific command */ *farg = NULL, *Farg = NULL; int ii, ret, cc, fscnt; struct stat64 stbuf; struct vfstab vget, vref; mode_t mode; FILE *fd; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); myname = strrchr(argv[0], '/'); if (myname) myname++; else myname = argv[0]; if (myname == 0) myname = "path unknown"; /* Process the args. */ while ((cc = getopt(argc, argv, "?acd:f:F:gmno:pqrvVO")) != -1) switch (cc) { case 'a': aflg++; break; case 'c': cflg++; break; #ifdef DEBUG case 'd': dflg = atoi(optarg); break; #endif case 'f': fflg++; farg = optarg; break; case 'F': Fflg++; Farg = optarg; break; case 'g': gflg++; break; case 'm': mflg++; break; /* do not update /etc/mnttab */ case 'o': oflg++; if ((specific_opts = strdup(optarg)) == NULL) nomem(); break; /* fstype dependent options */ case 'O': Oflg++; break; case 'p': pflg++; break; case 'q': qflg++; break; case 'r': rflg++; generic_opts = "ro"; break; case 'v': vflg++; break; case 'V': Vflg++; break; case '?': questflg++; break; } /* copy '--' to specific */ if (strcmp(argv[optind-1], "--") == 0) dashflg++; /* option checking */ /* more than two args not allowed if !aflg */ if (!aflg && (argc - optind > 2)) usage(); /* pv mututally exclusive */ if (pflg + vflg + aflg > 1) { fprintf(stderr, gettext ("%s: -a, -p, and -v are mutually exclusive\n"), myname); usage(); } /* * Can't have overlaying mounts on the same mount point during * a parallel mount. */ if (aflg && Oflg) { fprintf(stderr, gettext ("%s: -a and -O are mutually exclusive\n"), myname); usage(); } /* dfF mutually exclusive */ if (fflg + Fflg > 1) { fprintf(stderr, gettext ("%s: More than one FSType specified\n"), myname); usage(); } /* no arguments, only allow p,v,V or [F]? */ if (!aflg && optind == argc) { if (cflg || fflg || mflg || oflg || rflg || qflg) usage(); if (Fflg && !questflg) usage(); if (questflg) { if (Fflg) { newargv[2] = "-?"; newargv[3] = NULL; doexec(Farg, newargv); } usage(); } } if (questflg) usage(); /* one or two args, allow any but p,v */ if (optind != argc && (pflg || vflg)) { fprintf(stderr, gettext("%s: Cannot use -p and -v with arguments\n"), myname); usage(); } /* if only reporting mnttab, generic prints mnttab and exits */ if (!aflg && optind == argc) { if (Vflg) { printf("%s", myname); if (pflg) printf(" -p"); if (vflg) printf(" -v"); printf("\n"); exit(0); } print_mnttab(vflg, pflg); exit(0); } /* * Get filesystem type here. If "-F FStype" is specified, use * that fs type. Otherwise, determine the fs type from /etc/vfstab * if the entry exists. Otherwise, determine the local or remote * fs type from /etc/default/df or /etc/dfs/fstypes respectively. */ if (fflg) { if ((strcmp(farg, "S51K") != 0) && (strcmp(farg, "S52K") != 0)) { fstype = farg; } else fstype = "ufs"; } else /* if (Fflg) */ fstype = Farg; fscnt = argc - optind; if (aflg && (fscnt != 1)) exit(parmount(argv + optind, fscnt, fstype)); /* * Then don't bother with the parallel over head. Everything * from this point is simple/normal single execution. */ aflg = 0; /* get special and/or mount-point from arg(s) */ if (fscnt == 2) special = argv[optind++]; else special = NULL; if (optind < argc) mountp = argv[optind++]; else mountp = NULL; /* lookup only if we need to */ if (fstype == NULL || specific_opts == NULL || special == NULL || mountp == NULL) { if ((fd = fopen(vfstab, "r")) == NULL) { if (fstype == NULL || special == NULL || mountp == NULL) { fprintf(stderr, gettext( "%s: Cannot open %s\n"), myname, vfstab); exit(1); } else { /* * No vfstab, but we know what we want * to mount. */ goto out; } } vfsnull(&vref); vref.vfs_special = special; vref.vfs_mountp = mountp; vref.vfs_fstype = fstype; /* get a vfstab entry matching mountp or special */ while ((ret = getvfsany(fd, &vget, &vref)) > 0) vfserror(ret, vget.vfs_special); /* if no entry and there was only one argument */ /* then the argument could be the special */ /* and not mount point as we thought earlier */ if (ret == -1 && special == NULL) { rewind(fd); special = vref.vfs_special = mountp; mountp = vref.vfs_mountp = NULL; /* skip erroneous lines; they were reported above */ while ((ret = getvfsany(fd, &vget, &vref)) > 0) ; } fclose(fd); if (ret == 0) { if (fstype == NULL) fstype = vget.vfs_fstype; if (special == NULL) special = vget.vfs_special; if (mountp == NULL) mountp = vget.vfs_mountp; if (oflg == 0 && vget.vfs_mntopts) { oflg++; specific_opts = vget.vfs_mntopts; } } else if (special == NULL) { if (stat64(mountp, &stbuf) == -1) { fprintf(stderr, gettext("%s: cannot stat %s\n"), myname, mountp); exit(2); } if (((mode = (stbuf.st_mode & S_IFMT)) == S_IFBLK) || (mode == S_IFCHR)) { fprintf(stderr, gettext("%s: mount point cannot be determined\n"), myname); exit(1); } else { fprintf(stderr, gettext("%s: special cannot be determined\n"), myname); exit(1); } } else if (fstype == NULL) fstype = default_fstype(special); } out: if (realpath(mountp, realdir) == NULL) { (void) fprintf(stderr, "mount: "); perror(mountp); exit(1); } if ((mountp = strdup(realdir)) == NULL) nomem(); if (check_fields(fstype, mountp)) exit(1); /* create the new arg list, and end the list with a null pointer */ ii = 2; if (cflg) newargv[ii++] = "-c"; if (gflg) newargv[ii++] = "-g"; if (mflg) newargv[ii++] = "-m"; /* * The q option needs to go before the -o option as some * filesystems complain during first pass option parsing. */ if (qflg) newargv[ii++] = "-q"; if (oflg) { newargv[ii++] = "-o"; newargv[ii++] = specific_opts; } if (Oflg) newargv[ii++] = "-O"; if (rflg) newargv[ii++] = "-r"; if (dashflg) newargv[ii++] = "--"; newargv[ii++] = special; newargv[ii++] = mountp; newargv[ii] = NULL; doexec(fstype, newargv); return (0); }
/* * Read all vstab (fp) entries into memory if fstype == NULL. * If fstype is specified, than read all those that match it. * * Returns a linked list. */ vfsent_t * getvfsall(char *fstype, int takeall) { vfsent_t *vhead, *vtail; struct vfstab vget; FILE *fp; int cnt = 0, ret; if ((fp = fopen(vfstab, "r")) == NULL) { fprintf(stderr, gettext("%s: Cannot open %s\n"), myname, vfstab); exit(1); } vhead = vtail = NULL; while ((ret = getvfsent(fp, &vget)) != -1) { vfsent_t *vp; if (ret > 0) { vfserror(ret, vget.vfs_mountp); continue; } /* * If mount points were not specified, then we ignore * entries that aren't marked "yes". */ if (takeall && (vget.vfs_automnt == NULL || strcmp(vget.vfs_automnt, "yes"))) continue; if (fstype && vget.vfs_fstype && strcmp(fstype, vget.vfs_fstype)) continue; if (vget.vfs_mountp == NULL || (vget.vfs_fstype && (strcmp(vget.vfs_fstype, "swap") == 0))) continue; if (check_fields(vget.vfs_fstype, vget.vfs_mountp)) { exitcode = 1; continue; } vp = new_vfsent(&vget, cnt); /* create new vfs entry */ if (vhead == NULL) vhead = vp; else vtail->next = vp; vtail = vp; cnt++; } fclose(fp); if (vtail == NULL) { vfsarraysize = 0; vfslltail = NULL; return (NULL); } vtail->next = NULL; vfslltail = vtail; /* save it in the global variable */ vfsarraysize = cnt; return (vhead); }
/* * chfn - change a user's password file information * * This command controls the GECOS field information in the password * file entry. * * The valid options are * * -f full name * -r room number * -w work phone number * -h home phone number * -o other information (*) * * (*) requires root permission to execute. */ int main (int argc, char **argv) { const struct passwd *pw; /* password file entry */ char new_gecos[BUFSIZ]; /* buffer for new GECOS fields */ char *user; /* * Get the program name. The program name is used as a * prefix to most error messages. */ Prog = Basename (argv[0]); sanitize_env (); (void) setlocale (LC_ALL, ""); (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); process_root_flag ("-R", argc, argv); /* * This command behaves different for root and non-root * users. */ amroot = (getuid () == 0); OPENLOG ("chfn"); /* parse the command line options */ process_flags (argc, argv); /* * Get the name of the user to check. It is either the command line * name, or the name getlogin() returns. */ if (optind < argc) { user = argv[optind]; pw = xgetpwnam (user); if (NULL == pw) { fprintf (stderr, _("%s: user '%s' does not exist\n"), Prog, user); fail_exit (E_NOPERM); } } else { pw = get_my_pwent (); if (NULL == pw) { fprintf (stderr, _("%s: Cannot determine your user name.\n"), Prog); SYSLOG ((LOG_WARN, "Cannot determine the user name of the caller (UID %lu)", (unsigned long) getuid ())); fail_exit (E_NOPERM); } user = xstrdup (pw->pw_name); } #ifdef USE_NIS /* * Now we make sure this is a LOCAL password entry for this user ... */ if (__ispwNIS ()) { char *nis_domain; char *nis_master; fprintf (stderr, _("%s: cannot change user '%s' on NIS client.\n"), Prog, user); if (!yp_get_default_domain (&nis_domain) && !yp_master (nis_domain, "passwd.byname", &nis_master)) { fprintf (stderr, _ ("%s: '%s' is the NIS master for this client.\n"), Prog, nis_master); } fail_exit (E_NOPERM); } #endif /* Check that the caller is allowed to change the gecos of the * specified user */ check_perms (pw); /* If some fields were not set on the command line, load the value from * the old gecos fields. */ get_old_fields (pw->pw_gecos); /* * If none of the fields were changed from the command line, let the * user interactively change them. */ if (!fflg && !rflg && !wflg && !hflg && !oflg) { printf (_("Changing the user information for %s\n"), user); new_fields (); } /* * Check all of the fields for valid information */ check_fields (); /* * Build the new GECOS field by plastering all the pieces together, * if they will fit ... */ if ((strlen (fullnm) + strlen (roomno) + strlen (workph) + strlen (homeph) + strlen (slop)) > (unsigned int) 80) { fprintf (stderr, _("%s: fields too long\n"), Prog); fail_exit (E_NOPERM); } snprintf (new_gecos, sizeof new_gecos, "%s,%s,%s,%s%s%s", fullnm, roomno, workph, homeph, ('\0' != slop[0]) ? "," : "", slop); /* Rewrite the user's gecos in the passwd file */ update_gecos (user, new_gecos); SYSLOG ((LOG_INFO, "changed user '%s' information", user)); nscd_flush_cache ("passwd"); closelog (); exit (E_SUCCESS); }
void init_fields(){ for(int i=0;i<100;i++){ field.my_fields[i/10][i%10]=0; field.enemy_fields[i/10][i%10]=0; } #ifdef DEBUG for(int i=0;i<10;i++){ for(int j=0; j<10; j++) field.my_fields[i][j] = debug_fields[i][j]; } print_board(); #endif #ifndef DEBUG int x,y,begin_x,begin_y; char bufor[2]; print_board(); for(int i=1;i<5;i++){ for(int j=0;j<i;j++){ printf("Podaj poczatek statku nr:%d o dlugosci %d: ",j+1,5-i); do{ scanf("%s",bufor); if(parse_field(bufor,&x,&y)!=0){ if(check_field(y, x)!=0) break; } }while(1); begin_x=x; begin_y=y; printf("Podaj koniec statku nr:%d o dlugosci %d: ",j+1,5-i); if(5-i!=1){ do{ scanf("%s",bufor); if(parse_field(bufor,&x,&y)!=0){ if(check_field(y, x)!=0){ if(check_fields(begin_x,begin_y,x,y,5-i)!=0) break; } } }while(1); } place_vessel(begin_x,begin_y,x,y,5-i); print_board(); } } #endif request_t response; strcpy(response.name,client_name); response.lobby = GAME; response.action = PLAYER_READY; response.opponent_socket=opponent_socket; pthread_mutex_lock(&mutex); if(send(socket_fd, (void*) &response, sizeof(response), 0) == -1) error("send() redy"); pthread_mutex_unlock(&mutex); }