int main (int argc, char *argv[]) { Npcfsys *fs; Npcfid *afid, *root; char *aname; int fd = 0; /* stdin */ uid_t uid = geteuid (); diod_log_init (argv[0]); if (argc != 2) usage (); aname = argv[1]; if (!(fs = npc_start (fd, 8192+24, 0))) errn_exit (np_rerror (), "npc_start"); if (!(afid = npc_auth (fs, aname, uid, diod_auth)) && np_rerror () != 0) errn_exit (np_rerror (), "npc_auth"); if (!(root = npc_attach (fs, afid, aname, uid))) errn_exit (np_rerror (), "npc_attach"); if (afid && npc_clunk (afid) < 0) errn_exit (np_rerror (), "npc_clunk afid"); _flush_series (fs, root); if (npc_clunk (root) < 0) errn_exit (np_rerror (), "npc_clunk root"); npc_finish (fs); diod_log_fini (); exit (0); }
int main (int argc, char *argv[]) { Npcfsys *fs; Npcfid *afid, *root, *fid; char *aname; const int fd = 0; /* stdin */ uid_t uid; gid_t gid, ngid; diod_log_init (argv[0]); if (argc != 2) usage (); aname = argv[1]; if (geteuid () != 0) /* the server actually must be running as root */ msg_exit ("must run as root"); pick_user (&uid, &gid, &ngid); if (!(fs = npc_start (fd, 8192+24, 0))) errn_exit (np_rerror (), "npc_start"); if (!(afid = npc_auth (fs, aname, uid, diod_auth)) && np_rerror () != 0) errn_exit (np_rerror (), "npc_auth"); if (!(root = npc_attach (fs, afid, aname, uid))) errn_exit (np_rerror (), "npc_attach"); if (afid && npc_clunk (afid) < 0) errn_exit (np_rerror (), "npc_clunk afid"); /* should succeed */ if (!(fid = npc_create_bypath (root, "foo", 0644, O_RDONLY, gid))) errn_exit (np_rerror (), "npc_create_bypath as %d:%d with gid %d", uid, gid, gid); if (npc_clunk (fid) < 0) errn_exit (np_rerror (), "npc_clunk"); msg ("create foo with good gid succeeded"); /* should fail */ if ((fid = npc_create_bypath (root, "foo2", 0644, O_RDONLY, ngid))) msg_exit ("npc_create_bypath as %d:%d with gid %d succeeded: FAIL", uid, gid, ngid); msg ("create foo2 with bad gid failed"); if (npc_clunk (root) < 0) errn_exit (np_rerror (), "npc_clunk root"); npc_finish (fs); diod_log_fini (); exit (0); }
int main (int argc, char *argv[]) { Npsrv *srv; Npconn *conn; Nptrans *trans; int flags = SRV_FLAGS_DEBUG_9PTRACE | SRV_FLAGS_DEBUG_USER; diod_log_init (argv[0]); diod_conf_init (); if (!(srv = np_srv_create (16, flags))) errn_exit (np_rerror (), "out of memory"); srv->logmsg = diod_log_msg; srv->attach = myattach; srv->clunk = myclunk; /* create one connection */ if (!(trans = ttrans_create ())) err_exit ("ttrans_create"); if (!(conn = np_conn_create (srv, trans, "loopback"))) msg_exit ("np_conn_create failure"); _send_tversion (trans); _send_tauth (trans); _send_tattach (trans, 0, 0); _send_tattach (trans, 0, 1); _send_tattach (trans, 1, 2); _send_tattach (trans, 1, 3); _send_tattach (trans, 0, 4); _send_tclunk (trans, 4); _send_tclunk (trans, 3); _send_tclunk (trans, 2); _send_tclunk (trans, 1); _send_tclunk (trans, 0); ttrans_rpc (trans, NULL, NULL); /* signifies EOF to reader */ /* wait for exactly one connect/disconnect */ np_srv_wait_conncount (srv, 1); sleep(1); /* racy here - conn reader needs time to process EOF */ np_srv_destroy (srv); diod_conf_fini (); diod_log_fini (); exit (0); }
int main(int argc, char **argv) { int c; char *copt = NULL; srvmode_t mode = SRV_NORMAL; int rfdno = -1, wfdno = -1; diod_log_init (argv[0]); diod_conf_init (); /* config file overrides defaults */ opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'c': /* --config-file PATH */ copt = optarg; break; default: break; } } diod_conf_init_config_file (copt); /* Command line overrides config file. */ optind = 0; opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'f': /* --foreground */ diod_conf_set_foreground (1); break; case 'r': /* --rfdno */ mode = SRV_FILEDES; rfdno = strtoul (optarg, NULL, 10); break; case 'w': /* --wfdno */ mode = SRV_FILEDES; wfdno = strtoul (optarg, NULL, 10); break; case 'd': /* --debug MASK */ diod_conf_set_debuglevel (strtoul (optarg, NULL, 0)); break; case 'l': /* --listen HOST:PORT or /path/to/socket */ if (!diod_conf_opt_listen ()) diod_conf_clr_listen (); if (!strchr (optarg, ':') && optarg[0] != '/') usage (); diod_conf_add_listen (optarg); break; case 't': /* --nwthreads INT */ diod_conf_set_nwthreads (strtoul (optarg, NULL, 10)); break; case 'c': /* --config-file PATH */ break; case 'e': /* --export PATH */ if (!diod_conf_opt_exports ()) diod_conf_clr_exports (); diod_conf_add_exports (optarg); break; case 'E': /* --export-all */ diod_conf_set_exportall (1); break; case 'o': /* --export-ops opt,[opt,...] */ diod_conf_set_exportopts (optarg); break; case 'n': /* --no-auth */ diod_conf_set_auth_required (0); break; case 'p': /* --statfs-passthru */ diod_conf_set_statfs_passthru (0); break; case 'N': /* --no-userdb */ diod_conf_set_userdb (0); break; case 'S': /* --allsquash */ diod_conf_set_allsquash (1); break; case 'U': /* --squashuser USER */ diod_conf_set_squashuser (optarg); break; case 'u': { /* --runas-uid UID */ uid_t uid; char *end; errno = 0; uid = strtoul (optarg, &end, 10); if (errno != 0) err_exit ("error parsing --runas-uid argument"); if (*end != '\0') msg_exit ("error parsing --runas-uid argument"); diod_conf_set_runasuid (uid); break; } case 's': /* --socktest */ mode = SRV_SOCKTEST; break; case 'L': /* --logdest DEST */ diod_conf_set_logdest (optarg); diod_log_set_dest (optarg); break; default: usage(); } } if (optind < argc) usage(); if (diod_conf_opt_runasuid () && diod_conf_get_allsquash ()) msg_exit ("--runas-uid and allsquash cannot be used together"); if (mode == SRV_FILEDES && (rfdno == -1 || wfdno == -1)) msg_exit ("--rfdno,wfdno must be used together"); diod_conf_validate_exports (); if (geteuid () == 0) _setrlimit (); _service_run (mode, rfdno, wfdno); diod_conf_fini (); diod_log_fini (); exit (0); }
int main (int argc, char *argv[]) { char *aname = "ctl"; char *server = NULL; int msize = 65536; uid_t uid = geteuid (); int topt = 0; int Sopt = 0; int flags = 0; int fd, c; Npcfsys *fs = NULL; Npcfid *afid = NULL, *root = NULL; char *buf = NULL; struct timeval tv; struct timezone tz; diod_log_init (argv[0]); opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 's': /* --server HOST[:PORT] or /path/to/socket */ server = optarg; break; case 'm': /* --msize SIZE */ msize = strtoul (optarg, NULL, 10); break; case 'u': /* --uid UID */ uid = strtoul (optarg, NULL, 10); break; case 't': /* --timeout SECS */ topt = strtoul (optarg, NULL, 10); break; case 'S': /* --set-time */ Sopt = 1; break; default: usage (); } } if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) err_exit ("signal"); if (signal (SIGALRM, sigalarm) == SIG_ERR) err_exit ("signal"); if (topt > 0) alarm (topt); if ((fd = diod_sock_connect (server, flags)) < 0) exit (1); if (!(fs = npc_start (fd, fd, msize, 0))) { errn (np_rerror (), "error negotiating protocol with server"); goto done; } if (!(afid = npc_auth (fs, aname, uid, diod_auth)) && np_rerror () != 0) { errn (np_rerror (), "error authenticating to server"); goto done; } if (!(root = npc_attach (fs, afid, aname, uid))) { errn (np_rerror (), "error attaching to aname='%s'", aname); goto done; } buf = npc_aget (root, "date"); if (!buf) { errn (np_rerror (), "error reading date"); goto done; } if (sscanf (buf, "%lu.%lu %d.%d", &tv.tv_sec, &tv.tv_usec, &tz.tz_minuteswest, &tz.tz_dsttime) != 4) { msg ("error scanning returned date: %s", buf); goto done; } if (Sopt) { if (settimeofday (&tv, &tz) < 0) err_exit ("settimeofday"); } else { time_t t = tv.tv_sec; printf ("%s", ctime (&t)); } done: if (buf) free (buf); if (root && npc_clunk (root) < 0) errn_exit (np_rerror (), "error clunking %s", aname); if (afid && npc_clunk (afid) < 0) errn_exit (np_rerror (), "error clunking afid"); if (fs) npc_finish (fs); close (fd); diod_log_fini (); exit (0); }
int main (int argc, char *argv[]) { char *aname = NULL; char *server = NULL; int msize = 65536; uid_t uid = geteuid (); int topt = 0; int lopt = 0; int fd, c; diod_log_init (argv[0]); opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'a': /* --aname NAME */ aname = optarg; break; case 's': /* --server HOST[:PORT] or /path/to/socket */ server = optarg; break; case 'm': /* --msize SIZE */ msize = strtoul (optarg, NULL, 10); break; case 'u': /* --uid UID */ uid = strtoul (optarg, NULL, 10); break; case 't': /* --timeout SECS */ topt = strtoul (optarg, NULL, 10); break; case 'l': /* --long */ lopt = 1; break; default: usage (); } } if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) err_exit ("signal"); if (signal (SIGALRM, sigalarm) == SIG_ERR) err_exit ("signal"); if (topt > 0) alarm (topt); if ((fd = diod_sock_connect (server, 0)) < 0) exit (1); if (!aname) aname = "ctl"; if (lsfiles (fd, uid, msize, aname, lopt, argv + optind, argc - optind) < 0) exit (1); close (fd); diod_log_fini (); exit (0); }
int main (int argc, char *argv[]) { char *host = NULL; char *port = "564"; int msize = 65536; int numthreads = 16; int runtime = 10; int i, c, err; time_t now = time (NULL); thd_t *t; uint64_t readbytes = 0, writebytes = 0, opcount = 0; load_t loadtype = LOAD_IO; diod_log_init (argv[0]); opterr = 0; while ((c = GETOPT (argc, argv, OPTIONS, longopts)) != -1) { switch (c) { case 'h': /* --hostname NAME */ host = optarg; break; case 'p': /* --port PORT */ port = optarg; break; case 'm': /* --msize SIZE */ msize = strtoul (optarg, NULL, 10); break; case 'n': /* --numthreads INT */ numthreads = strtoul (optarg, NULL, 10); break; case 'r': /* --runtime INT */ runtime = strtoul (optarg, NULL, 10); break; case 'g': /* --getattr */ loadtype = LOAD_GETATTR; break; default: usage (); } } if (signal (SIGPIPE, SIG_IGN) == SIG_ERR) err_exit ("signal"); if (!(t = malloc (sizeof (thd_t) * numthreads))) msg_exit ("out of memory"); for (i = 0; i < numthreads; i++) { t[i].host = host ? host : "localhost"; t[i].port = port; t[i].msize = msize; t[i].stoptime = now + runtime; t[i].fd = -1; t[i].fs = NULL; t[i].root = t[i].afid = t[i].infile = t[i].outfile = NULL; t[i].readbytes = t[i].writebytes = 0; t[i].loadtype = loadtype; if (!(t[i].buf = malloc (msize))) msg_exit ("out of memory"); if ((err = pthread_create (&t[i].t, NULL, loadgen, &t[i]))) errn_exit (err, "pthread_create"); } for (i = 0; i < numthreads; i++) { if ((err = pthread_join (t[i].t, NULL))) errn_exit (err, "pthread_join"); readbytes += t[i].readbytes; writebytes += t[i].writebytes; opcount += t[i].opcount; free (t[i].buf); } free (t); msg ("%"PRIu64" ops/s, %"PRIu64" rMB/s, %"PRIu64" wMB/s", opcount/runtime, readbytes/(1024*1024*runtime), writebytes/(1024*1024*runtime)); diod_log_fini (); exit (0); }