Example #1
0
File: 9write.c Project: nuxlli/npfs
int
main(int argc, char **argv)
{
	int i, n, off;
	int c, port, dotu;
	char *addr, *s;
	char *path;
	Npuser *user;
	Npcfsys *fs;
	Npcfid *fid;
	char buf[512];

	port = 564;
//	npc_chatty = 1;

#ifdef _WIN32
	init();
	user = np_default_users->uname2user(np_default_users, "nobody");
#else
	user = np_default_users->uid2user(np_default_users, geteuid());
	if (!user) {
		fprintf(stderr, "cannot retrieve user %d\n", geteuid());
		exit(1);
	}
#endif

	dotu = 1;
	while ((c = getopt(argc, argv, "dp:u:U")) != -1) {
		switch (c) {
		case 'd':
			npc_chatty = 1;
			break;

		case 'p':
			port = strtol(optarg, &s, 10);
			if (*s != '\0')
				usage();
			break;

		case 'u':
			user = np_default_users->uname2user(np_default_users, optarg);
			break;

		case 'U':
			dotu = 0;
			break;

		default:
			usage();
		}
	}

	

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	fs = npc_netmount(npc_netaddr(addr, port), dotu, user, port, NULL, NULL);

	fid = npc_open(fs, path, Owrite);
	if (!fid) {
		fid = npc_create(fs, path, 0666, Owrite);
		if (!fid) {
			fprintf(stderr, "error creating\n");
			exit(1);
		}
	}

	off = 0;
	while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) {
		i = npc_write(fid, (u8*) buf, n, off);
		if (i != n) {
			fprintf(stderr, "error writing\n");
			exit(1);
		}

		off += n;
	}
			
	npc_close(fid);
	npc_umount(fs);

	exit(0);
}
Example #2
0
int
main(int argc, char **argv)
{
	int sfd, i, n, off;
	int c, port;
	char *addr, *s;
	char *uname, *path;
	Npuser *user;
	Npcfsys *fs;
	Npcfid *fid;
	struct sockaddr_in saddr;
	struct hostent *hostinfo;
	char buf[512];

	port = 564;
//	npc_chatty = 1;

	user = np_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':
			npc_chatty = 1;
			break;

		case 'p':
			port = strtol(optarg, &s, 10);
			if (*s != '\0')
				usage();
			break;

		case 'u':
			uname = optarg;
			break;

		default:
			usage();
		}
	}

	

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	sfd = socket(PF_INET, SOCK_STREAM, 0);
	if (sfd < 0) {
		perror("socket");
		exit(1);
	}

	hostinfo = gethostbyname (addr);
	if (!hostinfo) {
		perror("gethostbyname");
		exit(1);
	}

	saddr.sin_family = AF_INET;
	saddr.sin_port = htons(port);
	saddr.sin_addr = *(struct in_addr *) hostinfo->h_addr;

	if (connect(sfd, (struct sockaddr *) &saddr, sizeof(saddr)) < 0) {
		perror("connect");
		exit(1);
	}

	fs = npc_mount(sfd, NULL, "lucho");

	fid = npc_open(fs, path, Oread);
	if (!fid) {
		fprintf(stderr, "cannot open\n");
		exit(1);
	}

	off = 0;
	while ((n = npc_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;
	}
			
	npc_close(fid);
	npc_umount(fs);

	exit(0);
}
Example #3
0
File: 9ls.c Project: nuxlli/npfs
int __cdecl
main(int argc, char **argv)
{
	struct npcauth auth;
	int i, n;
	int c, port, dotu;
	char *addr, *authsrv, *s;
	char *path, *passwd;
	Npuser *user;
	Npcfsys *fs;
	Npcfid *fid;
	Npwstat *stat;

	port = 564;
	dotu = 2;
	passwd = NULL;
	authsrv = NULL;
//	npc_chatty = 1;

#ifdef _WIN32
	init();
	user = np_default_users->uname2user(np_default_users, "nobody");
#else
	user = np_default_users->uid2user(np_default_users, geteuid());
	if (!user) {
		fprintf(stderr, "cannot retrieve user %d\n", geteuid());
		exit(1);
	}
#endif
	while ((c = getopt(argc, argv, "a:dp:P:u:U")) != -1) {
		switch (c) {
		case 'a':
			authsrv = optarg;
			break;
			
		case 'd':
			npc_chatty = 1;
			break;

		case 'p':
			port = strtol(optarg, &s, 10);
			if (*s != '\0')
				usage();
			break;

		case 'P':
			passwd = optarg;
			break;

		case 'u':
			user = np_default_users->uname2user(np_default_users, optarg);
			break;


		case 'U':
			dotu = 0;
			break;

		default:
			usage();
		}
	}

	

	if (argc - optind < 2)
		usage();

	addr = argv[optind];
	path = argv[optind+1];

	if(passwd) {
		if(!authsrv)
			authsrv = addr;
		memset(&auth, 0, sizeof auth);
		makeKey(passwd, auth.key);
		auth.srv = npc_netaddr(authsrv, 567);
		fs = npc_netmount(npc_netaddr(addr, port), dotu, user, port, authp9any, &auth);
	} else {
		fs = npc_netmount(npc_netaddr(addr, port), dotu, user, port, NULL, NULL);
	}

	if(!fs) {
		char *estr;
		int eno;

		np_rerror(&estr, &eno);
		fprintf(stderr, "error mounting: (%d) %s\n", eno, estr);
		exit(1);
	}

	fid = npc_open(fs, path, Oread);
	if (!fid) {
		fprintf(stderr, "error\n");
	}

	while (1) {
		n = npc_dirread(fid, &stat);
		if (n <= 0)
			break;

		for(i = 0; i < n; i++)
			printf("%s\n", stat[i].name);
		free(stat);
	}

	npc_close(fid);
	npc_umount(fs);

	exit(0);
}