You can subscribe to this list here.
2008 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(2) |
Jun
|
Jul
(1) |
Aug
|
Sep
(6) |
Oct
|
Nov
(11) |
Dec
(5) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2009 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(7) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(9) |
Dec
(4) |
2010 |
Jan
(4) |
Feb
(2) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
From: <ab...@us...> - 2010-12-27 22:40:10
|
Revision: 59 http://npfs.svn.sourceforge.net/npfs/?rev=59&view=rev Author: abbyz9 Date: 2010-12-27 22:40:04 +0000 (Mon, 27 Dec 2010) Log Message: ----------- Changes in v9fs broke pipesrv. Fix it. Modified Paths: -------------- npfs/trunk/libnpfs/pipesrv.c Modified: npfs/trunk/libnpfs/pipesrv.c =================================================================== --- npfs/trunk/libnpfs/pipesrv.c 2010-02-16 22:10:33 UTC (rev 58) +++ npfs/trunk/libnpfs/pipesrv.c 2010-12-27 22:40:04 UTC (rev 59) @@ -87,7 +87,7 @@ ps = srv->srvaux; snprintf(options, sizeof(options), - "msize=%d,name=%s,%s,proto=fd,rfdno=%d,wfdno=%d,%s", + "maxdata=%d,uname=%s,%s,trans=fd,rfdno=%d,wfdno=%d,%s", srv->msize, user, srv->dotu?"":"noextend", ps->pipout[0], ps->pipin[1], opts); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-02-16 22:10:44
|
Revision: 58 http://npfs.svn.sourceforge.net/npfs/?rev=58&view=rev Author: newsham Date: 2010-02-16 22:10:33 +0000 (Tue, 16 Feb 2010) Log Message: ----------- - don't set nfid until after we verified that a new fid has been opened, as setting nfid is what indicates that a fid must be clunked if an error occurs. Acked by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpclient/walk.c Modified: npfs/trunk/libnpclient/walk.c =================================================================== --- npfs/trunk/libnpclient/walk.c 2010-02-16 03:14:36 UTC (rev 57) +++ npfs/trunk/libnpclient/walk.c 2010-02-16 22:10:33 UTC (rev 58) @@ -67,11 +67,11 @@ if (npc_rpc(fs, tc, &rc) < 0) goto error; - nfid = fid->fid; if (rc->nwqid != n) { np_werror("file not found", ENOENT); goto error; } + nfid = fid->fid; if(n > 0) fid->qid = rc->wqids[n-1]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-02-16 03:14:45
|
Revision: 57 http://npfs.svn.sourceforge.net/npfs/?rev=57&view=rev Author: newsham Date: 2010-02-16 03:14:36 +0000 (Tue, 16 Feb 2010) Log Message: ----------- - filled in group field, previously missing. Acked: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpclient/stat.c Modified: npfs/trunk/libnpclient/stat.c =================================================================== --- npfs/trunk/libnpclient/stat.c 2010-01-05 21:24:16 UTC (rev 56) +++ npfs/trunk/libnpclient/stat.c 2010-02-16 03:14:36 UTC (rev 57) @@ -71,7 +71,6 @@ u16 i16 = 0xffff; u8 i8 = 0xff; - st->size = i16; st->type = i16; st->dev = i32; st->qid.type = i8; @@ -83,6 +82,7 @@ st->length = i64; st->name = ""; st->uid = ""; + st->gid = ""; st->muid = ""; st->n_uid = i32; st->n_gid = i32; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-01-05 21:24:23
|
Revision: 56 http://npfs.svn.sourceforge.net/npfs/?rev=56&view=rev Author: newsham Date: 2010-01-05 21:24:16 +0000 (Tue, 05 Jan 2010) Log Message: ----------- - oops, remove some debugging cruft. Modified Paths: -------------- npfs/trunk/libnpauth/authsrv/authsrv.c Modified: npfs/trunk/libnpauth/authsrv/authsrv.c =================================================================== --- npfs/trunk/libnpauth/authsrv/authsrv.c 2010-01-05 21:05:01 UTC (rev 55) +++ npfs/trunk/libnpauth/authsrv/authsrv.c 2010-01-05 21:24:16 UTC (rev 56) @@ -69,10 +69,7 @@ u = findUser(user); if(u) { -int i; printf("using user=%s password=%s\n", user, u->passwd); -for(i = 0; i < 7; i++) printf("%02x ", (unsigned char)u->key[i]); -printf("\n"); return u->key; } printf("user %s not found, sending garbage\n", user); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-01-05 21:05:07
|
Revision: 55 http://npfs.svn.sourceforge.net/npfs/?rev=55&view=rev Author: newsham Date: 2010-01-05 21:05:01 +0000 (Tue, 05 Jan 2010) Log Message: ----------- - be better at detecting when getpwname_r and friends fail. Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpfs/uxusers.c Modified: npfs/trunk/libnpfs/uxusers.c =================================================================== --- npfs/trunk/libnpfs/uxusers.c 2010-01-05 19:32:54 UTC (rev 54) +++ npfs/trunk/libnpfs/uxusers.c 2010-01-05 21:05:01 UTC (rev 55) @@ -123,7 +123,7 @@ buf = np_malloc(bufsize); i = getpwnam_r(uname, &pw, buf, bufsize, &pwp); - if (i) { + if (i || !pwp) { np_uerror(i); free(buf); free(u); @@ -185,7 +185,7 @@ buf = np_malloc(bufsize); i = getpwuid_r(uid, &pw, buf, bufsize, &pwp); - if (i) { + if (i || !pwp) { np_uerror(i); free(buf); free(u); @@ -242,7 +242,7 @@ buf = np_malloc(bufsize); i = getgrnam_r(gname, &grp, buf, bufsize, &pgrp); - if (i) { + if (i || !pgrp) { np_uerror(i); free(buf); free(g); @@ -295,7 +295,7 @@ buf = np_malloc(bufsize); err = getgrgid_r(gid, &grp, buf, bufsize, &pgrp); - if (err) { + if (err || !pgrp) { np_uerror(err); free(buf); free(g); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-01-05 19:33:09
|
Revision: 54 http://npfs.svn.sourceforge.net/npfs/?rev=54&view=rev Author: newsham Date: 2010-01-05 19:32:54 +0000 (Tue, 05 Jan 2010) Log Message: ----------- - Add the new libnpauth library. Tested on windows, linux and osx and against npfs, plan9, and py9p. Example npfs server and client in examples subdir. Example authserver in authsrv subdir. Added Paths: ----------- npfs/trunk/include/npauth.h npfs/trunk/libnpauth/ npfs/trunk/libnpauth/Makefile npfs/trunk/libnpauth/authsrv/ npfs/trunk/libnpauth/authsrv/Makefile npfs/trunk/libnpauth/authsrv/authsrv.c npfs/trunk/libnpauth/authsrv/ntmakefile npfs/trunk/libnpauth/authsrv/sources npfs/trunk/libnpauth/authsrv/winhelp.c npfs/trunk/libnpauth/examples/ npfs/trunk/libnpauth/examples/9ls.c npfs/trunk/libnpauth/examples/Makefile npfs/trunk/libnpauth/examples/echofs.c npfs/trunk/libnpauth/examples/ntmakefile npfs/trunk/libnpauth/examples/sources npfs/trunk/libnpauth/examples/winhelp.c npfs/trunk/libnpauth/help.c npfs/trunk/libnpauth/msgs.c npfs/trunk/libnpauth/npaimpl.h npfs/trunk/libnpauth/ntmakefile npfs/trunk/libnpauth/ossl.h npfs/trunk/libnpauth/p9any.c npfs/trunk/libnpauth/p9sk1.c npfs/trunk/libnpauth/sources npfs/trunk/libnpauth/srv.c Added: npfs/trunk/include/npauth.h =================================================================== --- npfs/trunk/include/npauth.h (rev 0) +++ npfs/trunk/include/npauth.h 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,36 @@ + +struct addrinfo; + +// client state during auth +typedef struct npcauth { + struct addrinfo *srv; + char key[7]; + int gen; +} Npcauth; + +// server state during auth +typedef struct npsrvauth { + int state; + int gen; + int done; + char chc[8], chs[8]; + char *ids, *dom, *key; // prefilled server identity + char *idc, *idr; // auth information, dynamic alloc'd +} Npsrvauth; + +extern char *srvid; // fill with server's username +extern char *srvdom; // fill with server's domain +extern char srvkey[7]; // fill with server's key + +extern Npauth srvauthp9any; +extern Npauth srvauthp9sk1; + +// aux must be an npcauth structure. +int authp9any(Npcfid *fid, Npuser *user, void *aux); +int authp9sk1(Npcfid *fid, Npuser *user, void *aux); + +int srvp9any(struct npsrvauth *a, char *msg, int len, char *resp, int resplen); +int srvp9sk1(struct npsrvauth *a, char *msg, int len, char *resp, int resplen); + +void makeKey(char *pw, char *key); + Added: npfs/trunk/libnpauth/Makefile =================================================================== --- npfs/trunk/libnpauth/Makefile (rev 0) +++ npfs/trunk/libnpauth/Makefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,31 @@ +SYSNAME:=${shell uname} +SYSNAME!=uname +MULTILIBPATH=${shell test -d /lib64 && echo lib64 || echo lib} +HFILES=../include/npfs.h ../include/npclient.h ../include/npauth.h npaimpl.h +CFLAGS=-Wall -g -I ../include + +LIBFILES=\ + help.o\ + msgs.o\ + p9any.o\ + p9sk1.o\ + srv.o\ + +libnpauth.a: $(LIBFILES) + ar rc libnpauth.a $(LIBFILES) + ranlib libnpauth.a + +install: + mkdir -p $(INSTALLPREFIX)/include + mkdir -p $(INSTALLPREFIX)/$(MULTILIBPATH) + cp ../include/npauth.h $(INSTALLPREFIX)/include + cp libnpauth.a $(INSTALLPREFIX)/$(MULTILIBPATH) + +clean: + rm -f *.o *.a *~ + make -C examples clean + +$(LIBFILES): Makefile $(HFILES) + +%.o: %.c + $(CC) $(CFLAGS) -c $*.c Added: npfs/trunk/libnpauth/authsrv/Makefile =================================================================== --- npfs/trunk/libnpauth/authsrv/Makefile (rev 0) +++ npfs/trunk/libnpauth/authsrv/Makefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,15 @@ +CFLAGS=-Wall -g -I ../../include +LFLAGS=-L../../libnpfs -L.. -lnpauth -lnpclient -lnpfs -lpthread -lcrypto + +CMD=authsrv + +all: $(CMD) + +authsrv: authsrv.o ../../libnpfs/libnpfs.a ../../libnpclient/libnpclient.a ../libnpauth.a + $(CC) -o $@ $(CFLAGS) authsrv.o $(LFLAGS) + +clean: + rm -f *.o *.a *~ $(CMD) + +%.o: %.c + $(CC) $(CFLAGS) -c $*.c Added: npfs/trunk/libnpauth/authsrv/authsrv.c =================================================================== --- npfs/trunk/libnpauth/authsrv/authsrv.c (rev 0) +++ npfs/trunk/libnpauth/authsrv/authsrv.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,220 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <arpa/inet.h> + #define __cdecl +#endif + +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "../npaimpl.h" + +char *dom = "testdom.com"; + +struct ident { + char *user; + char *passwd; + char key[7]; +}; +struct ident users[] = { + // If your server uses uxusers then these accounts must exist locally + { "root", "rootpw" }, + { "bin", "binpw" }, + { 0, 0 }, +}; + +static void +xperror(char *msg) +{ + perror(msg); + exit(1); +} + +static struct ident * +findUser(char *user) +{ + int i; + + for(i = 0; users[i].user; i++) { + if(strcmp(users[i].user, user) == 0) + return &users[i]; + } + return NULL; +} + +static void +initUsers() +{ + int i; + + for(i = 0; users[i].user; i++) { + makeKey(users[i].passwd, users[i].key); + } +} + +static char * +getKey(char *user, char key[7]) +{ + struct ident *u; + + u = findUser(user); + if(u) { +int i; + printf("using user=%s password=%s\n", user, u->passwd); +for(i = 0; i < 7; i++) printf("%02x ", (unsigned char)u->key[i]); +printf("\n"); + return u->key; + } + printf("user %s not found, sending garbage\n", user); + getRand(key, 7); + return key; +} + +static int +speaksFor(char *idc, char *idr) +{ + return strcmp(idc, idr) == 0; +} + +static void +serv1(int s) +{ + char outbuf[145], treqbuf[141], kn[7], kc[7], ks[7]; + struct ticketreq treq; + struct ticket ctick, stick; + + if(read(s, treqbuf, sizeof treqbuf) != sizeof treqbuf + || decTicketReq(treqbuf, &treq) == -1 + || treq.type != AuthTreq + || strcmp(treq.dom, dom) != 0 + || !speaksFor(treq.idc, treq.idr)) + goto err; + + getRand(kn, sizeof kn); + + ctick.type = AuthTc; + ctick.ch = treq.ch; + ctick.idc = treq.idc; + ctick.idr = treq.idr; + ctick.key = kn; + + stick.type = AuthTs; + stick.ch = treq.ch; + stick.idc = treq.idc; + stick.idr = treq.idr; + stick.key = kn; + + outbuf[0] = AuthOK; + if(encTicket(outbuf+1, &ctick, getKey(treq.idc, kc)) == -1 + || encTicket(outbuf+73, &stick, getKey(treq.ids, ks)) == -1 + || write(s, outbuf, sizeof outbuf) != sizeof outbuf) + goto err; + close(s); + return; + +err: + printf("error\n"); + close(s); +} + +static int +tcp_listen(int port) +{ + struct sockaddr_in addr; + int s; + + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_port = htons(port); + s = socket(AF_INET, SOCK_STREAM, 0); + if(s == -1) + xperror("socket"); + if(bind(s, (struct sockaddr *)&addr, sizeof addr) == -1) + xperror("bind"); + if(listen(s, 5) == -1) + xperror("listen"); + return s; +} + +void +server(int port) +{ + struct sockaddr_in addr; + size_t adlen; + int s, s2; + + s = tcp_listen(port); + for(;;) { + adlen = sizeof addr; + s2 = accept(s, (struct sockaddr *)&addr, &adlen); + if(s2 == -1) + xperror("accept"); + printf("connection from %s:%d\n", inet_ntoa(addr.sin_addr), ntohs(addr.sin_port)); +#ifdef _WIN32 + // just one at a time for now... + serv1(s2); +#else + switch(fork()) { + case -1: + perror("fork"); + break; + case 0: + close(s); + serv1(s2); + exit(0); + break; + default: + break; + } +#endif + close(s2); + } +} + +void +usage(char *prog) +{ + fprintf(stderr, "usage: %s [-p port]", prog); + exit(1); +} + +int __cdecl +main(int argc, char **argv) +{ + int port, ch; + char *prog; + +#ifdef _WIN32 + init(); +#endif + prog = argv[0]; + port = 567; + while((ch = getopt(argc, argv, "p:")) != -1) { + switch(ch) { + case 'p': + port = atoi(optarg); + break; + default: + usage(prog); + } + } + argc -= optind; + argv += optind; + if(argc) + usage(prog); + + initUsers(); + server(port); + return 0; +} + Added: npfs/trunk/libnpauth/authsrv/ntmakefile =================================================================== --- npfs/trunk/libnpauth/authsrv/ntmakefile (rev 0) +++ npfs/trunk/libnpauth/authsrv/ntmakefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Added: npfs/trunk/libnpauth/authsrv/sources =================================================================== --- npfs/trunk/libnpauth/authsrv/sources (rev 0) +++ npfs/trunk/libnpauth/authsrv/sources 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,18 @@ +TARGETTYPE=PROGRAM + +OPENSSL=c:\openssl +INCLUDES=..\..\include +LINKLIBS=\ + ..\..\libnpauth\$(O)\npauth.lib \ + ..\..\libnpclient\$(O)\npclient.lib \ + ..\..\libnpfs\$(O)\npfs.lib \ + $(SDK_LIB_PATH)\ws2_32.lib \ + $(OPENSSL)\lib\VC\libeay32MT.lib + +USE_MSVCRT=1 + +TARGETNAME=authsrv +SOURCES=authsrv.c winhelp.c + +UMTYPE=console +UMBASE=0x400000 Added: npfs/trunk/libnpauth/authsrv/winhelp.c =================================================================== --- npfs/trunk/libnpauth/authsrv/winhelp.c (rev 0) +++ npfs/trunk/libnpauth/authsrv/winhelp.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,47 @@ +#include <windows.h> +#include <winsock2.h> +#include <string.h> + +static int optind = 1; +static int optpos = 0; +static char *optarg = NULL; + +static int +getopt(int argc, char **argv, const char *opts) +{ + char *p, ch; + + if(optind >= argc || !argv[optind]) + return -1; + if(optpos && !argv[optind][optpos]) { + optind ++; + optpos = 0; + } + if(optind >= argc || !argv[optind]) + return -1; + if(optpos == 0 && argv[optind][optpos++] != '-') + return -1; + ch = argv[optind][optpos++]; + p = strchr(opts, ch); + if(!p) + return '?'; + if(p[1] != ':') + return ch; + + optarg = argv[optind++] + optpos; + optpos = 0; + if(*optarg) + return ch; + if(optind >= argc || !argv[optind]) + return '?'; + optarg = argv[optind++]; + return ch; +} + +static void +init() { + WSADATA wsData; + + WSAStartup(MAKEWORD(2,2), &wsData); +} + Added: npfs/trunk/libnpauth/examples/9ls.c =================================================================== --- npfs/trunk/libnpauth/examples/9ls.c (rev 0) +++ npfs/trunk/libnpauth/examples/9ls.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2005 by Latchesar Ionkov <lu...@io...> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#define _XOPEN_SOURCE 600 +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <assert.h> +#include "npfs.h" +#include "npclient.h" +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #define __cdecl +#endif +#include "npauth.h" + + +extern int npc_chatty; + +static void +usage() +{ + fprintf(stderr, "9ls [-dU] [-a authsrv] [-p port] [-P passwd] [-u user] addr path\n"); + exit(1); +} + +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); +} Added: npfs/trunk/libnpauth/examples/Makefile =================================================================== --- npfs/trunk/libnpauth/examples/Makefile (rev 0) +++ npfs/trunk/libnpauth/examples/Makefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,20 @@ +SYSNAME:=${shell uname} +SYSNAME!=uname +CFLAGS=-Wall -g -I ../../include +LFLAGS=-L../../libnpfs -L.. -lnpauth -lnpclient -lnpfs -lpthread -lcrypto + +CMD=9ls echofs + +all: $(CMD) + +9ls: 9ls.o ../../libnpfs/libnpfs.a ../../libnpclient/libnpclient.a ../libnpauth.a + $(CC) -o $@ $(CFLAGS) 9ls.o $(LFLAGS) + +echofs: echofs.o ../../libnpfs/libnpfs.a ../../libnpclient/libnpclient.a ../libnpauth.a + $(CC) -o $@ $(CFLAGS) echofs.o $(LFLAGS) + +clean: + rm -f *.o *.a *~ $(CMD) + +%.o: %.c + $(CC) $(CFLAGS) -c $*.c Added: npfs/trunk/libnpauth/examples/echofs.c =================================================================== --- npfs/trunk/libnpauth/examples/echofs.c (rev 0) +++ npfs/trunk/libnpauth/examples/echofs.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2005 by Latchesar Ionkov <lu...@io...> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * LATCHESAR IONKOV AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ +#define _XOPEN_SOURCE 600 +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <time.h> +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #define __cdecl +#endif +#include "npfs.h" +#include "npclient.h" // ugh.. irritating dep from npauth +#include "npauth.h" + +typedef struct Req Req; +struct Req { + Npreq* req; + Req* next; +}; + +static Npfile* echo_first(Npfile *); +static Npfile* echo_next(Npfile *, Npfile *); +static int echo_read(Npfilefid *, u64, u32, u8*, Npreq *); +static int echo_write(Npfilefid *, u64, u32, u8*, Npreq *); +static int echo_wstat(Npfile *, Npstat *); +static void echo_connclose(Npconn *); + +static Npsrv *srv; +static Npfile *root; +static Npfile *echo; +static pthread_mutex_t reqslock = PTHREAD_MUTEX_INITIALIZER; +static Req *reqs; + +static Npdirops rootops = { + 0, 0, 0, + echo_first, echo_next, + 0, 0, 0, 0, 0 +}; + +static Npfileops nullops = { + 0, 0, + echo_read, echo_write, echo_wstat, + 0, 0, 0 +}; + +static void +usage() +{ + fprintf(stderr, "echofs: [-d] [-w nthreads] [-p port] id domain password\n"); + exit(-1); +} + +int __cdecl +main(int argc, char **argv) +{ + int c, debuglevel, nwthreads, port; + Npuser *user; + char *s; +#ifdef _WIN32 + WSADATA wsData; + + WSAStartup(MAKEWORD(2,2), &wsData); +#endif + + debuglevel = 0; + nwthreads = 16; + port = 564; + while ((c = getopt(argc, argv, "dp:w:")) != -1) { + switch (c) { + case 'd': + debuglevel = 1; + break; + + case 'p': + port = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + + case 'w': + nwthreads = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + + default: + fprintf(stderr, "invalid option\n"); + usage(); + exit(1); + } + } + + argc -= optind; + argv += optind; + if (argc != 3) + usage(); + + srvid = argv[0]; + srvdom = argv[1]; + makeKey(argv[2], srvkey); + user = np_default_users->uname2user(np_default_users, srvid); + + if (!user) { + fprintf(stderr, "invalid user\n"); + return -1; + } + + root = npfile_alloc(NULL, strdup(""), 0755|Dmdir, 0, &rootops, NULL); + root->parent = root; + npfile_incref(root); + root->atime = time(NULL); + root->mtime = root->atime; + root->uid = user; + root->gid = user->dfltgroup; + root->muid = user; + + echo = npfile_alloc(root, strdup("echo"), 0644, 1, &nullops, NULL); + npfile_incref(echo); + root->dirfirst = echo; + root->dirlast = echo; + + srv = np_socksrv_create_tcp(nwthreads, &port); + if (!srv) { + fprintf(stderr, "cant create server\n"); + return -1; + } + + srv->debuglevel = debuglevel; + srv->connclose = echo_connclose; + srv->auth = &srvauthp9any; + npfile_init_srv(srv, root); + np_srv_start(srv); + + while (1) { + sleep(100); + } + + return 0; +} + +static void +echo_connclose(Npconn *conn) +{ + exit(0); +} + +static Npfile* +echo_first(Npfile *dir) +{ + if (dir->dirfirst) + npfile_incref(dir->dirfirst); + + return dir->dirfirst; +} + +static Npfile* +echo_next(Npfile *dir, Npfile *prevchild) +{ + if (prevchild->next) + npfile_incref(prevchild->next); + + return prevchild->next; +} + +static int +echo_read(Npfilefid* file, u64 offset, u32 count, u8* data, Npreq *req) +{ + Req *r; + + pthread_mutex_lock(&reqslock); + r = malloc(sizeof(*r)); + r->req = req; + r->next = reqs; + reqs = r; + pthread_mutex_unlock(&reqslock); + + return -1; +} + +static int +echo_write(Npfilefid* file, u64 offset, u32 count, u8* data, Npreq *req) +{ + Npfcall *rc; + Req *r, *r1; + + pthread_mutex_lock(&reqslock); + r = reqs; + reqs = NULL; + pthread_mutex_unlock(&reqslock); + + while (r) { + rc = np_create_rread(count, data); + np_respond(r->req, rc); + r1 = r->next; + free(r); + r = r1; + } + + return count; +} + +static int +echo_wstat(Npfile* file, Npstat* stat) +{ + return 1; +} Added: npfs/trunk/libnpauth/examples/ntmakefile =================================================================== --- npfs/trunk/libnpauth/examples/ntmakefile (rev 0) +++ npfs/trunk/libnpauth/examples/ntmakefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Added: npfs/trunk/libnpauth/examples/sources =================================================================== --- npfs/trunk/libnpauth/examples/sources (rev 0) +++ npfs/trunk/libnpauth/examples/sources 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,23 @@ +TARGETTYPE=PROGRAM + +OPENSSL=c:\openssl +INCLUDES=..\..\include +LINKLIBS=\ + ..\..\libnpauth\$(O)\npauth.lib \ + ..\..\libnpclient\$(O)\npclient.lib \ + ..\..\libnpfs\$(O)\npfs.lib \ + $(SDK_LIB_PATH)\ws2_32.lib \ + $(OPENSSL)\lib\VC\libeay32MT.lib + +USE_MSVCRT=1 + +# ----- pick one ----- + +#TARGETNAME=9ls +#SOURCES=9ls.c winhelp.c + +TARGETNAME=echofs +SOURCES=echofs.c winhelp.c + +UMTYPE=console +UMBASE=0x400000 Added: npfs/trunk/libnpauth/examples/winhelp.c =================================================================== --- npfs/trunk/libnpauth/examples/winhelp.c (rev 0) +++ npfs/trunk/libnpauth/examples/winhelp.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,47 @@ +#include <windows.h> +#include <winsock2.h> +#include <string.h> + +static int optind = 1; +static int optpos = 0; +static char *optarg = NULL; + +static int +getopt(int argc, char **argv, const char *opts) +{ + char *p, ch; + + if(optind >= argc || !argv[optind]) + return -1; + if(optpos && !argv[optind][optpos]) { + optind ++; + optpos = 0; + } + if(optind >= argc || !argv[optind]) + return -1; + if(optpos == 0 && argv[optind][optpos++] != '-') + return -1; + ch = argv[optind][optpos++]; + p = strchr(opts, ch); + if(!p) + return '?'; + if(p[1] != ':') + return ch; + + optarg = argv[optind++] + optpos; + optpos = 0; + if(*optarg) + return ch; + if(optind >= argc || !argv[optind]) + return '?'; + optarg = argv[optind++]; + return ch; +} + +static void +init() { + WSADATA wsData; + + WSAStartup(MAKEWORD(2,2), &wsData); +} + Added: npfs/trunk/libnpauth/help.c =================================================================== --- npfs/trunk/libnpauth/help.c (rev 0) +++ npfs/trunk/libnpauth/help.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,90 @@ +#include <stdarg.h> +#include <stdio.h> +#include <string.h> +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "npaimpl.h" + +int +get(Npcfid *fid, char *buf, int sz) +{ + int n; + + n = npc_read(fid, (u8*)buf, sz, fid->offset); + if(n > 0) { + if(n != sz) + return -1; + fid->offset += n; + } + return n; +} + +// read NUL-terminated line, expected in a single read operation. +int +getline0(Npcfid *fid, char *buf, int sz) +{ + int n; + + n = npc_read(fid, (u8*)buf, sz, fid->offset); + if(n <= 0 || buf[n-1] != '\0' || strlen(buf) != n-1) + return -1; + if(n > 0) + fid->offset += n; + return n; +} + +int +put(Npcfid *fid, char *buf, int sz) +{ + int n; + + n = npc_write(fid, (u8*)buf, sz, fid->offset); + if(n >= 0) { + if(n != sz) + return -1; + fid->offset += n; + } + return n; +} + +int +putline0(Npcfid *fid, char *fmt, ...) +{ + char buf[128]; + int l; + va_list ap; + + va_start(ap, fmt); + l = vsnprintf(buf, sizeof buf - 1, fmt, ap); + if(l >= sizeof buf - 1) + return -1; + va_end(ap); + return put(fid, buf, l+1); +} + +int +err(char *msg, int no) +{ + np_werror(msg, no); + return -1; +} + +int +getWord(char **buf, char sep, char **retbuf) +{ + char *p; + + p = NULL; + if(sep) + p = strchr(*buf, sep); + if(!p) + p = *buf + strlen(*buf); + *retbuf = *buf; + if(*p) + *p++ = 0; + *buf = p; + return 0; +} + Added: npfs/trunk/libnpauth/msgs.c =================================================================== --- npfs/trunk/libnpauth/msgs.c (rev 0) +++ npfs/trunk/libnpauth/msgs.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,266 @@ +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "npaimpl.h" +#include "ossl.h" + +void +setKey(unsigned char *key, DES_key_schedule *sched) +{ + DES_cblock kb; + + // expand 7 bytes to 8 and add parity in low bit + kb[0] = key[0]; + kb[1] = (key[0] << 7) | (key[1] >> 1); + kb[2] = (key[1] << 6) | (key[2] >> 2); + kb[3] = (key[2] << 5) | (key[3] >> 3); + kb[4] = (key[3] << 4) | (key[4] >> 4); + kb[5] = (key[4] << 3) | (key[5] >> 5); + kb[6] = (key[5] << 2) | (key[6] >> 6); + kb[7] = (key[6] << 1); + DES_set_odd_parity(&kb); + DES_set_key_checked(&kb, sched); +} + + +int +_encrypt(unsigned char *buf, int n, char *key) +{ + DES_key_schedule sched; + int i, r; + + if(n < 8) + return -1; + setKey((unsigned char *)key, &sched); + n--; + r = n % 7; + n /= 7; + for(i = 0; i < n; i++) { + DES_ecb_encrypt((DES_cblock *)buf, (DES_cblock *)buf, &sched, DES_ENCRYPT); + buf += 7; + } + if(r) + DES_ecb_encrypt((DES_cblock *)(buf - 7 + r), (DES_cblock *)(buf - 7 + r), &sched, DES_ENCRYPT); + return 0; +} + +int +_decrypt(unsigned char *buf, int n, char *key) +{ + DES_key_schedule sched; + int i, r; + + if(n < 8) + return -1; + setKey((unsigned char *)key, &sched); + n --; + r = n % 7; + n /= 7; + + buf += n*7; + if(r) + DES_ecb_encrypt((DES_cblock *)(buf - 7 + r), (DES_cblock *)(buf - 7 + r), &sched, DES_DECRYPT); + for(i = 0; i < n; i++) { + buf -= 7; + DES_ecb_encrypt((DES_cblock *)buf, (DES_cblock *)buf, &sched, DES_DECRYPT); + } + return 0; +} + +void +makeKey(char *pw, char *key) +{ + char pwbuf[28]; + unsigned char *t; + int n, i; + + // always at least 8 characters. NUL terminated before 28 chars + n = strlen(pw); + if(n > 27) + n = 27; + memset(pwbuf, ' ', 8); + strncpy(pwbuf, pw, n); + pwbuf[n] = 0; + + t = (unsigned char *)pwbuf; + for(;;) { + for(i = 0; i < 7; i++) + key[i] = (t[i] >> i) + (t[i+1] << (8 - (i+1))); + if(n <= 8) + return; + + n -= 8; + t += 8; + if(n < 8) { + t -= 8 - n; + n = 8; + } + // encrypt next 8, or last 8, with pw. + _encrypt(t, 8, key); + } +} + +static int +dec4(char **buf, int *x) +{ + char *p = *buf; + + *x = (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]; + *buf += 4; + return 0; +} + +static int +enc4(char **buf, int x) +{ + char *p = *buf; + + p[0] = x >> 24; + p[1] = x >> 16; + p[2] = x >> 8; + p[3] = x; + *buf += 4; + return 0; +} + +static int +decFixed(char **buf, int sz, char **r) +{ + *r = *buf; + *buf += sz; + return 0; +} + +static int +encFixed(char **buf, int sz, char *r) +{ + memcpy(*buf, r, sz); + *buf += sz; + return 0; +} + +static int +decPad(char **buf, int sz, char **r) +{ + char *p; + + // We give up the ability to decode all possible strings + // in exchange for the ability to decode in-place. Our max + // length is one shorter than what the protocol may dictate. + // This is unlikely to be a problem. + *r = *buf; + p = *buf; + *buf += sz; + while(*p && sz) { + p++; + sz--; + } + if(*p) + return -1; + return 0; +} + +static int +encPad(char **buf, int sz, char *r) +{ + int l; + + l = strlen(r); + if(l >= sz) + return -1; + strcpy(*buf, r); + memset(*buf+l, 0, sz-l); + *buf += sz; + return 0; +} + +int +decTicketReq(char *buf, struct ticketreq *r) +{ + r->type = *buf++; + if(decPad(&buf, 28, &r->ids) == -1 + || decPad(&buf, 48, &r->dom) == -1 + || decFixed(&buf, 8, &r->ch) == -1 + || decPad(&buf, 28, &r->idc) == -1 + || decPad(&buf, 28, &r->idr) == -1) + return -1; + return 0; +} + +int +encTicketReq(char *buf, struct ticketreq *r) +{ + *buf++ = r->type; + if(encPad(&buf, 28, r->ids) == -1 + || encPad(&buf, 48, r->dom) == -1 + || encFixed(&buf, 8, r->ch) == -1 + || encPad(&buf, 28, r->idc) == -1 + || encPad(&buf, 28, r->idr) == -1) + return -1; + return 0; +} + +int +decTicket(char *buf, struct ticket *r, char *key) +{ + _decrypt((unsigned char *)buf, 72, key); + r->type = *buf++; + if(decFixed(&buf, 8, &r->ch) == -1 + || decPad(&buf, 28, &r->idc) == -1 + || decPad(&buf, 28, &r->idr) == -1 + || decFixed(&buf, 7, &r->key) == -1) + return -1; + return 0; +} + +int +encTicket(char *buf, struct ticket *r, char *key) +{ + char *p = buf; + *p++ = r->type; + if(encFixed(&p, 8, r->ch) == -1 + || encPad(&p, 28, r->idc) == -1 + || encPad(&p, 28, r->idr) == -1 + || encFixed(&p, 7, r->key) == -1) + return -1; + _encrypt((unsigned char *)buf, 72, key); + return 0; +} + +int +decAuth(char *buf, struct auth *r, char *key) +{ + _decrypt((unsigned char *)buf, 13, key); + r->type = *buf++; + if(decFixed(&buf, 8, &r->ch) == -1 + || dec4(&buf, &r->gen) == -1) + return -1; + return 0; +} + +int +encAuth(char *buf, struct auth *r, char *key) +{ + char *p = buf; + + *p++ = r->type; + if(encFixed(&p, 8, r->ch) == -1 + || enc4(&p, r->gen) == -1) + return -1; + _encrypt((unsigned char *)buf, 13, key); + return 0; +} + +void +getRand(char *buf, int sz) +{ + int x; + + x = RAND_bytes((unsigned char *)buf, sz); + assert(x != 0); +} + Added: npfs/trunk/libnpauth/npaimpl.h =================================================================== --- npfs/trunk/libnpauth/npaimpl.h (rev 0) +++ npfs/trunk/libnpauth/npaimpl.h 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,50 @@ + +enum { + AuthTreq = 1, AuthChal, AuthPass, AuthOK, AuthErr, AuthMod, + AuthTs = 64, AuthTc, AuthAs, AuthAc, AuthTp, AuthHr, +}; + +struct DES_ks; + +struct ticketreq { + char type; + char *ids; + char *dom; + char *ch; + char *idc; + char *idr; +}; + +struct ticket { + char type; + char *ch; + char *idc; + char *idr; + char *key; +}; + +struct auth { + char type; + char *ch; + int gen; +}; + +void setKey(unsigned char *key, struct DES_ks *sched); +int _encrypt(unsigned char *buf, int n, char *key); +int _decrypt(unsigned char *buf, int n, char *key); +void getRand(char *buf, int sz); + +int decTicketReq(char *buf, struct ticketreq *r); +int encTicketReq(char *buf, struct ticketreq *r); +int decTicket(char *buf, struct ticket *r, char *key); +int encTicket(char *buf, struct ticket *r, char *key); +int decAuth(char *buf, struct auth *r, char *key); +int encAuth(char *buf, struct auth *r, char *key); + +int get(Npcfid *fid, char *buf, int sz); +int getline0(Npcfid *fid, char *buf, int sz); +int put(Npcfid *fid, char *buf, int sz); +int putline0(Npcfid *fid, char *fmt, ...); +int err(char *msg, int no); +int getWord(char **buf, char sep, char **retbuf); + Added: npfs/trunk/libnpauth/ntmakefile =================================================================== --- npfs/trunk/libnpauth/ntmakefile (rev 0) +++ npfs/trunk/libnpauth/ntmakefile 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Added: npfs/trunk/libnpauth/ossl.h =================================================================== --- npfs/trunk/libnpauth/ossl.h (rev 0) +++ npfs/trunk/libnpauth/ossl.h 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,21 @@ + +#ifdef _WIN32 + // all OpenSSL functions are CDECL, although none of the headers + // have annotations for this. As a quick workaround, we use CPP + // to add annotations. + // We can't simply force all functions to be CDECL because we want + // to be able to link against other libraries that may not be CDECL + #define DECL __cdecl + #define DES_set_key_checked DECL DES_set_key_checked + #define DES_set_odd_parity DECL DES_set_odd_parity + #define DES_ecb_encrypt DECL DES_ecb_encrypt + #define RAND_bytes DECL RAND_bytes +#endif + +#include <openssl/rand.h> +#include <openssl/des.h> + +#ifdef _WIN32 + #undef DECL + #define DECL +#endif Added: npfs/trunk/libnpauth/p9any.c =================================================================== --- npfs/trunk/libnpauth/p9any.c (rev 0) +++ npfs/trunk/libnpauth/p9any.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,108 @@ + +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "npaimpl.h" + +#ifdef _WIN32 +#define EPROTONOSUPPORT 93 // XXX +#endif + +struct authproto { + char *name; + int (*auth)(Npcfid *fid, Npuser *user, void *aux); +}; + +static struct authproto authprotos[] = { + { "p9sk1", authp9sk1 }, + { 0, 0 }, +}; + +int +srvp9any(struct npsrvauth *a, char *msg, int len, char *resp, int resplen) +{ + char *proto, *dom; + int r; + + switch(a->state) { + case 0: + if(len != 0 + || resplen < strlen(a->dom) + 32) + return err("internal error", EINVAL); + sprintf(resp, "v.2 p9sk1@%s", a->dom); + a->state++; + return strlen(resp) + 1; + + case 1: + if(len == 0 + || msg[len-1] != '\0' + || strlen(msg) != len-1 + || getWord(&msg, ' ', &proto) == -1 + || getWord(&msg, 0, &dom) == -1 + || strcmp(dom, a->dom) != 0) + return err("botch", EINVAL); + if(strcmp(proto, "p9sk1") != 0) + return err("unsupported", EPROTONOSUPPORT); + if(resplen < 32) + return err("internal error", EINVAL); + strcpy(resp, "OK"); + a->state++; + return strlen(resp) + 1; + + default: + a->state -= 1; // map state [2..] to [1..] (skip state 0) + r = srvp9sk1(a, msg, len, resp, resplen); + a->state += 1; + return r; + } +} + + +int +authp9any(Npcfid *afid, Npuser *user, void *aux) +{ + char buf[128], *p, *word, *proto, *dom; + int (*found)(Npcfid *afid, Npuser *user, void *aux); + int v2, i; + + if(getline0(afid, buf, sizeof buf) <= 0) + return err("botch", EINVAL); + + p = buf; + found = 0; + v2 = 0; + if(strncmp(p, "v.2 ", 4) == 0) { + v2 = 1; + p += 4; + } + while(*p && !found) { + if(getWord(&p, ' ', &word) == -1 + || getWord(&word, '@', &proto) == -1 + || getWord(&word, 0, &dom) == -1) + return err("botch", EINVAL); + for(i = 0; authprotos[i].name; i++) { + if(strcmp(authprotos[i].name, "p9sk1") == 0) { + found = authprotos[i].auth; + break; + } + } + } + if(!found) + return err("unsupported", EPROTONOSUPPORT); + + if(putline0(afid, "%s %s", proto, dom) <= 0) + return err("botch", EINVAL); + + if(v2) { + if(getline0(afid, buf, sizeof buf) <= 0) + return err("botch", EINVAL); + if(strcmp(buf, "OK") != 0) + return err("botch", EINVAL); + } + return found(afid, user, aux); +} + Added: npfs/trunk/libnpauth/p9sk1.c =================================================================== --- npfs/trunk/libnpauth/p9sk1.c (rev 0) +++ npfs/trunk/libnpauth/p9sk1.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,174 @@ + +#include <stdio.h> +#include <string.h> +#ifdef _WIN32 + #include <ws2tcpip.h> +#else + #include <unistd.h> + #include <sys/types.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <netdb.h> +#endif +#include <errno.h> +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "npaimpl.h" + +static int +con(struct addrinfo *srv) +{ + int s; + + s = socket(srv->ai_family, srv->ai_socktype, 0); + if(s == -1) + return -1; + if (connect(s, srv->ai_addr, sizeof(*srv->ai_addr)) < 0) { + close(s); + return -1; + } + return s; +} + +static int +getTicket(Npcauth *auth, struct ticketreq *treq, char ctick[72], char stick[72]) +{ + char treqbuf[141]; + int fd; + char type; + + fd = con(auth->srv); + if(fd == -1) + return err("cant reach auth", EPERM); + + // XXX do we need to handle other type replies? + if(encTicketReq(treqbuf, treq) == -1 + || send(fd, treqbuf, sizeof treqbuf, 0) != sizeof treqbuf + || recv(fd, &type, 1, 0) != 1 + || type != AuthOK + || recv(fd, ctick, 72, 0) != 72 + || recv(fd, stick, 72, 0) != 72) { + close(fd); + return err("botch", EINVAL); + } + close(fd); + return 0; +} + +int +srvp9sk1(struct npsrvauth *a, char *msg, int len, char *resp, int resplen) +{ + struct ticketreq treq; + struct auth auth; + struct ticket tick; + + switch(a->state) { + case 0: + // state 0 is reserved for cases where server speaks first + if(len != 0) + return err("botch", EINVAL); + a->state++; + return 0; + + case 1: + if(len != 8) + return err("botch", EINVAL); + memcpy(a->chc, msg, 8); + getRand(a->chs, 8); + + treq.type = AuthTreq; + treq.ids = a->ids; + treq.dom = a->dom; + treq.ch = a->chs; + treq.idc = ""; + treq.idr = ""; + if(resplen < 141 + || encTicketReq(resp, &treq) == -1) + return err("internal error", EINVAL); + a->state++; + return 141; + + case 2: + if(len != 85) + return err("botch", EINVAL); + if(decTicket(msg, &tick, a->key) == -1 + || tick.type != AuthTs + || memcmp(tick.ch, a->chs, 8) != 0 + || decAuth(msg+72, &auth, tick.key) == -1 + || auth.type != AuthAc + || memcmp(auth.ch, a->chs, 8) != 0 + || auth.gen != a->gen) + return err("bad auth", EPERM); + + a->idc = strdup(tick.idc); + a->idr = strdup(tick.idr); + auth.type = AuthAs; + memcpy(auth.ch, a->chc, 8); + auth.gen = a->gen; + if(resplen < 13 + || encAuth(resp, &auth, tick.key) == -1) + return err("internal error", EINVAL); + a->state++; + a->done = 1; + return 13; + + default: + return err("botch", EINVAL); + } +} + +int +authp9sk1(Npcfid *afid, Npuser *user, void *aux) +{ + char treqbuf[141], ctickbuf[72], stickbuf[72]; + char authbuf[85], chc[8]; + struct ticketreq treq; + struct ticket ctick; + struct auth auth; + struct npcauth *a = (struct npcauth *)aux; + + // C->S CHc + getRand(chc, 8); + if(put(afid, chc, 8) <= 0) + return err("botch", EINVAL); + + // S->C AuthTreq, IDs, DN, DHs, -, - + if(get(afid, treqbuf, 141) <= 0 + || decTicketReq(treqbuf, &treq) == -1) + return err("botch", EINVAL); + if(treq.type != AuthTreq) + return err("botch", EINVAL); + + // forward ticket request to authserver to get tickets. + treq.idc = user->uname; + treq.idr = user->uname; + if(getTicket(a, &treq, ctickbuf, stickbuf) == -1) + return -1; + if(decTicket(ctickbuf, &ctick, a->key) == -1) + return err("botch", EINVAL); + if(memcmp(treq.ch, ctick.ch, 8) != 0) + return err("bad auth", EPERM); + + // C->S Ks{AuthTs, CHs, IDc, IDr, Kn}, Kn{AuthAc, CHs} + auth.type = AuthAc; + auth.ch = treq.ch; + auth.gen = a->gen; + memcpy(authbuf, stickbuf, 72); + if(encAuth(authbuf+72, &auth, ctick.key) == -1 + || put(afid, authbuf, sizeof authbuf) == -1) + return err("botch", EINVAL); + + // S->C Kn{AuthAs, Chc} + if(get(afid, authbuf, 13) == -1 + || decAuth(authbuf, &auth, ctick.key)) + return err("botch", EINVAL); + if(auth.type != AuthAs + || memcmp(auth.ch, chc, 8) != 0 + || auth.gen != a->gen) + return err("bad server", EPERM); + + a->gen++; + return 0; +} Added: npfs/trunk/libnpauth/sources =================================================================== --- npfs/trunk/libnpauth/sources (rev 0) +++ npfs/trunk/libnpauth/sources 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,16 @@ +TARGETNAME=npauth +TARGETTYPE=LIBRARY + +OPENSSL=c:\openssl +INCLUDES=..\include\;$(OPENSSL)\include + +USE_MSVCRT=1 + +SOURCES=\ + help.c\ + msgs.c\ + p9any.c\ + p9sk1.c\ + srv.c + +UMTYPE=windows Added: npfs/trunk/libnpauth/srv.c =================================================================== --- npfs/trunk/libnpauth/srv.c (rev 0) +++ npfs/trunk/libnpauth/srv.c 2010-01-05 19:32:54 UTC (rev 54) @@ -0,0 +1,132 @@ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include "npfs.h" +#include "npclient.h" +#include "npauth.h" + +#include "npaimpl.h" + +// to be filled in by API client. +char *srvid = "nobody";; +char *srvdom = "@nowhere.com"; +char srvkey[7] = { 0 }; + +typedef int srvfunc(struct npsrvauth *a, char *msg, int len, char *resp, int resplen); + +struct authstate { + struct npsrvauth state; + srvfunc *srv; + char readbuf[256]; + int readcnt; +}; + +struct authstate * +newAuthState(srvfunc *srv) +{ + struct authstate *a; + + a = malloc(sizeof *a); + if(a) { + memset(a, 0, sizeof *a); + a->srv = srv; + a->state.ids = srvid; + a->state.dom = srvdom; + a->state.key = srvkey; + a->readcnt = a->srv(&a->state, NULL, 0, a->readbuf, sizeof a->readbuf); + } + return a; +} + +static int +startp9any(Npfid *afid, char *aname, Npqid *aqid) +{ + afid->aux = newAuthState(srvp9any); + aqid->type = Qtauth; + aqid->version = 0; + aqid->path = 1; + return 1; +} + +static int +startp9sk1(Npfid *afid, char *aname, Npqid *aqid) +{ + afid->aux = newAuthState(srvp9sk1); + return 1; +} + +static int +checkauth(Npfid *fid, Npfid *afid, char *aname) +{ + if(afid) { + struct authstate *a = (struct authstate *)afid->aux; + + if(a->state.done + && strcmp(fid->user->uname, a->state.idr) == 0) + return 1; + } + return err("bad auth", EPERM); +} + +static int +readauth(Npfid *fid, u64 off, u32 cnt, u8 *data) +{ + struct authstate *a = (struct authstate *)fid->aux; + int n; + + if(a->readcnt == 0 || cnt < a->readcnt) + return err("botch", EIO); + n = a->readcnt; + memcpy(data, a->readbuf, n); + a->readcnt = 0; + return n; +} + +static int +writeauth(Npfid *fid, u64 off, u32 cnt, u8 *data) +{ + struct authstate *a = (struct authstate *)fid->aux; + int n; + + if(a->state.done || a->readcnt > 0) + return err("botch", EIO); + n = a->srv(&a->state, (char *)data, cnt, a->readbuf, sizeof a->readbuf); + if(n < 0) + return 0; + a->readcnt = n; + return cnt; +} + +static int +clunkauth(Npfid *fid) +{ + struct authstate *a = (struct authstate *)fid->aux; + + if(a) { + if(a->state.idc) + free(a->state.idc); + if(a->state.idr) + free(a->state.idr); + free(a); + } + fid->aux = NULL; + return 1; +} + +struct Npauth srvauthp9any = { + startp9any, + checkauth, + readauth, + writeauth, + clunkauth +}; + +struct Npauth srvauthp9sk1 = { + startp9sk1, + checkauth, + readauth, + writeauth, + clunkauth +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2010-01-05 18:04:54
|
Revision: 53 http://npfs.svn.sourceforge.net/npfs/?rev=53&view=rev Author: newsham Date: 2010-01-05 18:04:47 +0000 (Tue, 05 Jan 2010) Log Message: ----------- - remove debug assert that shouldn't have been committed Modified Paths: -------------- npfs/trunk/libnpfs/winthread.c Modified: npfs/trunk/libnpfs/winthread.c =================================================================== --- npfs/trunk/libnpfs/winthread.c 2009-12-29 23:56:41 UTC (rev 52) +++ npfs/trunk/libnpfs/winthread.c 2010-01-05 18:04:47 UTC (rev 53) @@ -7,7 +7,6 @@ */ #include <stdlib.h> #include <stdio.h> -#include <assert.h> #include <errno.h> #include <assert.h> #include "npfs.h" @@ -95,7 +94,6 @@ { int x, last; - assert(cond->waiters < 10); pthread_mutex_lock(&cond->lock); cond->waiters++; pthread_mutex_unlock(&cond->lock); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-12-30 01:43:01
|
Revision: 52 http://npfs.svn.sourceforge.net/npfs/?rev=52&view=rev Author: newsham Date: 2009-12-29 23:56:41 +0000 (Tue, 29 Dec 2009) Log Message: ----------- - tiny makefile fix since OSX doesnt like a space after -L option. Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpclient/examples/Makefile Modified: npfs/trunk/libnpclient/examples/Makefile =================================================================== --- npfs/trunk/libnpclient/examples/Makefile 2009-12-29 23:54:54 UTC (rev 51) +++ npfs/trunk/libnpclient/examples/Makefile 2009-12-29 23:56:41 UTC (rev 52) @@ -1,7 +1,7 @@ SYSNAME:=${shell uname} SYSNAME!=uname CFLAGS=-Wall -g -I ../../include -LFLAGS=-L ../../libnpfs -L .. -lnpclient -lnpfs -lpthread +LFLAGS=-L../../libnpfs -L.. -lnpclient -lnpfs -lpthread CMD=\ 9ls\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-12-29 23:55:02
|
Revision: 51 http://npfs.svn.sourceforge.net/npfs/?rev=51&view=rev Author: newsham Date: 2009-12-29 23:54:54 +0000 (Tue, 29 Dec 2009) Log Message: ----------- - use the hint to getaddrinfo to favor a SOCK_STREAM socket Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpclient/netmount.c Modified: npfs/trunk/libnpclient/netmount.c =================================================================== --- npfs/trunk/libnpclient/netmount.c 2009-12-29 21:08:35 UTC (rev 50) +++ npfs/trunk/libnpclient/netmount.c 2009-12-29 23:54:54 UTC (rev 51) @@ -41,6 +41,7 @@ struct addrinfo * npc_netaddr(char *address, int dfltport) { + struct addrinfo hints; int r; char *addr, *name, *p, port[8]; struct addrinfo *addrlist; @@ -61,11 +62,10 @@ else snprintf(port, sizeof(port), "%d", dfltport); - /* they have this cute 'hints' thing you can put in. - * it would be really great if it worked, but it fails in some - * places, so just don't use it. - */ - r = getaddrinfo(name, port, NULL, &addrlist); + memset(&hints, 0, sizeof hints); + hints.ai_family = PF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + r = getaddrinfo(name, port, &hints, &addrlist); if (r) np_werror("cannot resolve name", EIO); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-12-29 21:08:46
|
Revision: 50 http://npfs.svn.sourceforge.net/npfs/?rev=50&view=rev Author: newsham Date: 2009-12-29 21:08:35 +0000 (Tue, 29 Dec 2009) Log Message: ----------- - Add a "dotu" option to the mount command Clients should be able to choose if they want to connect using dotu or not. Also update the npclient examples to the new API change and fixes some minor getopt/usage bugs in those programs. Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/include/npclient.h npfs/trunk/libnpclient/examples/9ls.c npfs/trunk/libnpclient/examples/9read.c npfs/trunk/libnpclient/examples/9write.c npfs/trunk/libnpclient/mount.c npfs/trunk/libnpclient/netmount.c Modified: npfs/trunk/include/npclient.h =================================================================== --- npfs/trunk/include/npclient.h 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/include/npclient.h 2009-12-29 21:08:35 UTC (rev 50) @@ -34,11 +34,11 @@ Npqid qid; }; -Npcfsys* npc_mount(int fd, char *aname, Npuser *user, +Npcfsys* npc_mount(int fd, char *aname, int dotu, Npuser *user, int (*auth)(Npcfid *afid, Npuser *user, void *aux), void *aux); void npc_umount(Npcfsys *fs); struct addrinfo *npc_netaddr(char *address, int dfltport); -Npcfsys * npc_netmount(struct addrinfo *address, Npuser *user, int dfltport, +Npcfsys * npc_netmount(struct addrinfo *address, int dotu, Npuser *user, int dfltport, int (*auth)(Npcfid *afid, Npuser *user, void *aux), void *aux); Npcfid* npc_create(Npcfsys *fs, char *path, u32 perm, int mode); Npcfid* npc_open(Npcfsys *fs, char *path, int mode); Modified: npfs/trunk/libnpclient/examples/9ls.c =================================================================== --- npfs/trunk/libnpclient/examples/9ls.c 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/libnpclient/examples/9ls.c 2009-12-29 21:08:35 UTC (rev 50) @@ -41,7 +41,7 @@ static void usage() { - fprintf(stderr, "9ls -d -p port addr path\n"); + fprintf(stderr, "9ls [-dU] [-p port] [-u user] addr path\n"); exit(1); } @@ -49,7 +49,7 @@ main(int argc, char **argv) { int i, n; - int c, port; + int c, port, dotu; char *addr, *s; char *path; Npuser *user; @@ -71,7 +71,8 @@ } #endif - while ((c = getopt(argc, argv, "dp:")) != -1) { + dotu = 1; + while ((c = getopt(argc, argv, "dp:u:U")) != -1) { switch (c) { case 'd': npc_chatty = 1; @@ -87,6 +88,10 @@ user = np_default_users->uname2user(np_default_users, optarg); break; + case 'U': + dotu = 0; + break; + default: usage(); } @@ -100,8 +105,16 @@ addr = argv[optind]; path = argv[optind+1]; - fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); + 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"); Modified: npfs/trunk/libnpclient/examples/9read.c =================================================================== --- npfs/trunk/libnpclient/examples/9read.c 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/libnpclient/examples/9read.c 2009-12-29 21:08:35 UTC (rev 50) @@ -40,7 +40,7 @@ static void usage() { - fprintf(stderr, "9write -d -p port addr path\n"); + fprintf(stderr, "9read [-dU] [-p port] [-u user] addr path\n"); exit(1); } @@ -48,7 +48,7 @@ main(int argc, char **argv) { int i, n, off; - int c, port; + int c, port, dotu; char *addr, *s; char *path; Npuser *user; @@ -70,7 +70,8 @@ } #endif - while ((c = getopt(argc, argv, "dp:")) != -1) { + dotu = 1; + while ((c = getopt(argc, argv, "dp:u:U")) != -1) { switch (c) { case 'd': npc_chatty = 1; @@ -86,6 +87,10 @@ user = np_default_users->uname2user(np_default_users, optarg); break; + case 'U': + dotu = 0; + break; + default: usage(); } @@ -99,7 +104,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); + fs = npc_netmount(npc_netaddr(addr, port), dotu, user, port, NULL, NULL); fid = npc_open(fs, path, Oread); if (!fid) { Modified: npfs/trunk/libnpclient/examples/9write.c =================================================================== --- npfs/trunk/libnpclient/examples/9write.c 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/libnpclient/examples/9write.c 2009-12-29 21:08:35 UTC (rev 50) @@ -40,7 +40,7 @@ static void usage() { - fprintf(stderr, "9write -d -p port addr path\n"); + fprintf(stderr, "9write [-dU] [-p port] [-u user] addr path\n"); exit(1); } @@ -48,7 +48,7 @@ main(int argc, char **argv) { int i, n, off; - int c, port; + int c, port, dotu; char *addr, *s; char *path; Npuser *user; @@ -70,7 +70,8 @@ } #endif - while ((c = getopt(argc, argv, "dp:")) != -1) { + dotu = 1; + while ((c = getopt(argc, argv, "dp:u:U")) != -1) { switch (c) { case 'd': npc_chatty = 1; @@ -86,6 +87,10 @@ user = np_default_users->uname2user(np_default_users, optarg); break; + case 'U': + dotu = 0; + break; + default: usage(); } @@ -99,7 +104,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); + fs = npc_netmount(npc_netaddr(addr, port), dotu, user, port, NULL, NULL); fid = npc_open(fs, path, Owrite); if (!fid) { Modified: npfs/trunk/libnpclient/mount.c =================================================================== --- npfs/trunk/libnpclient/mount.c 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/libnpclient/mount.c 2009-12-29 21:08:35 UTC (rev 50) @@ -29,7 +29,7 @@ #include "npcimpl.h" Npcfsys* -npc_mount(int fd, char *aname, Npuser *user, +npc_mount(int fd, char *aname, int dotu, Npuser *user, int (*auth)(Npcfid *afid, Npuser *user, void *aux), void *aux) { Npcfsys *fs; @@ -39,7 +39,7 @@ if (!fs) return NULL; - tc = np_create_tversion(8216, "9P2000.u"); + tc = np_create_tversion(8216, dotu ? "9P2000.u" : "9P2000"); if (npc_rpc(fs, tc, &rc) < 0) goto error; Modified: npfs/trunk/libnpclient/netmount.c =================================================================== --- npfs/trunk/libnpclient/netmount.c 2009-12-05 23:51:30 UTC (rev 49) +++ npfs/trunk/libnpclient/netmount.c 2009-12-29 21:08:35 UTC (rev 50) @@ -76,7 +76,7 @@ Npcfsys * -npc_netmount(struct addrinfo *addrlist, Npuser *user, int dfltport, +npc_netmount(struct addrinfo *addrlist, int dotu, Npuser *user, int dfltport, int (*auth)(Npcfid *afid, Npuser *user, void *aux), void *aux) { char *s; @@ -105,7 +105,7 @@ goto error; } - return npc_mount(fd, NULL, user, auth, aux); + return npc_mount(fd, NULL, dotu, user, auth, aux); error: return NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-12-05 23:51:36
|
Revision: 49 http://npfs.svn.sourceforge.net/npfs/?rev=49&view=rev Author: abbyz9 Date: 2009-12-05 23:51:30 +0000 (Sat, 05 Dec 2009) Log Message: ----------- addrlist is NULL when getaddrinfo fails. so we simply check before using it. using gai_strerror() to get the actual error string would be good, but it doesn't look to be thread-safe. Signed-off-by: Abhishek Kulkarni <adk...@um...> Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpclient/netmount.c Modified: npfs/trunk/libnpclient/netmount.c =================================================================== --- npfs/trunk/libnpclient/netmount.c 2009-11-20 18:39:31 UTC (rev 48) +++ npfs/trunk/libnpclient/netmount.c 2009-12-05 23:51:30 UTC (rev 49) @@ -83,6 +83,9 @@ int fd; char ename[32]; + if (!addrlist) + goto error; + fd = socket(addrlist->ai_family, addrlist->ai_socktype, 0); if (fd < 0) { np_uerror(errno); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-20 18:39:40
|
Revision: 48 http://npfs.svn.sourceforge.net/npfs/?rev=48&view=rev Author: newsham Date: 2009-11-20 18:39:31 +0000 (Fri, 20 Nov 2009) Log Message: ----------- fixes a crash during attach when no auth is requested. It looks like code was put into the wrong branch of an if/else. Approved: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpfs/fcall.c Modified: npfs/trunk/libnpfs/fcall.c =================================================================== --- npfs/trunk/libnpfs/fcall.c 2009-11-20 18:38:48 UTC (rev 47) +++ npfs/trunk/libnpfs/fcall.c 2009-11-20 18:39:31 UTC (rev 48) @@ -165,13 +165,13 @@ np_werror(Eunknownfid, EIO); goto done; } - + } else { if (!afid->type&Qtauth) { np_werror(Ebadusefid, EIO); goto done; } - } else np_fid_incref(afid); + } if (tc->uname.len && tc->n_uname==~0) { uname = np_strdup(&tc->uname); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-20 18:38:55
|
Revision: 47 http://npfs.svn.sourceforge.net/npfs/?rev=47&view=rev Author: newsham Date: 2009-11-20 18:38:48 +0000 (Fri, 20 Nov 2009) Log Message: ----------- fixes some unmarshalling when dotu is not set. Previously it was leaving the optional fields uninitialized, and they are still referenced elsewhere. Patch just initializes them to the default values. Approved: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpfs/np.c Modified: npfs/trunk/libnpfs/np.c =================================================================== --- npfs/trunk/libnpfs/np.c 2009-11-20 18:37:58 UTC (rev 46) +++ npfs/trunk/libnpfs/np.c 2009-11-20 18:38:48 UTC (rev 47) @@ -1054,6 +1054,10 @@ fc->afid = buf_get_int32(bufp); buf_get_str(bufp, &fc->uname); buf_get_str(bufp, &fc->aname); + if(dotu) + fc->n_uname = buf_get_int32(bufp); + else + fc->n_uname = ~0; break; case Rauth: @@ -1069,6 +1073,10 @@ fc->afid = buf_get_int32(bufp); buf_get_str(bufp, &fc->uname); buf_get_str(bufp, &fc->aname); + if(dotu) + fc->n_uname = buf_get_int32(bufp); + else + fc->n_uname = ~0; break; case Rattach: @@ -1080,7 +1088,7 @@ if (dotu) fc->ecode = buf_get_int32(bufp); else - fc->ecode = 0; + fc->ecode = ~0; break; case Twalk: @@ -1121,6 +1129,8 @@ fc->mode = buf_get_int8(bufp); if (dotu) buf_get_str(bufp, &fc->extension); + else + np_strzero(&fc->extension); break; case Tread: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-20 18:38:07
|
Revision: 46 http://npfs.svn.sourceforge.net/npfs/?rev=46&view=rev Author: newsham Date: 2009-11-20 18:37:58 +0000 (Fri, 20 Nov 2009) Log Message: ----------- fixes the user pool I added for win32 so that looking up the same user returns the same object. This is necessary since the code relies on pointer equality for tests. Approved: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/libnpfs/simpleusers.c Modified: npfs/trunk/libnpfs/simpleusers.c =================================================================== --- npfs/trunk/libnpfs/simpleusers.c 2009-11-05 21:47:26 UTC (rev 45) +++ npfs/trunk/libnpfs/simpleusers.c 2009-11-20 18:37:58 UTC (rev 46) @@ -3,24 +3,45 @@ #include "npfs.h" #include "npfsimpl.h" +static struct Npusercache { + pthread_mutex_t lock; + Npuser* users; +} usercache = { PTHREAD_MUTEX_INITIALIZER, 0 }; + +static struct Npgroupcache { + pthread_mutex_t lock; + Npgroup* groups; +} groupcache = { PTHREAD_MUTEX_INITIALIZER, 0 }; + static Npuser * np_simpl_uname2user(Npuserpool *up, char *uname) { Npuser *u; - u = np_malloc(sizeof(*u) + strlen(uname) + 1); - pthread_mutex_init(&u->lock, NULL); - u->refcount = 1; - u->upool = up; - u->uid = -1; - u->uname = (char *)u + sizeof(*u); - strcpy(u->uname, uname); - u->dfltgroup = NULL; - u->ngroups = 0; - u->groups = NULL; - u->next = NULL; - u->dfltgroup = (*up->gname2group)(up, uname); + pthread_mutex_lock(&usercache.lock); + for(u = usercache.users; u; u = u->next) { + if(strcmp(u->uname, uname) == 0) + break; + } + if(!u) { + u = np_malloc(sizeof(*u) + strlen(uname) + 1); + pthread_mutex_init(&u->lock, NULL); + u->refcount = 1; + u->upool = up; + u->uid = -1; + u->uname = (char *)u + sizeof(*u); + strcpy(u->uname, uname); + u->dfltgroup = NULL; + u->ngroups = 0; + u->groups = NULL; + u->next = NULL; + u->dfltgroup = (*up->gname2group)(up, uname); + + u->next = usercache.users; + usercache.users = u; + } np_user_incref(u); + pthread_mutex_unlock(&usercache.lock); return u; } @@ -35,15 +56,26 @@ { Npgroup *g; - g = np_malloc(sizeof(*g) + strlen(gname) + 1); - pthread_mutex_init(&g->lock, NULL); - g->refcount = 1; - g->upool = up; - g->gid = -1; - g->gname = (char *)g + sizeof(*g); - strcpy(g->gname, gname); - g->next = NULL; + pthread_mutex_lock(&groupcache.lock); + for(g = groupcache.groups; g; g = g->next) { + if(strcmp(g->gname, gname) == 0) + break; + } + + if(!g) { + g = np_malloc(sizeof(*g) + strlen(gname) + 1); + pthread_mutex_init(&g->lock, NULL); + g->refcount = 1; + g->upool = up; + g->gid = -1; + g->gname = (char *)g + sizeof(*g); + strcpy(g->gname, gname); + + g->next = groupcache.groups; + groupcache.groups = g; + } np_group_incref(g); + pthread_mutex_unlock(&groupcache.lock); return g; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-04 18:50:47
|
Revision: 43 http://npfs.svn.sourceforge.net/npfs/?rev=43&view=rev Author: newsham Date: 2009-11-04 18:50:33 +0000 (Wed, 04 Nov 2009) Log Message: ----------- - Add win32 support to the npfs tree Tested to compile and run on WinXP and linux. lots of headers juggled so this should probably be tested on other platforms soon. Win32 build: cd libnpfs; nmake /f ntmakefile cd ../libnpclient; nmake /f ntmakefile cd examples; nmake /f ntmakefile Still has some rough edges that need addressing, marked as XXX. Acked-by: Latchesar Ionkov Modified Paths: -------------- npfs/trunk/fs/echofs.c npfs/trunk/fs/nullfs.c npfs/trunk/fs/ramfs.c npfs/trunk/fs/ramfs2.c npfs/trunk/include/npfs.h npfs/trunk/libnpclient/dirread.c npfs/trunk/libnpclient/examples/9ls.c npfs/trunk/libnpclient/examples/9read.c npfs/trunk/libnpclient/examples/9write.c npfs/trunk/libnpclient/fid.c npfs/trunk/libnpclient/fsys.c npfs/trunk/libnpclient/mount.c npfs/trunk/libnpclient/netmount.c npfs/trunk/libnpclient/open.c npfs/trunk/libnpclient/pool.c npfs/trunk/libnpclient/read.c npfs/trunk/libnpclient/remove.c npfs/trunk/libnpclient/stat.c npfs/trunk/libnpclient/stat2wstat.c npfs/trunk/libnpclient/walk.c npfs/trunk/libnpclient/write.c npfs/trunk/libnpfs/conn.c npfs/trunk/libnpfs/error.c npfs/trunk/libnpfs/fcall.c npfs/trunk/libnpfs/fdtrans.c npfs/trunk/libnpfs/fidpool.c npfs/trunk/libnpfs/file.c npfs/trunk/libnpfs/fmt.c npfs/trunk/libnpfs/np.c npfs/trunk/libnpfs/npfsimpl.h npfs/trunk/libnpfs/pipesrv.c npfs/trunk/libnpfs/pvusers.c npfs/trunk/libnpfs/rdmasrv.c npfs/trunk/libnpfs/rdmatrans.c npfs/trunk/libnpfs/socksrv.c npfs/trunk/libnpfs/srv.c npfs/trunk/libnpfs/trans.c npfs/trunk/libnpfs/user.c npfs/trunk/libnpfs/uxusers.c Added Paths: ----------- npfs/trunk/include/winthread.h npfs/trunk/libnpclient/examples/ntmakefile npfs/trunk/libnpclient/examples/sources npfs/trunk/libnpclient/examples/winhelp.c npfs/trunk/libnpclient/ntmakefile npfs/trunk/libnpclient/sources npfs/trunk/libnpfs/ntmakefile npfs/trunk/libnpfs/simpleusers.c npfs/trunk/libnpfs/sources npfs/trunk/libnpfs/winthread.c Modified: npfs/trunk/fs/echofs.c =================================================================== --- npfs/trunk/fs/echofs.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/fs/echofs.c 2009-11-04 18:50:33 UTC (rev 43) @@ -78,7 +78,7 @@ debuglevel = 0; nwthreads = 16; - user = np_unix_users->uid2user(np_unix_users, getuid()); + user = np_default_users->uid2user(np_default_users, getuid()); while ((c = getopt(argc, argv, "dw:")) != -1) { switch (c) { case 'd': Modified: npfs/trunk/fs/nullfs.c =================================================================== --- npfs/trunk/fs/nullfs.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/fs/nullfs.c 2009-11-04 18:50:33 UTC (rev 43) @@ -69,7 +69,7 @@ debuglevel = 0; nwthreads = 16; - user = np_unix_users->uid2user(np_unix_users, getuid()); + user = np_default_users->uid2user(np_default_users, getuid()); while ((c = getopt(argc, argv, "dw:")) != -1) { switch (c) { case 'd': Modified: npfs/trunk/fs/ramfs.c =================================================================== --- npfs/trunk/fs/ramfs.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/fs/ramfs.c 2009-11-04 18:50:33 UTC (rev 43) @@ -879,7 +879,7 @@ nwthreads = 4; opts = ""; logfile = "/tmp/ramfs.log"; - user = np_unix_users->uid2user(np_unix_users, getuid()); + user = np_default_users->uid2user(np_default_users, getuid()); while ((c = getopt(argc, argv, "du:w:b:o:l:")) != -1) { switch (c) { case 'd': @@ -887,7 +887,7 @@ break; case 'u': - user = np_unix_users->uname2user(np_unix_users, optarg); + user = np_default_users->uname2user(np_default_users, optarg); break; case 'b': Modified: npfs/trunk/fs/ramfs2.c =================================================================== --- npfs/trunk/fs/ramfs2.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/fs/ramfs2.c 2009-11-04 18:50:33 UTC (rev 43) @@ -99,7 +99,7 @@ nwthreads = 1; opts = ""; logfile = "/tmp/ramfs.log"; - user = np_unix_users->uid2user(np_unix_users, getuid()); + user = np_default_users->uid2user(np_default_users, getuid()); while ((c = getopt(argc, argv, "du:w:b:o:l:")) != -1) { switch (c) { case 'd': @@ -107,7 +107,7 @@ break; case 'u': - user = np_unix_users->uname2user(np_unix_users, optarg); + user = np_default_users->uname2user(np_default_users, optarg); break; case 'b': Modified: npfs/trunk/include/npfs.h =================================================================== --- npfs/trunk/include/npfs.h 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/include/npfs.h 2009-11-04 18:50:33 UTC (rev 43) @@ -21,13 +21,43 @@ * DEALINGS IN THE SOFTWARE. */ -#include <sys/types.h> -#include <stdint.h> +#ifdef _WIN32 + #include <windows.h> + #include <winsock2.h> + #include "winthread.h" + #define inline + #define snprintf _snprintf + #define vsnprintf _vsnprintf + #define strdup _strdup + static int close(SOCKET s) { return closesocket(s); } + static int read(SOCKET s, char *buf, int len) { return recv(s, buf, len, 0); } + static int write(SOCKET s, char *buf, int len) { return send(s, buf, len, 0); } + static void sleep(DWORD val) { Sleep(val * 1000); } -typedef uint8_t u8; -typedef uint16_t u16; -typedef uint32_t u32; -typedef uint64_t u64; + typedef UINT8 u8; + typedef UINT16 u16; + typedef UINT32 u32; + typedef UINT64 u64; + typedef UINT32 uid_t; // XXX + typedef UINT32 gid_t; + typedef int socklen_t; + + enum { + ECONNABORTED = 53, + }; + +#else // !_WIN32 + #include <pthread.h> + #include <sys/types.h> + #include <stdint.h> + + typedef uint8_t u8; + typedef uint16_t u16; + typedef uint32_t u32; + typedef uint64_t u64; +#endif + + typedef struct Npstr Npstr; typedef struct Npqid Npqid; typedef struct Npstat Npstat; @@ -484,7 +514,7 @@ extern char *Eexist; extern char *Enotempty; extern char *Eunknownuser; -extern Npuserpool *np_unix_users; +extern Npuserpool *np_default_users; Npsrv *np_srv_create(int nwthread); void np_srv_remove_conn(Npsrv *, Npconn *); Added: npfs/trunk/include/winthread.h =================================================================== --- npfs/trunk/include/winthread.h (rev 0) +++ npfs/trunk/include/winthread.h 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,53 @@ +typedef PVOID pthread_attr_t; +typedef PVOID pthread_mutexattr_t; +typedef PVOID pthread_condattr_t; +typedef struct { + INT init; + HANDLE handle; +} pthread_mutex_t; +#define PTHREAD_MUTEX_INITIALIZER { 0 } + +typedef struct { + UINT waiters; + INT broadcast; + pthread_mutex_t lock; + HANDLE queue; + HANDLE done; +} pthread_cond_t; + +typedef struct { + INT detached; + HANDLE handle; + void *(*run)(void *); + void *arg; + PVOID retval; +} *pthread_t; + +typedef struct { + UINT init; +} pthread_once_t; +#define PTHREAD_ONCE_INIT {0} + +typedef struct { + DWORD tlsidx; + void (*destroy)(void*); +} pthread_key_t; + +int pthread_mutex_init(pthread_mutex_t *mux, const pthread_mutexattr_t *dummy); +int pthread_mutex_destroy(pthread_mutex_t *mux); +int pthread_mutex_lock(pthread_mutex_t *mux); +int pthread_mutex_unlock(pthread_mutex_t *mux); +int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *dummy); +int pthread_cond_destroy(pthread_cond_t *cond); +int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mux); +int pthread_cond_signal(pthread_cond_t *cond); +int pthread_cond_broadcast(pthread_cond_t *cond); +int pthread_create(pthread_t *thr, const pthread_attr_t *dummy, void *(*run)(void*), void *arg); +int pthread_join(pthread_t thr, void **retval); +int pthread_detach(pthread_t dummy); +int pthread_once(pthread_once_t *once, void (*func)(void)); +int pthread_key_create(pthread_key_t *key, void (*destroy)(void*)); +void * pthread_getspecific(pthread_key_t key); +int pthread_setspecific(pthread_key_t key, const void *val); +pthread_t pthread_self(void); + Modified: npfs/trunk/libnpclient/dirread.c =================================================================== --- npfs/trunk/libnpclient/dirread.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/dirread.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> +#ifndef _WIN32 + #include <unistd.h> +#endif #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/examples/9ls.c =================================================================== --- npfs/trunk/libnpclient/examples/9ls.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/examples/9ls.c 2009-11-04 18:50:33 UTC (rev 43) @@ -24,18 +24,18 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <fcntl.h> #include <assert.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - #include "npfs.h" #include "npclient.h" +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #define __cdecl +#endif + extern int npc_chatty; static void @@ -45,7 +45,7 @@ exit(1); } -int +int __cdecl main(int argc, char **argv) { int i, n; @@ -60,11 +60,16 @@ port = 564; // npc_chatty = 1; - user = np_unix_users->uid2user(np_unix_users, geteuid()); +#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, "dp:")) != -1) { switch (c) { @@ -79,7 +84,7 @@ break; case 'u': - user = np_unix_users->uname2user(np_unix_users, optarg); + user = np_default_users->uname2user(np_default_users, optarg); break; default: Modified: npfs/trunk/libnpclient/examples/9read.c =================================================================== --- npfs/trunk/libnpclient/examples/9read.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/examples/9read.c 2009-11-04 18:50:33 UTC (rev 43) @@ -24,17 +24,16 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <fcntl.h> #include <assert.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - #include "npfs.h" #include "npclient.h" +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #define __cdecl +#endif extern int npc_chatty; @@ -45,7 +44,7 @@ exit(1); } -int +int __cdecl main(int argc, char **argv) { int i, n, off; @@ -60,11 +59,16 @@ port = 564; // npc_chatty = 1; - user = np_unix_users->uid2user(np_unix_users, geteuid()); +#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, "dp:")) != -1) { switch (c) { @@ -79,7 +83,7 @@ break; case 'u': - user = np_unix_users->uname2user(np_unix_users, optarg); + user = np_default_users->uname2user(np_default_users, optarg); break; default: @@ -105,7 +109,7 @@ off = 0; while ((n = npc_read(fid, (u8*) buf, sizeof(buf), off)) > 0) { - i = write(1, buf, n); + i = fwrite(buf, 1, n, stdout); if (i != n) { fprintf(stderr, "error writing\n"); exit(1); Modified: npfs/trunk/libnpclient/examples/9write.c =================================================================== --- npfs/trunk/libnpclient/examples/9write.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/examples/9write.c 2009-11-04 18:50:33 UTC (rev 43) @@ -24,17 +24,16 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <fcntl.h> #include <assert.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - #include "npfs.h" #include "npclient.h" +#ifdef _WIN32 + #include "winhelp.c" +#else + #include <unistd.h> + #define __cdecl +#endif extern int npc_chatty; @@ -60,11 +59,16 @@ port = 564; // npc_chatty = 1; - user = np_unix_users->uid2user(np_unix_users, geteuid()); +#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, "dp:")) != -1) { switch (c) { @@ -79,7 +83,7 @@ break; case 'u': - user = np_unix_users->uname2user(np_unix_users, optarg); + user = np_default_users->uname2user(np_default_users, optarg); break; default: @@ -107,7 +111,7 @@ } off = 0; - while ((n = read(0, buf, sizeof(buf))) > 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"); Added: npfs/trunk/libnpclient/examples/ntmakefile =================================================================== --- npfs/trunk/libnpclient/examples/ntmakefile (rev 0) +++ npfs/trunk/libnpclient/examples/ntmakefile 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Added: npfs/trunk/libnpclient/examples/sources =================================================================== --- npfs/trunk/libnpclient/examples/sources (rev 0) +++ npfs/trunk/libnpclient/examples/sources 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,24 @@ +TARGETTYPE=PROGRAM + +INCLUDES=..\..\include +LINKLIBS=\ + ..\..\libnpclient\$(O)\npclient.lib \ + ..\..\libnpfs\$(O)\npfs.lib \ + $(SDK_LIB_PATH)\ws2_32.lib + +USE_MSVCRT=1 + +# ----- pick one ----- + +TARGETNAME=9ls +SOURCES=9ls.c winhelp.c + +#TARGETNAME=9read +#SOURCES=9read.c winhelp.c + +#TARGETNAME=9write +#SOURCES=9write.c winhelp.c + + +UMTYPE=console +UMBASE=0x400000 Added: npfs/trunk/libnpclient/examples/winhelp.c =================================================================== --- npfs/trunk/libnpclient/examples/winhelp.c (rev 0) +++ npfs/trunk/libnpclient/examples/winhelp.c 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,47 @@ +#include <windows.h> +#include <winsock2.h> +#include <string.h> + +static int optind = 1; +static int optpos = 0; +static char *optarg = NULL; + +static int +getopt(int argc, char **argv, const char *opts) +{ + char *p, ch; + + if(optind >= argc || !argv[optind]) + return -1; + if(optpos && !argv[optind][optpos]) { + optind ++; + optpos = 0; + } + if(optind >= argc || !argv[optind]) + return -1; + if(optpos == 0 && argv[optind][optpos++] != '-') + return -1; + ch = argv[optind][optpos++]; + p = strchr(opts, ch); + if(!p) + return '?'; + if(p[1] != ':') + return ch; + + optarg = argv[optind++] + optpos; + optpos = 0; + if(*optarg) + return ch; + if(optind >= argc || !argv[optind]) + return '?'; + optarg = argv[optind++]; + return ch; +} + +static void +init() { + WSADATA wsData; + + WSAStartup(MAKEWORD(2,2), &wsData); +} + Modified: npfs/trunk/libnpclient/fid.c =================================================================== --- npfs/trunk/libnpclient/fid.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/fid.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/fsys.c =================================================================== --- npfs/trunk/libnpclient/fsys.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/fsys.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,11 +23,12 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <sys/socket.h> #include <assert.h> +#ifndef _WIN32 + #include <unistd.h> + #include <sys/socket.h> +#endif #include "npfs.h" #include "npclient.h" #include "npcimpl.h" Modified: npfs/trunk/libnpclient/mount.c =================================================================== --- npfs/trunk/libnpclient/mount.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/mount.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,10 +23,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <sys/socket.h> #include "npfs.h" #include "npclient.h" #include "npcimpl.h" Modified: npfs/trunk/libnpclient/netmount.c =================================================================== --- npfs/trunk/libnpclient/netmount.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/netmount.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,14 +23,17 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <arpa/inet.h> - +#ifndef _WIN32 + #include <unistd.h> + #include <sys/socket.h> + #include <netinet/in.h> + #include <netdb.h> + #include <arpa/inet.h> +#else + #include <ws2tcpip.h> +#endif +#include <assert.h> #include "npfs.h" #include "npclient.h" #include "npcimpl.h" @@ -88,7 +91,11 @@ if (connect(fd, addrlist->ai_addr, sizeof(*addrlist->ai_addr)) < 0) { /* real computers have errstr */ +#ifdef _WIN32 + snprintf(ename, sizeof ename, "connect error"); // XXX +#else // !_WIN32 strerror_r(errno, ename, sizeof(ename)); +#endif s = inet_ntoa(*(struct in_addr*) addrlist->ai_addr); np_werror("%s:%s", errno, s, ename); close(fd); Added: npfs/trunk/libnpclient/ntmakefile =================================================================== --- npfs/trunk/libnpclient/ntmakefile (rev 0) +++ npfs/trunk/libnpclient/ntmakefile 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Modified: npfs/trunk/libnpclient/open.c =================================================================== --- npfs/trunk/libnpclient/open.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/open.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/pool.c =================================================================== --- npfs/trunk/libnpclient/pool.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/pool.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/read.c =================================================================== --- npfs/trunk/libnpclient/read.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/read.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/remove.c =================================================================== --- npfs/trunk/libnpclient/remove.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/remove.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Added: npfs/trunk/libnpclient/sources =================================================================== --- npfs/trunk/libnpclient/sources (rev 0) +++ npfs/trunk/libnpclient/sources 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,23 @@ +TARGETNAME=npclient +TARGETTYPE=LIBRARY + +INCLUDES=..\include\ + +USE_MSVCRT=1 + +SOURCES=\ + dirread.c\ + fid.c\ + fsys.c\ + mount.c\ + netmount.c\ + open.c\ + pool.c\ + read.c\ + remove.c\ + stat.c\ + stat2wstat.c\ + walk.c\ + write.c + +UMTYPE=windows Modified: npfs/trunk/libnpclient/stat.c =================================================================== --- npfs/trunk/libnpclient/stat.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/stat.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/stat2wstat.c =================================================================== --- npfs/trunk/libnpclient/stat2wstat.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/stat2wstat.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/walk.c =================================================================== --- npfs/trunk/libnpclient/walk.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/walk.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpclient/write.c =================================================================== --- npfs/trunk/libnpclient/write.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpclient/write.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,8 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npclient.h" Modified: npfs/trunk/libnpfs/conn.c =================================================================== --- npfs/trunk/libnpfs/conn.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/conn.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include <assert.h> #include "npfs.h" Modified: npfs/trunk/libnpfs/error.c =================================================================== --- npfs/trunk/libnpfs/error.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/error.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include <stdarg.h> #include "npfs.h" @@ -60,7 +59,7 @@ } static void -np_init_error_key() +np_init_error_key(void) { pthread_key_create(&error_key, np_destroy_error); } @@ -140,9 +139,32 @@ return 0; } +#ifdef _WIN32 void np_uerror(int ecode) { + char buf[100]; + + // XXX? + snprintf(buf, sizeof buf, "error %d\n", ecode); + np_werror(buf, ecode); +} + +void +np_suerror(char *s, int ecode) +{ + char buf[512]; + + // XXX? + snprintf(buf, sizeof buf, "error %d\n", ecode); + snprintf(buf, sizeof(buf), "%s: error %d", s, ecode); + np_werror(buf, ecode); +} + +#else // !_WIN32 +void +np_uerror(int ecode) +{ char buf[256]; strerror_r(ecode, buf, sizeof(buf)); @@ -159,3 +181,4 @@ snprintf(buf, sizeof(buf), "%s: %s", s, err); np_werror(buf, ecode); } +#endif Modified: npfs/trunk/libnpfs/fcall.c =================================================================== --- npfs/trunk/libnpfs/fcall.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/fcall.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include <assert.h> #include "npfs.h" Modified: npfs/trunk/libnpfs/fdtrans.c =================================================================== --- npfs/trunk/libnpfs/fdtrans.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/fdtrans.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,10 +23,9 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/poll.h> -#include <pthread.h> +#ifndef _WIN32 + #include <unistd.h> +#endif #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/fidpool.c =================================================================== --- npfs/trunk/libnpfs/fidpool.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/fidpool.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/file.c =================================================================== --- npfs/trunk/libnpfs/file.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/file.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,10 +23,10 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include <assert.h> #include <limits.h> +#include <time.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/fmt.c =================================================================== --- npfs/trunk/libnpfs/fmt.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/fmt.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npfsimpl.h" @@ -79,7 +78,11 @@ buf[n++] = 'L'; buf[n] = '\0'; +#ifdef _WIN32 + return fprintf(f, " (%.16I64x %x '%s')", (unsigned long long)q->path, q->version, buf); +#else return fprintf(f, " (%.16llx %x '%s')", (unsigned long long)q->path, q->version, buf); +#endif } int @@ -94,8 +97,13 @@ n += np_printqid(f, &st->qid); n += fprintf(f, " m "); n += np_printperm(f, st->mode); +#ifdef _WIN32 + n += fprintf(f, " at %d mt %d l %I64u t %d d %d", + st->atime, st->mtime, (unsigned long long)st->length, st->type, st->dev); +#else n += fprintf(f, " at %d mt %d l %llu t %d d %d", st->atime, st->mtime, (unsigned long long)st->length, st->type, st->dev); +#endif if (dotu) n += fprintf(f, " ext '%.*s'", st->extension.len, st->extension.str); @@ -238,8 +246,13 @@ break; case Tread: +#ifdef _WIN32 + ret += fprintf(f, "Tread tag %u fid %d offset %I64u count %u", + tag, fid, (unsigned long long)fc->offset, fc->count); +#else ret += fprintf(f, "Tread tag %u fid %d offset %llu count %u", tag, fid, (unsigned long long)fc->offset, fc->count); +#endif break; case Rread: @@ -248,8 +261,13 @@ break; case Twrite: +#ifdef _WIN32 + ret += fprintf(f, "Twrite tag %u fid %d offset %I64u count %u data ", + tag, fid, (unsigned long long)fc->offset, fc->count); +#else ret += fprintf(f, "Twrite tag %u fid %d offset %llu count %u data ", tag, fid, (unsigned long long)fc->offset, fc->count); +#endif ret += np_printdata(f, fc->data, fc->count); break; Modified: npfs/trunk/libnpfs/np.c =================================================================== --- npfs/trunk/libnpfs/np.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/np.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <pthread.h> #include <errno.h> #include <assert.h> #include "npfs.h" @@ -39,7 +38,7 @@ buf_init(struct cbuf *buf, void *data, int datalen) { buf->sp = buf->p = data; - buf->ep = data + datalen; + buf->ep = (char*)data + datalen; } static inline int Modified: npfs/trunk/libnpfs/npfsimpl.h =================================================================== --- npfs/trunk/libnpfs/npfsimpl.h 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/npfsimpl.h 2009-11-04 18:50:33 UTC (rev 43) @@ -21,7 +21,7 @@ * DEALINGS IN THE SOFTWARE. */ -extern Npuserpool *np_unix_users; +extern Npuserpool *np_default_users; /* fcall.c */ Npfcall *np_version(Npreq *req, Npfcall *tc); Added: npfs/trunk/libnpfs/ntmakefile =================================================================== --- npfs/trunk/libnpfs/ntmakefile (rev 0) +++ npfs/trunk/libnpfs/ntmakefile 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,3 @@ +# DO NOT EDIT THIS FILE!!! Edit .\sources. +!INCLUDE $(NTMAKEENV)\makefile.def +C_DEFINES = /DUNICODE Modified: npfs/trunk/libnpfs/pipesrv.c =================================================================== --- npfs/trunk/libnpfs/pipesrv.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/pipesrv.c 2009-11-04 18:50:33 UTC (rev 43) @@ -25,7 +25,6 @@ #include <stdio.h> #include <unistd.h> #include <netinet/in.h> -#include <pthread.h> #include <errno.h> #include <sys/mount.h> #include "npfs.h" Modified: npfs/trunk/libnpfs/pvusers.c =================================================================== --- npfs/trunk/libnpfs/pvusers.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/pvusers.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,12 +23,8 @@ #include <stdlib.h> #include <stdio.h> -#include <unistd.h> #include <string.h> -#include <pwd.h> -#include <grp.h> #include <errno.h> -#include <pthread.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/rdmasrv.c =================================================================== --- npfs/trunk/libnpfs/rdmasrv.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/rdmasrv.c 2009-11-04 18:50:33 UTC (rev 43) @@ -4,7 +4,6 @@ #include <unistd.h> #include <sys/socket.h> #include <netinet/in.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/rdmatrans.c =================================================================== --- npfs/trunk/libnpfs/rdmatrans.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/rdmatrans.c 2009-11-04 18:50:33 UTC (rev 43) @@ -4,7 +4,6 @@ #include <unistd.h> #include <fcntl.h> #include <sys/poll.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Added: npfs/trunk/libnpfs/simpleusers.c =================================================================== --- npfs/trunk/libnpfs/simpleusers.c (rev 0) +++ npfs/trunk/libnpfs/simpleusers.c 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,83 @@ +#include <stdlib.h> +#include <stdio.h> +#include "npfs.h" +#include "npfsimpl.h" + +static Npuser * +np_simpl_uname2user(Npuserpool *up, char *uname) +{ + Npuser *u; + + u = np_malloc(sizeof(*u) + strlen(uname) + 1); + pthread_mutex_init(&u->lock, NULL); + u->refcount = 1; + u->upool = up; + u->uid = -1; + u->uname = (char *)u + sizeof(*u); + strcpy(u->uname, uname); + u->dfltgroup = NULL; + u->ngroups = 0; + u->groups = NULL; + u->next = NULL; + u->dfltgroup = (*up->gname2group)(up, uname); + np_user_incref(u); + return u; +} + +static Npuser * +np_simpl_uid2user(Npuserpool *up, u32 uid) +{ + return NULL; +} + +static Npgroup * +np_simpl_gname2group(Npuserpool *up, char *gname) +{ + Npgroup *g; + + g = np_malloc(sizeof(*g) + strlen(gname) + 1); + pthread_mutex_init(&g->lock, NULL); + g->refcount = 1; + g->upool = up; + g->gid = -1; + g->gname = (char *)g + sizeof(*g); + strcpy(g->gname, gname); + g->next = NULL; + np_group_incref(g); + return g; +} + +static Npgroup * +np_simpl_gid2group(Npuserpool *up, u32 gid) +{ + return NULL; +} + +static int +np_simpl_ismember(Npuserpool *up, Npuser *u, Npgroup *g) +{ + return 0; // XXX something fancier? +} + +static void +np_simpl_udestroy(Npuserpool *up, Npuser *u) +{ +} + +static void +np_simpl_gdestroy(Npuserpool *up, Npgroup *g) +{ +} + +static Npuserpool upool = { + NULL, + np_simpl_uname2user, + np_simpl_uid2user, + np_simpl_gname2group, + np_simpl_gid2group, + np_simpl_ismember, + np_simpl_udestroy, + np_simpl_gdestroy, +}; + +Npuserpool *np_default_users = &upool; Modified: npfs/trunk/libnpfs/socksrv.c =================================================================== --- npfs/trunk/libnpfs/socksrv.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/socksrv.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,10 +23,11 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> -#include <unistd.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <pthread.h> +#ifndef _WIN32 + #include <unistd.h> + #include <sys/socket.h> + #include <netinet/in.h> +#endif #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Added: npfs/trunk/libnpfs/sources =================================================================== --- npfs/trunk/libnpfs/sources (rev 0) +++ npfs/trunk/libnpfs/sources 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,25 @@ +TARGETNAME=npfs +TARGETTYPE=LIBRARY + +INCLUDES=..\include\ + +USE_MSVCRT=1 + +SOURCES=\ + conn.c\ + error.c\ + fcall.c\ + fdtrans.c\ + fidpool.c\ + file.c\ + fmt.c\ + np.c\ + pvusers.c\ + simpleusers.c\ + socksrv.c\ + srv.c\ + trans.c\ + user.c\ + winthread.c + +UMTYPE=windows Modified: npfs/trunk/libnpfs/srv.c =================================================================== --- npfs/trunk/libnpfs/srv.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/srv.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include <assert.h> #include "npfs.h" @@ -90,7 +89,7 @@ srv->remove = np_default_remove; srv->stat = np_default_stat; srv->wstat = np_default_wstat; - srv->upool = np_unix_users; + srv->upool = np_default_users; srv->conns = NULL; srv->reqs_first = NULL; Modified: npfs/trunk/libnpfs/trans.c =================================================================== --- npfs/trunk/libnpfs/trans.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/trans.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,7 +23,6 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> -#include <pthread.h> #include <errno.h> #include "npfs.h" #include "npfsimpl.h" Modified: npfs/trunk/libnpfs/user.c =================================================================== --- npfs/trunk/libnpfs/user.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/user.c 2009-11-04 18:50:33 UTC (rev 43) @@ -23,13 +23,13 @@ #include <stdlib.h> #include <stdio.h> -#include <unistd.h> #include <string.h> -#include <pwd.h> -#include <grp.h> #include <errno.h> -#include <pthread.h> -#include <sys/syscall.h> +#ifndef _WIN32 + #include <unistd.h> + #include <grp.h> + #include <sys/syscall.h> +#endif #include "npfs.h" #include "npfsimpl.h" @@ -101,7 +101,16 @@ free(g); } +#ifdef _WIN32 int +np_change_user(Npuser *u) +{ + np_uerror(EPERM); + return -1; +} + +#else // !_WIN32 +int sreuid(int a, int b) { return syscall(SYS_setreuid, a, b); @@ -144,6 +153,7 @@ np_uerror(errno); return -1; } +#endif Npuser * np_current_user(void) Modified: npfs/trunk/libnpfs/uxusers.c =================================================================== --- npfs/trunk/libnpfs/uxusers.c 2009-11-03 22:14:29 UTC (rev 42) +++ npfs/trunk/libnpfs/uxusers.c 2009-11-04 18:50:33 UTC (rev 43) @@ -28,7 +28,6 @@ #include <pwd.h> #include <grp.h> #include <errno.h> -#include <pthread.h> #include "npfs.h" #include "npfsimpl.h" @@ -51,7 +50,7 @@ .gdestroy = np_unix_gdestroy, }; -Npuserpool *np_unix_users = &upool; +Npuserpool *np_default_users = &upool; static struct Npusercache { pthread_mutex_t lock; Added: npfs/trunk/libnpfs/winthread.c =================================================================== --- npfs/trunk/libnpfs/winthread.c (rev 0) +++ npfs/trunk/libnpfs/winthread.c 2009-11-04 18:50:33 UTC (rev 43) @@ -0,0 +1,263 @@ +/* + * winthread + * Thread portability layer for win32. + * + * condition variables discussed in + * http://www.cs.wustl.edu/~schmidt/win32-cv-1.html + */ +#include <stdlib.h> +#include <stdio.h> +#include <assert.h> +#include <errno.h> +#include <assert.h> +#include "npfs.h" + +enum { + StackSize = 10*4096, // XXX? wild guess.. whats good here? +}; + +int +pthread_mutex_init(pthread_mutex_t *mux, const pthread_mutexattr_t *dummy) +{ + mux->init = 1; + mux->handle = CreateMutex(NULL, FALSE, NULL); + return 0; +} + +int +pthread_mutex_destroy(pthread_mutex_t *mux) +{ + CloseHandle(mux->handle); + return 0; +} + +int +pthread_mutex_lock(pthread_mutex_t *mux) +{ + HANDLE imux; + + if(!mux->init) { + // CreateMutex is atomic and will reopen an existing mutex. + // XXX probably minor security issue here, someone can deadlock us + // by grabbing our lock. + imux = CreateMutex(NULL, FALSE, L"Local\\pthread_mutex_initlock"); + if(!imux) + return EINVAL; + WaitForSingleObject(imux, INFINITE); + if(!mux->init) + pthread_mutex_init(mux, NULL); + ReleaseMutex(imux); + } + WaitForSingleObject(mux->handle, INFINITE); + return 0; +} + +int +pthread_mutex_unlock(pthread_mutex_t *mux) +{ + ReleaseMutex(mux->handle); + return 0; +} + +int +pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *dummy) +{ + assert(!dummy); + cond->waiters = 0; + cond->broadcast = 0; + pthread_mutex_init(&cond->lock, NULL); + cond->queue = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); + if(!cond->queue) + return ENOMEM; + cond->done = CreateEvent(NULL, FALSE, FALSE, NULL); + if(!cond->done) { + CloseHandle(cond->queue); + return ENOMEM; + } + return 0; +} + +int +pthread_cond_destroy(pthread_cond_t *cond) +{ + int busy; + + if(cond->waiters > 0) + return EBUSY; + pthread_mutex_destroy(&cond->lock); + CloseHandle(cond->queue); + CloseHandle(cond->done); + return 0; +} + +int +pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mux) +{ + int x, last; + + assert(cond->waiters < 10); + pthread_mutex_lock(&cond->lock); + cond->waiters++; + pthread_mutex_unlock(&cond->lock); + + // this does a pthread_mutex_unlock on mux + x = SignalObjectAndWait(mux->handle, cond->queue, INFINITE, FALSE); + assert(x == 0); + + pthread_mutex_lock(&cond->lock); + cond->waiters--; + last = cond->broadcast && cond->waiters == 0; + pthread_mutex_unlock(&cond->lock); + + if(last) + SignalObjectAndWait(cond->done, mux->handle, INFINITE, FALSE); + else + pthread_mutex_lock(mux); + return 0; +} + +int +pthread_cond_signal(pthread_cond_t *cond) +{ + int wake; + + pthread_mutex_lock(&cond->lock); + wake = cond->waiters > 0; + pthread_mutex_unlock(&cond->lock); + if(wake) + ReleaseSemaphore(cond->queue, 1, 0); + return 0; +} + +int +pthread_cond_broadcast(pthread_cond_t *cond) +{ + int wake; + + pthread_mutex_lock(&cond->lock); + wake = 0; + if(cond->waiters > 0) { + cond->broadcast = 1; + wake = 1; + } + if(wake) + ReleaseSemaphore(cond->queue, cond->waiters, 0); + pthread_mutex_unlock(&cond->lock); + if(wake) { + WaitForSingleObject(cond->done, INFINITE); + cond->broadcast = 0; + } + return 0; +} + +static pthread_once_t handInit = PTHREAD_ONCE_INIT; +static pthread_key_t handKey; + +static void +init(void) { + pthread_key_create(&handKey, NULL); +} + +static DWORD +trampoline(void *arg) +{ + pthread_t thr = (pthread_t)arg; + pthread_setspecific(handKey, thr); + thr->retval = thr->run(thr->arg); + if(thr->detached) + free(thr); + return 0; +} + + +int +pthread_create(pthread_t *pthr, const pthread_attr_t *dummy, void *(*run)(void*), void *arg) +{ + HANDLE h; + pthread_t thr; + + assert(!dummy); + pthread_once(&handInit, init); + thr = malloc(sizeof *thr); + thr->detached = 0; + thr->arg = arg; + thr->run = run; + h = CreateThread(NULL, StackSize, trampoline, thr, 0, NULL); + if(!h) { + free(thr); + return EAGAIN; + } + thr->handle = h; + *pthr = thr; + return 0; +} + +int +pthread_join(pthread_t thr, void **retval) +{ + if(WaitForSingleObject(thr->handle, INFINITE) != WAIT_OBJECT_0) + return ESRCH; + *retval = thr->retval; + return 0; +} + +int +pthread_detach(pthread_t thr) +{ + thr->detached = 1; + return 0; +} + +pthread_t +pthread_self(void) +{ + return pthread_getspecific(handKey); +} + +int +pthread_once(pthread_once_t *once, void (*func)(void)) +{ + static pthread_mutex_t oncelock = PTHREAD_MUTEX_INITIALIZER; + + if(!once->init) { + pthread_mutex_lock(&oncelock); + if(!once->init) + func(); + once->init = 1; + pthread_mutex_unlock(&oncelock); + } + return 0; +} + +int +pthread_key_create(pthread_key_t *key, void (*destroy)(void*)) +{ + DWORD tlsidx; + + tlsidx = TlsAlloc(); + if(tlsidx == TLS_OUT_OF_INDEXES) + return EAGAIN; + key->tlsidx = tlsidx; + key->destroy = destroy; + return 0; +} + +void * +pthread_getspecific(pthread_key_t key) +{ + return TlsGetValue(key.tlsidx); +} + +int +pthread_setspecific(pthread_key_t key, const void *val) +{ + PVOID old; + + old = pthread_getspecific(key); + if(old) + key.destroy(old); + if(!TlsSetValue(key.tlsidx, (void*)val)) + return EINVAL; + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-03 22:14:38
|
Revision: 42 http://npfs.svn.sourceforge.net/npfs/?rev=42&view=rev Author: newsham Date: 2009-11-03 22:14:29 +0000 (Tue, 03 Nov 2009) Log Message: ----------- - Keep a copy of the QID in the Npcfid Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/include/npclient.h npfs/trunk/libnpclient/mount.c npfs/trunk/libnpclient/walk.c Modified: npfs/trunk/include/npclient.h =================================================================== --- npfs/trunk/include/npclient.h 2009-11-03 22:13:12 UTC (rev 41) +++ npfs/trunk/include/npclient.h 2009-11-03 22:14:29 UTC (rev 42) @@ -31,6 +31,7 @@ Npcfsys* fsys; u32 fid; u64 offset; + Npqid qid; }; Npcfsys* npc_mount(int fd, char *aname, Npuser *user, Modified: npfs/trunk/libnpclient/mount.c =================================================================== --- npfs/trunk/libnpclient/mount.c 2009-11-03 22:13:12 UTC (rev 41) +++ npfs/trunk/libnpclient/mount.c 2009-11-03 22:14:29 UTC (rev 42) @@ -84,6 +84,7 @@ user->uname, aname, user->uid, fs->dotu); if (npc_rpc(fs, tc, &rc) < 0) goto error; + fs->root->qid = rc->qid; free(tc); free(rc); Modified: npfs/trunk/libnpclient/walk.c =================================================================== --- npfs/trunk/libnpclient/walk.c 2009-11-03 22:13:12 UTC (rev 41) +++ npfs/trunk/libnpclient/walk.c 2009-11-03 22:14:29 UTC (rev 42) @@ -47,6 +47,7 @@ fid = npc_fid_alloc(fs); s = fname; nfid = fs->root->fid; + fid->qid = fs->root->qid; while (1) { n = 0; while (n<MAXWELEM && *s!='\0') { @@ -73,6 +74,8 @@ np_werror("file not found", ENOENT); goto error; } + if(n > 0) + fid->qid = rc->wqids[n-1]; free(tc); free(rc); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ne...@us...> - 2009-11-03 22:13:21
|
Revision: 41 http://npfs.svn.sourceforge.net/npfs/?rev=41&view=rev Author: newsham Date: 2009-11-03 22:13:12 +0000 (Tue, 03 Nov 2009) Log Message: ----------- - add npc_wstat call and helper. Acked-by: Latchesar Ionkov <lu...@io...> Modified Paths: -------------- npfs/trunk/include/npclient.h npfs/trunk/libnpclient/stat.c Modified: npfs/trunk/include/npclient.h =================================================================== --- npfs/trunk/include/npclient.h 2009-11-03 20:54:37 UTC (rev 40) +++ npfs/trunk/include/npclient.h 2009-11-03 22:13:12 UTC (rev 41) @@ -47,6 +47,8 @@ int npc_write(Npcfid *fid, u8 *buf, u32 count, u64 offset); int npc_dirread(Npcfid *fid, Npwstat **stat); Npwstat *npc_stat(Npcfsys *fs, char *path); +void npc_emptystat(Npwstat *st); +int npc_wstat(Npcfsys *fs, char *path, Npwstat *st); int npc_readnb(Npcfid *fid, u8 *buf, u32 count, u64 offset, void (*cb)(void *cba, u32 count), void *cba); Modified: npfs/trunk/libnpclient/stat.c =================================================================== --- npfs/trunk/libnpclient/stat.c 2009-11-03 20:54:37 UTC (rev 40) +++ npfs/trunk/libnpclient/stat.c 2009-11-03 22:13:12 UTC (rev 41) @@ -64,3 +64,51 @@ return st; } + +void +npc_emptystat(Npwstat *st) +{ + u64 i64 = 0xffffffffffffffffL; + u32 i32 = 0xffffffff; + u16 i16 = 0xffff; + u8 i8 = 0xff; + + st->size = i16; + st->type = i16; + st->dev = i32; + st->qid.type = i8; + st->qid.version = i32; + st->qid.path = i64; + st->mode = i32; + st->atime = i32; + st->mtime = i32; + st->length = i64; + st->name = ""; + st->uid = ""; + st->muid = ""; + st->n_uid = i32; + st->n_gid = i32; + st->n_muid = i32; +} + +int +npc_wstat(Npcfsys *fs, char *path, Npwstat *st) +{ + Npfcall *tc, *rc; + Npcfid *fid; + + fid = npc_walk(fs, path); + if (!fid) + return 0; + + tc = np_create_twstat(fid->fid, st, fs->dotu); + if (npc_rpc(fs, tc, &rc) < 0) { + free(tc); + npc_close(fid); + return -1; + } + free(rc); + free(tc); + return 0; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2009-11-03 20:54:56
|
Revision: 40 http://npfs.svn.sourceforge.net/npfs/?rev=40&view=rev Author: lionkov Date: 2009-11-03 20:54:37 +0000 (Tue, 03 Nov 2009) Log Message: ----------- One more uninitialized variable. Thanks to Tim Newsham. Modified Paths: -------------- npfs/trunk/libnpclient/write.c Modified: npfs/trunk/libnpclient/write.c =================================================================== --- npfs/trunk/libnpclient/write.c 2009-11-03 20:13:53 UTC (rev 39) +++ npfs/trunk/libnpclient/write.c 2009-11-03 20:54:37 UTC (rev 40) @@ -114,6 +114,7 @@ goto done; nocount = 0; + count = 0; for(i = 0; i < r->nreq; i++) { if (r->calls[i].ename) { np_werror(r->calls[i].ename, r->calls[i].ecode); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2009-11-03 20:14:01
|
Revision: 39 http://npfs.svn.sourceforge.net/npfs/?rev=39&view=rev Author: lionkov Date: 2009-11-03 20:13:53 +0000 (Tue, 03 Nov 2009) Log Message: ----------- fsys->afid left uninitialized. Modified Paths: -------------- npfs/trunk/libnpclient/fsys.c Modified: npfs/trunk/libnpclient/fsys.c =================================================================== --- npfs/trunk/libnpclient/fsys.c 2009-11-03 15:52:23 UTC (rev 38) +++ npfs/trunk/libnpclient/fsys.c 2009-11-03 20:13:53 UTC (rev 39) @@ -72,6 +72,7 @@ fs->msize = msize; fs->trans = NULL; fs->root = NULL; + fs->afid = NULL; fs->tagpool = NULL; fs->fidpool = NULL; fs->unsent_first = NULL; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <li...@us...> - 2009-11-03 15:52:30
|
Revision: 38 http://npfs.svn.sourceforge.net/npfs/?rev=38&view=rev Author: lionkov Date: 2009-11-03 15:52:23 +0000 (Tue, 03 Nov 2009) Log Message: ----------- Various bugfixes suggested by Tim Newsham. Modified Paths: -------------- npfs/trunk/include/npfs.h npfs/trunk/libnpclient/netmount.c npfs/trunk/libnpclient/read.c npfs/trunk/libnpfs/conn.c npfs/trunk/libnpfs/fdtrans.c npfs/trunk/libnpfs/np.c Modified: npfs/trunk/include/npfs.h =================================================================== --- npfs/trunk/include/npfs.h 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/include/npfs.h 2009-11-03 15:52:23 UTC (rev 38) @@ -520,6 +520,7 @@ int np_serialize_stat(Npwstat *wstat, u8* buf, int buflen, int dotu); int np_deserialize_stat(Npstat *stat, u8* buf, int buflen, int dotu); +void np_strzero(Npstr *str); char *np_strdup(Npstr *str); int np_strcmp(Npstr *str, char *cs); int np_strncmp(Npstr *str, char *cs, int len); Modified: npfs/trunk/libnpclient/netmount.c =================================================================== --- npfs/trunk/libnpclient/netmount.c 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/libnpclient/netmount.c 2009-11-03 15:52:23 UTC (rev 38) @@ -38,13 +38,12 @@ struct addrinfo * npc_netaddr(char *address, int dfltport) { - int fd, r; - char *addr, *name, *p, *port; - /* stupid library doesn't set it to NULL if error! */ - struct addrinfo *addrlist = NULL; + int r; + char *addr, *name, *p, port[8]; + struct addrinfo *addrlist; + addrlist = NULL; addr = strdup(address); - port = (char *) malloc(sizeof(char) * 6); if (strncmp(addr, "tcp!", 4) == 0) name = addr + 4; else @@ -54,10 +53,10 @@ if (p) { *p = '\0'; p++; - sprintf(port, "%s", p); + snprintf(port, sizeof(port), "%s", p); } else - sprintf(port, "%d", dfltport); + snprintf(port, sizeof(port), "%d", dfltport); /* they have this cute 'hints' thing you can put in. * it would be really great if it worked, but it fails in some @@ -65,10 +64,10 @@ */ r = getaddrinfo(name, port, NULL, &addrlist); - if (r) { + if (r) np_werror("cannot resolve name", EIO); - close(fd); - } + + free(addr); return addrlist; } Modified: npfs/trunk/libnpclient/read.c =================================================================== --- npfs/trunk/libnpclient/read.c 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/libnpclient/read.c 2009-11-03 15:52:23 UTC (rev 38) @@ -117,6 +117,7 @@ goto done; nocount = 0; + count = 0; for(i = 0; i < r->nreq; i++) { if (r->calls[i].ename) { np_werror(r->calls[i].ename, r->calls[i].ecode); Modified: npfs/trunk/libnpfs/conn.c =================================================================== --- npfs/trunk/libnpfs/conn.c 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/libnpfs/conn.c 2009-11-03 15:52:23 UTC (rev 38) @@ -102,6 +102,8 @@ pthread_mutex_unlock(&conn->lock); pthread_mutex_destroy(&conn->lock); + pthread_cond_destroy(&conn->resetcond); + pthread_cond_destroy(&conn->resetdonecond); free(conn); } Modified: npfs/trunk/libnpfs/fdtrans.c =================================================================== --- npfs/trunk/libnpfs/fdtrans.c 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/libnpfs/fdtrans.c 2009-11-03 15:52:23 UTC (rev 38) @@ -54,16 +54,15 @@ return NULL; //fprintf(stderr, "np_fdtrans_create trans %p fdtrans %p\n", npt, fdt); - fdt->trans = npt; fdt->fdin = fdin; fdt->fdout = fdout; - npt = np_trans_create(fdt, np_fdtrans_read, np_fdtrans_write, np_fdtrans_destroy); if (!npt) { free(fdt); return NULL; } + fdt->trans = npt; return npt; } Modified: npfs/trunk/libnpfs/np.c =================================================================== --- npfs/trunk/libnpfs/np.c 2009-06-04 17:42:18 UTC (rev 37) +++ npfs/trunk/libnpfs/np.c 2009-11-03 15:52:23 UTC (rev 38) @@ -180,7 +180,8 @@ buf_put_int32(bufp, wstat->n_uid, &stat->n_uid); buf_put_int32(bufp, wstat->n_gid, &stat->n_gid); buf_put_int32(bufp, wstat->n_muid, &stat->n_muid); - } + } else + np_strzero(&stat->extension); } static inline u8 @@ -279,7 +280,8 @@ stat->n_uid = buf_get_int32(buf); stat->n_gid = buf_get_int32(buf); stat->n_muid = buf_get_int32(buf); - } + } else + np_strzero(&stat->extension); } static int @@ -312,6 +314,13 @@ return size; } +void +np_strzero(Npstr *str) +{ + str->str = NULL; + str->len = 0; +} + char * np_strdup(Npstr *str) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-06-04 17:42:25
|
Revision: 37 http://npfs.svn.sourceforge.net/npfs/?rev=37&view=rev Author: abbyz9 Date: 2009-06-04 17:42:18 +0000 (Thu, 04 Jun 2009) Log Message: ----------- Take out fus from the default build target, since it is not portable and might break build on non-Linux platforms Modified Paths: -------------- npfs/trunk/fs/Makefile Modified: npfs/trunk/fs/Makefile =================================================================== --- npfs/trunk/fs/Makefile 2009-06-03 21:06:59 UTC (rev 36) +++ npfs/trunk/fs/Makefile 2009-06-04 17:42:18 UTC (rev 37) @@ -14,7 +14,6 @@ FS=\ npfs\ - fus\ ramfs\ nullfs\ ramfs2\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-06-03 21:07:06
|
Revision: 36 http://npfs.svn.sourceforge.net/npfs/?rev=36&view=rev Author: abbyz9 Date: 2009-06-03 21:06:59 +0000 (Wed, 03 Jun 2009) Log Message: ----------- Fix format warnings for libnpfs Modified Paths: -------------- npfs/trunk/libnpfs/fmt.c Modified: npfs/trunk/libnpfs/fmt.c =================================================================== --- npfs/trunk/libnpfs/fmt.c 2009-06-03 21:04:16 UTC (rev 35) +++ npfs/trunk/libnpfs/fmt.c 2009-06-03 21:06:59 UTC (rev 36) @@ -79,7 +79,7 @@ buf[n++] = 'L'; buf[n] = '\0'; - return fprintf(f, " (%.16llx %x '%s')", q->path, q->version, buf); + return fprintf(f, " (%.16llx %x '%s')", (unsigned long long)q->path, q->version, buf); } int @@ -94,8 +94,8 @@ n += np_printqid(f, &st->qid); n += fprintf(f, " m "); n += np_printperm(f, st->mode); - n += fprintf(f, " at %d mt %d l %lld t %d d %d", - st->atime, st->mtime, st->length, st->type, st->dev); + n += fprintf(f, " at %d mt %d l %llu t %d d %d", + st->atime, st->mtime, (unsigned long long)st->length, st->type, st->dev); if (dotu) n += fprintf(f, " ext '%.*s'", st->extension.len, st->extension.str); @@ -238,8 +238,8 @@ break; case Tread: - ret += fprintf(f, "Tread tag %u fid %d offset %lld count %u", - tag, fid, fc->offset, fc->count); + ret += fprintf(f, "Tread tag %u fid %d offset %llu count %u", + tag, fid, (unsigned long long)fc->offset, fc->count); break; case Rread: @@ -248,8 +248,8 @@ break; case Twrite: - ret += fprintf(f, "Twrite tag %u fid %d offset %lld count %u data ", - tag, fid, fc->offset, fc->count); + ret += fprintf(f, "Twrite tag %u fid %d offset %llu count %u data ", + tag, fid, (unsigned long long)fc->offset, fc->count); ret += np_printdata(f, fc->data, fc->count); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-06-03 21:04:25
|
Revision: 35 http://npfs.svn.sourceforge.net/npfs/?rev=35&view=rev Author: abbyz9 Date: 2009-06-03 21:04:16 +0000 (Wed, 03 Jun 2009) Log Message: ----------- Fix npclient examples. Modified Paths: -------------- npfs/trunk/libnpclient/examples/9ls.c npfs/trunk/libnpclient/examples/9read.c npfs/trunk/libnpclient/examples/9write.c Modified: npfs/trunk/libnpclient/examples/9ls.c =================================================================== --- npfs/trunk/libnpclient/examples/9ls.c 2009-06-03 20:57:45 UTC (rev 34) +++ npfs/trunk/libnpclient/examples/9ls.c 2009-06-03 21:04:16 UTC (rev 35) @@ -48,27 +48,24 @@ int main(int argc, char **argv) { - int sfd, i, n; + int i, n; int c, port; char *addr, *s; - char *uname, *path; + char *path; Npuser *user; Npcfsys *fs; Npcfid *fid; - struct sockaddr_in saddr; - struct hostent *hostinfo; Npwstat *stat; port = 564; // npc_chatty = 1; - user = np_uid2user(geteuid()); + user = np_unix_users->uid2user(np_unix_users, 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': @@ -82,7 +79,7 @@ break; case 'u': - uname = optarg; + user = np_unix_users->uname2user(np_unix_users, optarg); break; default: @@ -98,29 +95,8 @@ addr = argv[optind]; path = argv[optind+1]; - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) { - perror("socket"); - exit(1); - } + fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); - 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, "error\n"); Modified: npfs/trunk/libnpclient/examples/9read.c =================================================================== --- npfs/trunk/libnpclient/examples/9read.c 2009-06-03 20:57:45 UTC (rev 34) +++ npfs/trunk/libnpclient/examples/9read.c 2009-06-03 21:04:16 UTC (rev 35) @@ -48,27 +48,24 @@ int main(int argc, char **argv) { - int sfd, i, n, off; + int i, n, off; int c, port; char *addr, *s; - char *uname, *path; + char *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()); + user = np_unix_users->uid2user(np_unix_users, 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': @@ -82,7 +79,7 @@ break; case 'u': - uname = optarg; + user = np_unix_users->uname2user(np_unix_users, optarg); break; default: @@ -98,29 +95,8 @@ addr = argv[optind]; path = argv[optind+1]; - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) { - perror("socket"); - exit(1); - } + fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); - 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"); Modified: npfs/trunk/libnpclient/examples/9write.c =================================================================== --- npfs/trunk/libnpclient/examples/9write.c 2009-06-03 20:57:45 UTC (rev 34) +++ npfs/trunk/libnpclient/examples/9write.c 2009-06-03 21:04:16 UTC (rev 35) @@ -48,27 +48,24 @@ int main(int argc, char **argv) { - int sfd, i, n, off; + int i, n, off; int c, port; char *addr, *s; - char *uname, *path; + char *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()); + user = np_unix_users->uid2user(np_unix_users, 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': @@ -82,7 +79,7 @@ break; case 'u': - uname = optarg; + user = np_unix_users->uname2user(np_unix_users, optarg); break; default: @@ -98,29 +95,8 @@ addr = argv[optind]; path = argv[optind+1]; - sfd = socket(PF_INET, SOCK_STREAM, 0); - if (sfd < 0) { - perror("socket"); - exit(1); - } + fs = npc_netmount(npc_netaddr(addr, port), user, port, NULL, NULL); - 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, Owrite); if (!fid) { fid = npc_create(fs, path, 0666, Owrite); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-06-03 20:57:54
|
Revision: 34 http://npfs.svn.sourceforge.net/npfs/?rev=34&view=rev Author: abbyz9 Date: 2009-06-03 20:57:45 +0000 (Wed, 03 Jun 2009) Log Message: ----------- Add the -p option to specify a port for the spclient examples Modified Paths: -------------- spfs/trunk/libspclient/examples/9ls.c spfs/trunk/libspclient/examples/9read.c spfs/trunk/libspclient/examples/9read2.c spfs/trunk/libspclient/examples/9write.c Modified: spfs/trunk/libspclient/examples/9ls.c =================================================================== --- spfs/trunk/libspclient/examples/9ls.c 2009-06-03 20:56:36 UTC (rev 33) +++ spfs/trunk/libspclient/examples/9ls.c 2009-06-03 20:57:45 UTC (rev 34) @@ -40,7 +40,7 @@ static void usage() { - fprintf(stderr, "9ls -d addr path\n"); + fprintf(stderr, "9ls -d addr -p port path\n"); exit(1); } @@ -48,14 +48,15 @@ main(int argc, char **argv) { int i, n; - int c; - char *addr; - char *path; + int c, port; + char *addr, *s, *path; Spuser *user; Spcfsys *fs; Spcfid *fid; Spwstat *stat; + port = 564; + user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { @@ -63,6 +64,12 @@ spc_chatty = 1; break; + case 'p': + port = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; @@ -83,7 +90,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = spc_netmount(addr, user, 564, NULL, NULL); + fs = spc_netmount(addr, user, port, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { Modified: spfs/trunk/libspclient/examples/9read.c =================================================================== --- spfs/trunk/libspclient/examples/9read.c 2009-06-03 20:56:36 UTC (rev 33) +++ spfs/trunk/libspclient/examples/9read.c 2009-06-03 20:57:45 UTC (rev 34) @@ -37,7 +37,7 @@ static void usage() { - fprintf(stderr, "9write -d addr path\n"); + fprintf(stderr, "9write -d addr -p port path\n"); exit(1); } @@ -45,14 +45,15 @@ main(int argc, char **argv) { int i, n, off; - int c; - char *addr; - char *path; + int c, port; + char *addr, *s, *path; Spuser *user; Spcfsys *fs; Spcfid *fid; char buf[512]; + port = 564; + user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { @@ -60,6 +61,12 @@ spc_chatty = 1; break; + case 'p': + port = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; @@ -80,7 +87,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = spc_netmount(addr, user, 564, NULL, NULL); + fs = spc_netmount(addr, user, port, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); Modified: spfs/trunk/libspclient/examples/9read2.c =================================================================== --- spfs/trunk/libspclient/examples/9read2.c 2009-06-03 20:56:36 UTC (rev 33) +++ spfs/trunk/libspclient/examples/9read2.c 2009-06-03 20:57:45 UTC (rev 34) @@ -39,7 +39,7 @@ static void usage() { - fprintf(stderr, "9read -d addr path\n"); + fprintf(stderr, "9read -d addr -p port path\n"); exit(1); } @@ -71,13 +71,14 @@ int main(int argc, char **argv) { - int c; - char *addr; - char *path; + int c, port; + char *addr, *s, *path; Spuser *user; Spcfsys *fs; Spcfid *fid; + port = 564; + user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { @@ -85,6 +86,12 @@ spc_chatty = 1; break; + case 'p': + port = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; @@ -105,7 +112,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = spc_netmount(addr, user, 564, NULL, NULL); + fs = spc_netmount(addr, user, port, NULL, NULL); fid = spc_open(fs, path, Oread); if (!fid) { fprintf(stderr, "cannot open\n"); Modified: spfs/trunk/libspclient/examples/9write.c =================================================================== --- spfs/trunk/libspclient/examples/9write.c 2009-06-03 20:56:36 UTC (rev 33) +++ spfs/trunk/libspclient/examples/9write.c 2009-06-03 20:57:45 UTC (rev 34) @@ -37,7 +37,7 @@ static void usage() { - fprintf(stderr, "9write -d addr path\n"); + fprintf(stderr, "9write -d addr -p port path\n"); exit(1); } @@ -45,14 +45,15 @@ main(int argc, char **argv) { int i, n, off; - int c; - char *addr; - char *path; + int c, port; + char *addr, *s, *path; Spuser *user; Spcfsys *fs; Spcfid *fid; char buf[512]; + port = 564; + user = sp_unix_users->uid2user(sp_unix_users, geteuid()); while ((c = getopt(argc, argv, "dp:")) != -1) { switch (c) { @@ -60,6 +61,12 @@ spc_chatty = 1; break; + case 'p': + port = strtol(optarg, &s, 10); + if (*s != '\0') + usage(); + break; + case 'u': user = sp_unix_users->uname2user(sp_unix_users, optarg); break; @@ -80,7 +87,7 @@ addr = argv[optind]; path = argv[optind+1]; - fs = spc_netmount(addr, user, 564, NULL, NULL); + fs = spc_netmount(addr, user, port, NULL, NULL); fid = spc_open(fs, path, Owrite); if (!fid) { fid = spc_create(fs, path, 0666, Owrite); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ab...@us...> - 2009-06-03 20:56:45
|
Revision: 33 http://npfs.svn.sourceforge.net/npfs/?rev=33&view=rev Author: abbyz9 Date: 2009-06-03 20:56:36 +0000 (Wed, 03 Jun 2009) Log Message: ----------- Fix typecast format warnings when printing the 9p debug information Modified Paths: -------------- spfs/trunk/libspfs/fmt.c Modified: spfs/trunk/libspfs/fmt.c =================================================================== --- spfs/trunk/libspfs/fmt.c 2009-06-03 20:40:56 UTC (rev 32) +++ spfs/trunk/libspfs/fmt.c 2009-06-03 20:56:36 UTC (rev 33) @@ -78,7 +78,7 @@ buf[n++] = 'L'; buf[n] = '\0'; - return fprintf(f, " (%.16llx %x '%s')", q->path, q->version, buf); + return fprintf(f, " (%.16llx %x '%s')", (unsigned long long)q->path, q->version, buf); } int @@ -93,8 +93,8 @@ n += sp_printqid(f, &st->qid); n += fprintf(f, " m "); n += sp_printperm(f, st->mode); - n += fprintf(f, " at %d mt %d l %lld t %d d %d", - st->atime, st->mtime, st->length, st->type, st->dev); + n += fprintf(f, " at %d mt %d l %llu t %d d %d", + st->atime, st->mtime, (unsigned long long)st->length, st->type, st->dev); if (dotu) n += fprintf(f, " ext '%.*s'", st->extension.len, st->extension.str); @@ -241,8 +241,8 @@ break; case Tread: - ret += fprintf(f, "Tread tag %u fid %d offset %lld count %u", - tag, fid, fc->offset, fc->count); + ret += fprintf(f, "Tread tag %u fid %d offset %llu count %u", + tag, fid, (unsigned long long)fc->offset, fc->count); break; case Rread: @@ -251,8 +251,8 @@ break; case Twrite: - ret += fprintf(f, "Twrite tag %u fid %d offset %lld count %u data ", - tag, fid, fc->offset, fc->count); + ret += fprintf(f, "Twrite tag %u fid %d offset %llu count %u data ", + tag, fid, (unsigned long long)fc->offset, fc->count); ret += sp_printdata(f, fc->data, fc->count); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |