int xp_getpwent(Xpnode *nd, char *adminkey, char ***pwent) { char *buf = NULL, **toks; int n, bufsize = 8192; Xkey *akey = NULL; Spuser *auser = NULL; Spcfsys *fs = NULL; Spcfid *fid = NULL; if (adminkey) { akey = xauth_privkey_create(adminkey); if (!akey) goto error; } if (xp_defaultuser(&auser, &akey) < 0) goto error; fs = xp_node_mount(nd, auser, akey); if (!fs) { fs = xp_node_mount(nd, NULL, akey); if (!fs) goto error; } fid = spc_open(fs, "pwent", Oread); if (!fid) goto error; buf = sp_malloc(sizeof(*buf) * bufsize); if (!buf) goto error; n = spc_read(fid, (u8 *) buf, bufsize-1, 0); if (n < 0) goto error; buf[bufsize] = '\0'; spc_close(fid); spc_umount(fs); n = tokenize(buf, &toks); if (n < 0) goto error; free(buf); xauth_destroy(akey); *pwent = toks; return n; error: if (fid) spc_close(fid); if (fs) spc_umount(fs); if (buf) free(buf); if (akey) xauth_destroy(akey); return -1; }
int main(int argc, char **argv) { int c; char *addr; char *uname, *path; Spuser *user; Spcfsys *fs; Spcfid *fid; user = sp_uid2user(geteuid()); if (!user) { fprintf(stderr, "cannot retrieve user %d\n", geteuid()); exit(1); } uname = user->uname; while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { case 'd': spc_chatty = 1; break; case 'u': uname = optarg; break; default: usage(); } } if (argc - optind < 2) usage(); addr = argv[optind]; path = argv[optind+1]; fs = spc_netmount(addr, uname, 564); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); exit(1); } ispcfd = spcfd_add(fid, in_notify, fid); spcfd_start_loop(); spc_close(fid); spc_umount(fs); exit(0); }
int main(int argc, char **argv) { int ecode; int c; char *addr; char *ename, *path; Spuser *user; Spcfsys *fs; user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { case 'd': spc_chatty = 1; break; case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; default: usage(); } } if (!user) { fprintf(stderr, "cannot retrieve user %d\n", geteuid()); exit(1); } if (argc - optind < 2) usage(); addr = argv[optind]; path = argv[optind+1]; fs = spc_netmount(addr, user, 564, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); exit(1); } if (readnb(buf1) < 0) goto error; if (readnb(buf2) < 0) goto error; if (readnb(buf3) < 0) goto error; if (readnb(buf4) < 0) goto error; while (done < 4) sp_poll_once(); spc_close(fid); spc_umount(fs); return 0; error: sp_rerror(&ename, &ecode); fprintf(stderr, "Error: %s\n", ename); return -1; }
int main(int argc, char **argv) { int i, n, off; int c; char *addr; char *path; Spuser *user; Spcfsys *fs; Spcfid *fid; char buf[512]; user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { case 'd': spc_chatty = 1; break; case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; default: usage(); } } if (!user) { fprintf(stderr, "cannot retrieve user %d\n", geteuid()); exit(1); } if (argc - optind < 2) usage(); addr = argv[optind]; path = argv[optind+1]; fs = spc_netmount(addr, user, 564, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); exit(1); } off = 0; while ((n = spc_read(fid, (u8*) buf, sizeof(buf), off)) > 0) { i = write(1, buf, n); if (i != n) { fprintf(stderr, "error writing\n"); exit(1); } off += n; } spc_close(fid); spc_umount(fs); exit(0); }