2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
15 #include <afs/afsint.h>
16 #include <sys/socket.h>
17 #include <rx/rx_globals.h>
18 #include <netinet/in.h>
19 #include <arpa/inet.h>
24 struct ubik_client *cstruct;
25 struct rx_connection *serverconns[MAXSERVERS];
29 pxclient_Initialize(int auth, afs_int32 serverAddr)
32 rx_securityIndex scIndex;
33 struct rx_securityClass *sc;
35 code = rx_Init(htons(2115) /*0 */ );
37 fprintf(stderr, "pxclient_Initialize: Could not initialize rx.\n");
40 scIndex = RX_SECIDX_NULL;
42 sc = rxnull_NewClientSecurityObject();
44 rx_NewConnection(serverAddr, htons(7000), 1, sc, scIndex);
46 code = ubik_ClientInit(serverconns, &cstruct);
49 fprintf(stderr, "pxclient_Initialize: ubik client init failed.\n");
57 #include "AFS_component_version_number.c"
60 main(int argc, char **argv)
63 struct sockaddr_in host;
68 int noAuth = 1; /* Default is authenticated connections */
72 printf("usage: pxclient <serverHost>\n");
75 memset(&host, 0, sizeof(struct sockaddr_in));
76 host.sin_family = AF_INET;
77 host.sin_addr.s_addr = inet_addr(av[0]);
78 #ifdef STRUCT_SOCKADDR_HAS_SA_LEN
79 host.sin_len = sizeof(struct sockaddr_in);
81 if (host.sin_addr.s_addr != -1) {
82 strcpy(hnamebuf, av[0]);
84 hp = gethostbyname(av[0]);
86 host.sin_family = hp->h_addrtype;
87 memcpy((caddr_t) & host.sin_addr, hp->h_addr, hp->h_length);
89 printf("unknown server host %s\n", av[0]);
93 if ((code = pxclient_Initialize(noAuth, host.sin_addr.s_addr)) != 0) {
94 printf("Couldn't initialize fs library (code=%d).\n", code);
98 code = ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec, &tv.tv_usec);
100 printf("AFS_GetTime on %s sec=%ld, usec=%ld\n", av[0], tv.tv_sec,
101 (long int)tv.tv_usec);
103 printf("return code is %d\n", code);
111 if (fgets(line, 499, stdin) != NULL) {
114 GetArgs(line, argp, &nargs);
117 if (!strcmp(oper, "probe")) {
119 ubik_Call(RXAFS_GetTime, cstruct, 0, &tv.tv_sec,
121 printf("return code is %d\n", code);
123 printf("sec=%d\n", tv.tv_sec);
124 } else if (!strcmp(oper, "fsstats")) {
125 struct afsStatistics stats;
127 code = ubik_AFS_GetStatistics(cstruct, 0, &stats);
128 printf("return code is %d\n", code);
129 } else if (!strcmp(oper, "fd")) {
130 code = FetchData(argp);
131 printf("return code is %d\n", code);
132 } else if (!strcmp(oper, "fs")) {
133 code = FetchStatus(argp);
134 printf("return code is %d\n", code);
135 } else if (!strcmp(oper, "fa")) {
136 code = FetchACL(argp);
137 printf("return code is %d\n", code);
138 } else if (!strcmp(oper, "sd")) {
139 code = StoreData(argp);
140 printf("return code is %d\n", code);
141 } else if (!strcmp(oper, "ss")) {
142 code = StoreStatus(argp);
143 printf("return code is %d\n", code);
144 } else if (!strcmp(oper, "sa")) {
145 code = StoreACL(argp);
146 printf("return code is %d\n", code);
147 } else if (!strcmp(oper, "cf")) {
148 code = CreateFile(argp);
149 printf("return code is %d\n", code);
150 } else if (!strcmp(oper, "rf")) {
151 code = RemoveFile(argp);
152 printf("return code is %d\n", code);
153 } else if (!strcmp(oper, "rn")) {
155 printf("return code is %d\n", code);
156 } else if (!strcmp(oper, "sl")) {
157 code = Symlink(argp);
158 printf("return code is %d\n", code);
159 } else if (!strcmp(oper, "hl")) {
160 code = HardLink(argp);
161 printf("return code is %d\n", code);
162 } else if (!strcmp(oper, "md")) {
163 code = MakeDir(argp);
164 printf("return code is %d\n", code);
165 } else if (!strcmp(oper, "rd")) {
166 code = RemoveDir(argp);
167 printf("return code is %d\n", code);
168 } else if (!strcmp(oper, "rdd")) {
169 code = Readdir(argp);
170 printf("return code is %d\n", code);
171 } else if (!strcmp(oper, "mm")) {
172 code = MakeMountPoint(argp);
173 printf("return code is %d\n", code);
174 } else if (!strcmp(oper, "rt")) {
175 code = ReleaseTokens(argp);
176 printf("return code is %d\n", code);
177 } else if (!strcmp(oper, "bs")) {
178 code = BulkStatus(argp);
179 printf("return code is %d\n", code);
180 } else if (!strcmp(oper, "lk")) {
182 printf("return code is %d\n", code);
183 } else if (!strcmp(oper, "gt")) {
184 code = GetToken(argp);
185 printf("return code is %d\n", code);
186 } else if (!strcmp(oper, "ka")) {
187 code = KeepAlive(argp);
188 printf("return code is %d\n", code);
189 } else if ((!strcmp(oper, "q")) || !strcmp(oper, "quit"))
192 printf("Unknown oper! Available operations: \n\n");
193 printf("fd <vnode> <unique> <pos> <len>\n");
194 printf("fs <vnode> <unique>\n");
195 printf("fa <vnode> <unique>\n");
197 ("sd <vnode> <unique> <pos> <len> <flen> [<mode>|-1] [<owner>|-1] [<length>|-1] <string>\n");
199 ("ss <vnode> <unique> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
200 printf("sa <vnode> <unique> <string>\n");
201 printf("rf <vnode> <unique> <name>\n");
203 ("cf <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
205 ("rn <ovnode> <ounique> <oname> <nvnode> <nunique> <nname>\n");
207 ("sl <vnode> <unique> <name> <contents> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
208 printf("hl <dvnode> <dunique> <name> <evnode> <eunique>\n");
210 ("md <vnode> <unique> <name> [<mode>|-1] [<owner>|-1] [<length>|-1]\n");
211 printf("rd <vnode> <unique> <name>\n");
212 printf("rdd <vnode> <unique> <pos> <len>\n");
213 printf("lk <vnode> <unique> <name>\n");
214 printf("gt <vnode> <unique> <tokenID>\n");
215 printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n");
225 GetArgs(char *line, char **args, int *nargs)
236 *args++ = line, (*nargs)++;
237 while (*line && *line != ' ')
244 FetchData(char **argp)
246 struct afsFetchStatus OutStatus;
247 struct afsToken Token;
248 struct afsVolSync tsync;
250 int vnode, unique, position, length;
252 struct rx_call *tcall;
254 sscanf(&(*argp)[0], "%d", &vnode);
256 sscanf(&(*argp)[0], "%d", &unique);
258 memset(&fid, 0, sizeof(struct afsFid));
259 fid.Volume.low = 10; /* XXX */
262 sscanf(&(*argp)[0], "%d", &position);
264 sscanf(&(*argp)[0], "%d", &length);
266 tcall = rx_NewCall(cstruct->conns[0]);
267 code = StartAFS_FetchData(tcall, &fid, &hyp0, position, length, 0);
269 code = FetchProc(tcall);
272 code = EndAFS_FetchData(tcall, &OutStatus, &Token, &tsync);
274 code = rx_EndCall(tcall, code);
280 FetchProc(struct rx_call *acall)
282 extern char *malloc();
284 afs_int32 tlen, length, code;
286 code = rx_Read(acall, &length, sizeof(afs_int32));
287 length = ntohl(length);
288 if (code != sizeof(afs_int32))
290 tbuffer = malloc(256);
292 tlen = (length > 256 ? 256 : length);
293 code = rx_Read(acall, tbuffer, tlen);
306 FetchStatus(char **argp)
308 struct afsFetchStatus OutStatus;
309 struct afsToken Token;
310 struct afsVolSync tsync;
315 sscanf(&(*argp)[0], "%d", &vnode);
317 sscanf(&(*argp)[0], "%d", &unique);
319 memset(&fid, 0, sizeof(struct afsFid));
320 fid.Volume.low = 10; /* XXX */
324 ubik_AFS_FetchStatus(cstruct, 0, &fid, &hyp0, 0, &OutStatus,
331 FetchACL(char **argp)
333 struct afsFetchStatus OutStatus;
334 struct afsACL AccessList;
335 struct afsToken Token;
336 struct afsVolSync tsync;
341 sscanf(&(*argp)[0], "%d", &vnode);
343 sscanf(&(*argp)[0], "%d", &unique);
345 memset(&fid, 0, sizeof(struct afsFid));
346 fid.Volume.low = 10; /* XXX */
350 ubik_AFS_FetchACL(cstruct, 0, &fid, &hyp0, 0, &AccessList,
357 StoreData(char **argp)
359 struct afsStoreStatus InStatus;
360 struct afsFetchStatus OutStatus;
361 struct afsVolSync tsync;
363 int vnode, unique, position, length, filelength;
364 int mode, owner, len;
367 struct rx_call *tcall;
369 sscanf(&(*argp)[0], "%d", &vnode);
371 sscanf(&(*argp)[0], "%d", &unique);
373 memset(&fid, 0, sizeof(struct afsFid));
374 fid.Volume.low = 10; /* XXX */
377 sscanf(&(*argp)[0], "%d", &position);
379 sscanf(&(*argp)[0], "%d", &length);
381 sscanf(&(*argp)[0], "%d", &filelength);
383 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
384 sscanf(&(*argp)[0], "%d", &mode);
386 sscanf(&(*argp)[0], "%d", &owner);
388 sscanf(&(*argp)[0], "%d", &len);
391 InStatus.mode = mode;
392 InStatus.mask |= AFS_SETMODE;
395 InStatus.owner = owner;
396 InStatus.mask |= AFS_SETOWNER;
399 InStatus.length = length;
400 InStatus.mask |= AFS_SETLENGTH;
402 string = &argp[0][0];
405 tcall = rx_NewCall(cstruct->conns[0]);
407 StartAFS_StoreData(tcall, &fid, &InStatus, position, length,
408 filelength, &hyp0, 0);
410 code = StoreProc(tcall, string, length);
413 code = EndAFS_StoreData(tcall, &OutStatus, &tsync);
415 code = rx_EndCall(tcall, code);
421 StoreProc(struct rx_call *acall, char *string, int length)
423 afs_int32 tlen, code;
426 tlen = (length > 256 ? 256 : length);
427 code = rx_Write(acall, string, tlen);
438 StoreStatus(char **argp)
440 struct afsStoreStatus InStatus;
441 struct afsFetchStatus OutStatus;
442 struct afsVolSync tsync;
444 int vnode, unique, mode, owner, length;
447 sscanf(&(*argp)[0], "%d", &vnode);
449 sscanf(&(*argp)[0], "%d", &unique);
451 memset(&fid, 0, sizeof(struct afsFid));
452 fid.Volume.low = 10; /* XXX */
455 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
456 sscanf(&(*argp)[0], "%d", &mode);
458 sscanf(&(*argp)[0], "%d", &owner);
460 sscanf(&(*argp)[0], "%d", &length);
463 InStatus.mode = mode;
464 InStatus.mask |= AFS_SETMODE;
467 InStatus.owner = owner;
468 InStatus.mask |= AFS_SETOWNER;
471 InStatus.length = length;
472 InStatus.mask |= AFS_SETLENGTH;
475 ubik_AFS_StoreStatus(cstruct, 0, &fid, &InStatus, &hyp0, 0,
482 StoreACL(char **argp)
484 struct afsFetchStatus OutStatus;
485 struct afsACL AccessList;
486 struct afsToken Token;
487 struct afsVolSync tsync;
493 sscanf(&(*argp)[0], "%d", &vnode);
495 sscanf(&(*argp)[0], "%d", &unique);
497 memset(&fid, 0, sizeof(struct afsFid));
498 fid.Volume.low = 10; /* XXX */
501 string = &argp[0][0];
503 AccessList.afsACL_len = strlen(string) + 1;
504 AccessList.afsACL_val = string;
506 ubik_AFS_StoreACL(cstruct, 0, &fid, &AccessList, &hyp0, 0,
513 RemoveFile(char **argp)
515 struct afsFetchStatus OutDirStatus, OutFidStatus;
516 struct afsVolSync tsync;
517 struct afsFidName nameFid;
518 struct afsFid fid, outFid;
523 sscanf(&(*argp)[0], "%d", &vnode);
525 sscanf(&(*argp)[0], "%d", &unique);
527 memset(&fid, 0, sizeof(struct afsFid));
528 fid.Volume.low = 10; /* XXX */
533 memset(&nameFid, 0, sizeof(struct afsFidName));
534 strcpy(nameFid.name, name);
536 ubik_AFS_RemoveFile(cstruct, 0, &fid, &nameFid, &hyp0, 0,
537 &OutDirStatus, &OutFidStatus, &outFid, &tsync);
543 CreateFile(char **argp)
545 struct afsFetchStatus OutDirStatus, OutFidStatus;
546 struct afsStoreStatus InStatus;
547 struct afsVolSync tsync;
548 struct afsFid fid, outFid;
549 struct afsToken Token;
551 int vnode, unique, mode, owner, length;
554 sscanf(&(*argp)[0], "%d", &vnode);
556 sscanf(&(*argp)[0], "%d", &unique);
558 memset(&fid, 0, sizeof(struct afsFid));
559 fid.Volume.low = 10; /* XXX */
564 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
565 sscanf(&(*argp)[0], "%d", &mode);
567 sscanf(&(*argp)[0], "%d", &owner);
569 sscanf(&(*argp)[0], "%d", &length);
572 InStatus.mode = mode;
573 InStatus.mask |= AFS_SETMODE;
576 InStatus.owner = owner;
577 InStatus.mask |= AFS_SETOWNER;
580 InStatus.length = length;
581 InStatus.mask |= AFS_SETLENGTH;
584 ubik_AFS_CreateFile(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
585 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
593 struct afsFetchStatus OutOldDirStatus, OutNewDirStatus;
594 struct afsFetchStatus OutOldFileStatus, OutNewFileStatus;
595 struct afsVolSync tsync;
596 struct afsFid OldDirFid, NewDirFid, OutOldFileFid, OutNewFileFid;
597 struct afsFidName OldName, NewName;
599 int ovnode, ounique, nvnode, nunique;
602 sscanf(&(*argp)[0], "%d", &ovnode);
604 sscanf(&(*argp)[0], "%d", &ounique);
606 memset(&OldDirFid, 0, sizeof(struct afsFid));
607 OldDirFid.Volume.low = 10; /* XXX */
608 OldDirFid.Vnode = ovnode;
609 OldDirFid.Unique = ounique;
612 memset(&OldName, 0, sizeof(struct afsFidName));
613 strcpy(OldName.name, oname);
614 sscanf(&(*argp)[0], "%d", &nvnode);
616 sscanf(&(*argp)[0], "%d", &nunique);
618 memset(&NewDirFid, 0, sizeof(struct afsFid));
619 NewDirFid.Volume.low = 10; /* XXX */
620 NewDirFid.Vnode = nvnode;
621 NewDirFid.Unique = nunique;
624 memset(&NewName, 0, sizeof(struct afsFidName));
625 strcpy(NewName.name, nname);
627 ubik_AFS_Rename(cstruct, 0, &OldDirFid, &OldName, &NewDirFid,
628 &NewName, &hyp0, 0, &OutOldDirStatus, &OutNewDirStatus,
629 &OutOldFileFid, &OutOldFileStatus, &OutNewFileFid,
630 &OutNewFileStatus, &tsync);
638 struct afsFetchStatus OutDirStatus, OutFidStatus;
639 struct afsStoreStatus InStatus;
640 struct afsVolSync tsync;
641 struct afsFid fid, outFid;
642 struct afsToken Token;
643 char *name, *linkcontents;
644 int vnode, unique, mode, owner, length;
647 sscanf(&(*argp)[0], "%d", &vnode);
649 sscanf(&(*argp)[0], "%d", &unique);
651 memset(&fid, 0, sizeof(struct afsFid));
652 fid.Volume.low = 10; /* XXX */
657 linkcontents = &argp[0][0];
659 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
660 sscanf(&(*argp)[0], "%d", &mode);
662 sscanf(&(*argp)[0], "%d", &owner);
664 sscanf(&(*argp)[0], "%d", &length);
667 InStatus.mode = mode;
668 InStatus.mask |= AFS_SETMODE;
671 InStatus.owner = owner;
672 InStatus.mask |= AFS_SETOWNER;
675 InStatus.length = length;
676 InStatus.mask |= AFS_SETLENGTH;
679 ubik_AFS_Symlink(cstruct, 0, &fid, name, linkcontents,
680 &InStatus, &hyp0, 0, &outFid, &OutFidStatus, &OutDirStatus,
687 HardLink(char **argp)
689 struct afsFetchStatus OutDirStatus, OutFidStatus;
690 struct afsVolSync tsync;
691 struct afsFid fid, existingFid;
696 sscanf(&(*argp)[0], "%d", &vnode);
698 sscanf(&(*argp)[0], "%d", &unique);
700 memset(&fid, 0, sizeof(struct afsFid));
701 fid.Volume.low = 10; /* XXX */
706 sscanf(&(*argp)[0], "%d", &vnode);
708 sscanf(&(*argp)[0], "%d", &unique);
710 memset(&existingFid, 0, sizeof(struct afsFid));
711 existingFid.Volume.low = 10; /* XXX */
712 existingFid.Vnode = vnode;
713 existingFid.Unique = unique;
715 ubik_AFS_HardLink(cstruct, 0, &fid, name, &existingFid, &hyp0,
716 0, &OutFidStatus, &OutDirStatus, &tsync);
724 struct afsFetchStatus OutDirStatus, OutFidStatus;
725 struct afsStoreStatus InStatus;
726 struct afsVolSync tsync;
727 struct afsFid fid, outFid;
728 struct afsToken Token;
730 int vnode, unique, mode, owner, length;
733 sscanf(&(*argp)[0], "%d", &vnode);
735 sscanf(&(*argp)[0], "%d", &unique);
737 memset(&fid, 0, sizeof(struct afsFid));
738 fid.Volume.low = 10; /* XXX */
743 memset(&InStatus, 0, sizeof(struct afsStoreStatus));
744 sscanf(&(*argp)[0], "%d", &mode);
746 sscanf(&(*argp)[0], "%d", &owner);
748 sscanf(&(*argp)[0], "%d", &length);
751 InStatus.mode = mode;
752 InStatus.mask |= AFS_SETMODE;
755 InStatus.owner = owner;
756 InStatus.mask |= AFS_SETOWNER;
759 InStatus.length = length;
760 InStatus.mask |= AFS_SETLENGTH;
763 ubik_AFS_MakeDir(cstruct, 0, &fid, name, &InStatus, &hyp0, 0,
764 &outFid, &OutFidStatus, &OutDirStatus, &Token, &tsync);
770 RemoveDir(char **argp)
772 struct afsFetchStatus OutDirStatus;
773 struct afsVolSync tsync;
774 struct afsFid fid, outFid;
775 struct afsFidName nameFid;
780 sscanf(&(*argp)[0], "%d", &vnode);
782 sscanf(&(*argp)[0], "%d", &unique);
784 memset(&fid, 0, sizeof(struct afsFid));
785 fid.Volume.low = 10; /* XXX */
790 memset(&nameFid, 0, sizeof(struct afsFidName));
791 strcpy(nameFid.name, name);
793 ubik_AFS_RemoveDir(cstruct, 0, &fid, &nameFid, &hyp0, 0,
794 &OutDirStatus, &outFid, &tsync);
802 struct afsFetchStatus OutDirStatus;
803 struct afsVolSync tsync;
805 struct afsToken Token;
807 struct rx_call *tcall;
808 int vnode, unique, offset, length, NextOffset;
811 sscanf(&(*argp)[0], "%d", &vnode);
813 sscanf(&(*argp)[0], "%d", &unique);
815 sscanf(&(*argp)[0], "%d", &offset);
817 sscanf(&(*argp)[0], "%d", &length);
819 memset(&fid, 0, sizeof(struct afsFid));
820 fid.Volume.low = 10; /* XXX */
823 tcall = rx_NewCall(cstruct->conns[0]);
824 code = StartAFS_Readdir(tcall, &fid, offset, length, &hyp0, 0);
826 code = FetchDir(tcall);
830 EndAFS_FetchData(tcall, &NextOffset, &OutDirStatus, &Token,
833 code = rx_EndCall(tcall, code);
839 FetchDir(struct rx_call *acall)
841 extern char *malloc();
843 afs_int32 tlen, length, code;
847 tbuffer = malloc(256);
849 code = rx_Read(acall, &length, sizeof(afs_int32));
850 length = ntohl(length);
851 if (code != sizeof(afs_int32))
855 tlen = (length > 8192 ? 8192 : length);
856 code = rx_Read(acall, tbuffer, tlen);
863 dp = (struct dirent *)dp;
872 struct afsFetchStatus OutDirStatus, OutFidStatus;
873 struct afsVolSync tsync;
874 struct afsFid fid, outFid;
879 sscanf(&(*argp)[0], "%d", &vnode);
881 sscanf(&(*argp)[0], "%d", &unique);
883 memset(&fid, 0, sizeof(struct afsFid));
884 fid.Volume.low = 10; /* XXX */
890 ubik_AFS_Lookup(cstruct, 0, &fid, name, &hyp0, 0, &outFid,
891 &OutFidStatus, &OutDirStatus, &tsync);
897 GetToken(char **argp)
899 struct afsFetchStatus OutStatus;
900 struct afsVolSync tsync;
901 struct afsToken MinToken, RealToken;
903 int vnode, unique, tokenId;
906 sscanf(&(*argp)[0], "%d", &vnode);
908 sscanf(&(*argp)[0], "%d", &unique);
910 memset(&fid, 0, sizeof(struct afsFid));
911 fid.Volume.low = 10; /* XXX */
914 sscanf(&(*argp)[0], "%d", &tokenId);
916 memset(&MinToken, 0, sizeof(struct afsToken));
917 MinToken.tokenID.low = tokenId; /* XXX */
919 ubik_AFS_GetToken(cstruct, 0, &fid, &MinToken, &hyp0, 0,
920 &RealToken, &OutStatus, &tsync);
926 MakeMountPoint(char **argp)
932 ReleaseTokens(char **argp)
938 BulkStatus(char **argp)
942 /* printf("ka <vol.l> <vnode> <unique> <isExec> <kaTime>\n"); */
944 KeepAlive(char **argp)
946 struct afsBulkFEX fex;
947 afs_uint32 numExec, spare4;
951 memset(&fx, 0, sizeof(struct afsFidExp));
952 sscanf(&(*argp)[0], "%d", &fx.fid.Volume.low);
954 sscanf(&(*argp)[0], "%d", &fx.fid.Vnode);
956 sscanf(&(*argp)[0], "%d", &fx.fid.Unique);
958 sscanf(&(*argp)[0], "%d", &numExec);
960 sscanf(&(*argp)[0], "%d", &fx.keepAliveTime);
961 memset(&fex, 0, sizeof(struct afsBulkFEX));
962 fex.afsBulkFEX_val = &fx;
963 fex.afsBulkFEX_len = 1;
965 ubik_AFS_BulkKeepAlive(cstruct, 0, &fex, numExec, 0, 0, 0,