ptclient: rxgk support
[openafs.git] / src / ptserver / ptclient.c
index 332b8ed..ef613f0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
@@ -9,41 +9,34 @@
 
 #include <afsconfig.h>
 #include <afs/param.h>
+#include <afs/stds.h>
 
-RCSID
-    ("$Header$");
+#include <roken.h>
+#include <afs/opr.h>
 
-#ifdef AFS_AIX32_ENV
-#include <signal.h>
-#endif
-#include <sys/types.h>
 #ifdef AFS_NT40_ENV
-#include <winsock2.h>
 #include <WINNT/afsevent.h>
-#else
-#include <netinet/in.h>
-#include <netdb.h>
 #endif
-#include <stdio.h>
+
 #include <rx/xdr.h>
 #include <rx/rx.h>
-#include <string.h>
-#include <afs/stds.h>
 #include <afs/com_err.h>
 #include <afs/cellconfig.h>
-#include "ptclient.h"
-#include "pterror.h"
 #include <afs/afsutil.h>
 
+#include "ptclient.h"
+#include "ptuser.h"
+#include "pterror.h"
+#include "display.h"
 
 afs_int32 security = 0;
 char confdir[AFSDIR_PATH_MAX];
 
 char *whoami;
 
-#ifndef AFS_PTHREAD_ENV
 extern struct ubik_client *pruclient;
-#endif
+static void skip(char **);
+static void PrintHelp(void);
 
 static int ignoreExist = 0;
 static char line[256];
@@ -51,9 +44,8 @@ static char *lineProgress;
 
 #define WHITESPACE " \t\n"
 
-#ifndef AFS_PTHREAD_ENV
 int
-osi_audit()
+osi_audit(void)
 {
 /* OK, this REALLY sucks bigtime, but I can't tell who is calling
  * afsconf_CheckAuth easily, and only *SERVERS* should be calling osi_audit
@@ -61,12 +53,9 @@ osi_audit()
  */
     return 0;
 }
-#endif /* !AFS_PTHREAD_ENV */
 
 int
-GetToken(format, l)
-     char *format;
-     afs_int32 *l;
+GetToken(char *format, afs_int32 *l)
 {
     int c;
 
@@ -87,9 +76,7 @@ GetToken(format, l)
 #define GetXInt32(l) GetToken ("%x", l)
 
 int
-GetString(s, slen)
-     char *s;
-     int slen;
+GetString(char *s, int slen)
 {
     char *beg;
     int l;
@@ -123,8 +110,7 @@ GetString(s, slen)
 }
 
 int
-CodeOk(code)
-     afs_int32 code;
+CodeOk(afs_int32 code)
 {
     if (!ignoreExist)
        return code;
@@ -132,14 +118,13 @@ CodeOk(code)
 }
 
 int
-PrintEntry(ea, e, indent)
-     afs_int32 ea;
-     struct prentry *e;
-     int indent;
+PrintEntry(afs_int32 ea, struct prentry *e, int indent)
 {
     /* handle screwed up versions of DumpEntry */
     if (e->flags & PRCONT) {
-       afs_int32 id = *(afs_int32 *) (e->name);
+       afs_int32 id;
+
+       memcpy(&id, e->name, sizeof(id));
        if ((id != PRBADID) && ((id > (1 << 24)) || (id < -(1 << 24)))) {
            /* assume server incorrectly swapped these bytes... */
            int i = 0;
@@ -158,22 +143,21 @@ PrintEntry(ea, e, indent)
     return pr_PrintEntry(stdout, /*host order */ 1, ea, e, indent);
 }
 
-#ifndef AFS_PTHREAD_ENV
 
 /* main program */
 
 #include "AFS_component_version_number.c"
 
-main(argc, argv)
-     int argc;
-     char **argv;
+int
+main(int argc, char **argv)
 {
-    register afs_int32 code;
+    afs_int32 code;
     char op[8];
     char name[PR_MAXNAMELEN];
     afs_int32 id, oid = ANONYMOUSID, gid;
     afs_int32 pos;
-    int i;
+    unsigned int i;
+    int n;
     struct prentry entry;
     prlist alist;
     idlist lid;
@@ -184,11 +168,12 @@ main(argc, argv)
     char *foo;
     afs_int32 over;
     char *cell;
+    afs_int32 rxgk_level = 0;
 
 #ifdef AFS_AIX32_ENV
     /*
-     * The following signal action for AIX is necessary so that in case of a 
-     * crash (i.e. core is generated) we can include the user's data section 
+     * The following signal action for AIX is necessary so that in case of a
+     * crash (i.e. core is generated) we can include the user's data section
      * in the core dump. Unfortunately, by default, only a partial core is
      * generated which, in many cases, isn't too useful.
      */
@@ -205,39 +190,41 @@ main(argc, argv)
 
     strcpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH);
     cell = 0;
-    i = 1;
-    while (i < argc) {
-       int arglen = strlen(argv[i]);
+    n = 1;
+    while (n < argc) {
+       int arglen = strlen(argv[n]);
        char arg[256];
-       lcstring(arg, argv[i], sizeof(arg));
+       lcstring(arg, argv[n], sizeof(arg));
 #define IsArg(a) (strncmp (arg,a, arglen) == 0)
        if (IsArg("-testconfdir"))
-           strncpy(confdir, argv[++i], sizeof(confdir));
+           strncpy(confdir, argv[++n], sizeof(confdir));
        else if (IsArg("client"))
            strncpy(confdir, AFSDIR_CLIENT_ETC_DIRPATH, sizeof(confdir));
        else if (IsArg("server"))
            strncpy(confdir, AFSDIR_SERVER_ETC_DIRPATH, sizeof(confdir));
-       else if (IsArg("0") || IsArg("1") || IsArg("2"))
-           security = atoi(argv[i]);
+       else if (IsArg("0") || IsArg("1") || IsArg("2") || IsArg("3"))
+           security = atoi(argv[n]);
+       else if (IsArg("-rxgk"))
+           rxgk_level = atoi(argv[++n]);
        else if (IsArg("-ignoreexist"))
            ignoreExist++;
        else if (IsArg("-cell"))
-           cell = argv[++i];
+           cell = argv[++n];
        else {
            printf
-               ("Usage is: 'prclient [-testconfdir <dir> | server | client] [0 | 1 | 2] [-ignoreExist] [-cell <cellname>]\n");
+               ("Usage is: 'prclient [-testconfdir <dir> | server | client] [0 | 1 | 2 | 3] [-rxgk 0 | 1 | 2] [-ignoreExist] [-cell <cellname>]\n");
            exit(1);
        }
-       i++;
+       n++;
     }
 
     printf("Using CellServDB file in %s\n", confdir);
     if (security == 0)
        printf("Making unauthenticated connection to prserver\n");
 
-    code = pr_Initialize(security, confdir, cell);
+    code = pr_Initialize2(security, confdir, cell, rxgk_level);
     if (code) {
-       com_err(whoami, code, "Couldn't initialize protection library");
+       afs_com_err(whoami, code, "Couldn't initialize protection library");
        exit(1);
     }
 
@@ -252,9 +239,9 @@ main(argc, argv)
 
        code = GetString(op, sizeof(op));
        if (code) {
-           com_err(whoami, PRBADARG,
+           afs_com_err(whoami, PRBADARG,
                    "error reading opcode in line '%s', got '%.*s'", line,
-                   sizeof(op), op);
+                   (int) sizeof(op), op);
            exit(1);
        }
        if (strlen(op) == 0)
@@ -269,7 +256,7 @@ main(argc, argv)
            else
                code = ubik_PR_INewEntry(pruclient, 0, name, id, oid);
            if (CodeOk(code))
-               com_err(whoami, code, "on %s %s %d %d", op, name, id, oid);
+               afs_com_err(whoami, code, "on %s %s %d %d", op, name, id, oid);
        } else if (!strcmp(op, "sf")) {
            afs_int32 mask, access, gq, uq;
            if (GetInt32(&id) || GetXInt32(&mask) || GetXInt32(&access)
@@ -280,7 +267,7 @@ main(argc, argv)
                    ubik_PR_SetFieldsEntry(pruclient, 0, id, mask,
                              access, gq, uq, 0, 0);
            if (CodeOk(code))
-               com_err(whoami, code, "on %s %d %x %x %d %d", op, id, mask,
+               afs_com_err(whoami, code, "on %s %d %x %x %d %d", op, id, mask,
                        access, gq, uq);
        } else if (!strcmp(op, "ce")) {
            char newname[PR_MAXNAMELEN];
@@ -293,7 +280,7 @@ main(argc, argv)
                    ubik_PR_ChangeEntry(pruclient, 0, id, newname, oid,
                              newid);
            if (CodeOk(code))
-               com_err(whoami, code, "on %s %d %s %d %d", op, id, newname,
+               afs_com_err(whoami, code, "on %s %d %s %d %d", op, id, newname,
                        oid, newid);
        } else if (!strcmp(op, "wh")) {
            /* scanf("%d",&id); */
@@ -311,7 +298,7 @@ main(argc, argv)
            if (GetInt32(&pos))
                code = PRBADARG;
            else
-               code = ubik_PR_DumpEntry(pruclient, 0, pos, &entry);
+               code = ubik_PR_DumpEntry(pruclient, 0, pos, (struct prdebugentry *)&entry);
            if (CodeOk(code))
                printf("%s\n", pr_ErrorMsg(code));
            if (code == PRSUCCESS) {
@@ -334,9 +321,9 @@ main(argc, argv)
            else
                code = ubik_PR_AddToGroup(pruclient, 0, id, gid);
            if (CodeOk(code))
-               com_err(whoami, code, "on %s %d %d", op, id, gid);
+               afs_com_err(whoami, code, "on %s %d %d", op, id, gid);
        } else if (!strcmp(op, "iton")) {
-           lid.idlist_val = (afs_int32 *) malloc(20 * sizeof(afs_int32));
+           lid.idlist_val = malloc(20 * sizeof(afs_int32));
            ptr = lid.idlist_val;
            lid.idlist_len = 0;
            foo = line;
@@ -365,13 +352,12 @@ main(argc, argv)
            lid.idlist_val = 0;
            lid.idlist_len = 0;
        } else if (!strcmp(op, "ntoi")) {
-           lnames.namelist_val =
-               (prname *) malloc(PR_MAXLIST * PR_MAXNAMELEN);
+           lnames.namelist_val = malloc(PR_MAXLIST * PR_MAXNAMELEN);
            lnames.namelist_len = 0;
            foo = line;
            skip(&foo);
            for (i = 0; ((lnames.namelist_len < PR_MAXLIST)
-                        && (sscanf(foo, "%s", lnames.namelist_val[i]) !=
+                        && (sscanf(foo, "%63s", lnames.namelist_val[i]) !=
                             EOF)); i++) {
                lnames.namelist_len++;
                skip(&foo);
@@ -477,7 +463,7 @@ main(argc, argv)
            else if (!(hostinfo = gethostbyname(name)))
                code = PRBADARG;
            else {
-               hostaddr = hostinfo->h_addr_list[0];
+               hostaddr = (struct in_addr *)hostinfo->h_addr_list[0];
                id = ntohl(hostaddr->s_addr);
                code =
                    ubik_PR_GetHostCPS(pruclient, 0, id, &alist, &over);
@@ -648,7 +634,7 @@ main(argc, argv)
        else if (!strcmp(op, "fih")) {
            char tname[128];
            struct PrUpdateEntry uentry;
-           bzero(&uentry, sizeof(uentry));
+           memset(&uentry, 0, sizeof(uentry));
            /* scanf("%s",name); */
            if (GetString(name, sizeof(name))) {
                code = PRBADARG;
@@ -675,7 +661,7 @@ main(argc, argv)
        } else if (!strcmp(op, "fnh")) {
            int tid;
            struct PrUpdateEntry uentry;
-           bzero(&uentry, sizeof(uentry));
+           memset(&uentry, 0, sizeof(uentry));
            /* scanf("%d", &id); */
            if (GetInt32(&id)) {
                code = PRBADARG;
@@ -710,10 +696,12 @@ main(argc, argv)
        else
            printf("Unknown op: '%s'! ? for help\n", op);
     }
+    return 0;
 }
 
 
-PrintHelp()
+static void
+PrintHelp(void)
 {
     printf("cr name id owner - create entry with name and id.\n");
     printf("wh id  - what is the offset into database for id?\n");
@@ -742,13 +730,11 @@ PrintHelp()
     printf("q - quit.\n?- this message.\n");
 }
 
-
-skip(s)
-     char **s;
+static void
+skip(char **s)
 {
     while (**s != ' ' && **s != '\0')
        (*s)++;
     while (**s == ' ')
        (*s)++;
 }
-#endif /* !AFS_PTHREAD_ENV */