]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
auth: Add the ktc_ListTokensEx function
authorSimon Wilkinson <sxw@your-file-system.com>
Sat, 11 Sep 2010 09:11:57 +0000 (10:11 +0100)
committerDerrick Brashear <shadow@dementia.org>
Mon, 20 Sep 2010 07:09:21 +0000 (00:09 -0700)
Add a ktc_ListTokensEx function which uses the new GetToken pioctl
to implement the same functionality as the old ktc_ListTokens call.

As with ktc_ListTokens this is hugely inefficient, as it gets a
compelete token structure from the kernel, then throws it away to
return just the cell which the token is for.

Change-Id: Idf3daa536c6a04d397691d0cc6fcb2c59f9f444c
Reviewed-on: http://gerrit.openafs.org/2748
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/auth/auth.p.h
src/auth/ktc.c
src/auth/ktc_nt.c
src/libafsauthent/afsauthent.def

index 84f8c0c8fe03a7a5c0fe614f87912965d2fd8105..9423dd09845b4338959e5d1d167cc85890d3c963 100644 (file)
@@ -32,6 +32,7 @@ int ktc_GetToken(struct ktc_principal *, struct ktc_token *,
 struct ktc_setTokenData;
 int ktc_SetTokenEx(struct ktc_setTokenData *);
 int ktc_GetTokenEx(char *, struct ktc_setTokenData **);
+int ktc_ListTokensEx(int, int *, char **cellName);
 
 int ktc_ListTokens(int, int *, struct ktc_principal *);
 int ktc_ForgetToken(struct ktc_principal *);
index a29613c75c43e7d24a812450fa2f56bcd7c488a4..3e0e0a79f9f0c98e36a1291936f9ebd76025827e 100644 (file)
@@ -736,6 +736,63 @@ ktc_ForgetToken(struct ktc_principal *aserver)
 }
 #endif /* NO_AFS_CLIENT */
 
+int
+ktc_ListTokensEx(int prevIndex, int *newIndex, char **cellName) {
+    struct ViceIoctl iob;
+    char tbuffer[MAXPIOCTLTOKENLEN];
+    afs_int32 code;
+    afs_int32 index;
+    struct ktc_setTokenData tokenSet;
+    XDR xdrs;
+
+    memset(&tokenSet, 0, sizeof(tokenSet));
+
+    *cellName = NULL;
+    *newIndex = prevIndex;
+
+    index = prevIndex;
+
+    while (index<100) { /* Safety, incase of pioctl failure */
+       memset(tbuffer, 0, sizeof(tbuffer));
+       iob.in = tbuffer;
+       memcpy(tbuffer, &index, sizeof(afs_int32));
+       iob.in_size = sizeof(afs_int32);
+       iob.out = tbuffer;
+       iob.out_size = sizeof(tbuffer);
+
+       code = PIOCTL(0, VIOC_GETTOK2, &iob, 0);
+
+       /* Can't use new pioctl, so must use old one */
+       if (code == -1 && errno == EINVAL) {
+           struct ktc_principal server;
+
+           code = ktc_ListTokens(index, newIndex, &server);
+           if (code == 0)
+               *cellName = strdup(server.cell);
+           return code;
+       }
+
+       if (code == 0) {
+           /* Got a token from the pioctl. Now we throw it away,
+            * so we can return just a cellname. This is rather wasteful,
+            * but it's what the old API does. Ho hum.  */
+
+           xdrmem_create(&xdrs, iob.out, iob.out_size, XDR_DECODE);
+           if (!xdr_ktc_setTokenData(&xdrs, &tokenSet)) {
+               xdr_destroy(&xdrs);
+               return EINVAL;
+           }
+           xdr_destroy(&xdrs);
+           *cellName = strdup(tokenSet.cell);
+           xdr_free((xdrproc_t)xdr_ktc_setTokenData, &tokenSet);
+           *newIndex = index + 1;
+           return 0;
+       }
+       index++;
+    }
+    return KTC_PIOCTLFAIL;
+}
+
 /* ktc_ListTokens - list all tokens.  start aprevIndex at 0, it returns the
  * next rock in (*aindex).  (*aserver) is set to the relevant ticket on
  * success.  */
index 79ba04b0b229bc5c1ea2d6ef33e8ef750b3ff7d5..65aaac2853d9fb57d493d4594fd5e3a6dd361b01 100644 (file)
@@ -959,3 +959,10 @@ ForgetOneLocalToken(struct ktc_principal *aserver)
     UNLOCK_GLOBAL_MUTEX;
     return KTC_NOENT;
 }
+
+int
+ktc_ListTokensEx(int prevIndex, int *newIndex, char **cellName) {
+    /* Not yet implemented */
+    return KTC_PIOCTLFAIL;
+}
+
index e9a1bb5f978903652153cb7c3c70031d4a825b31..a0bd567e7ea7f71816432af202c8cb738dbba5c9 100644 (file)
@@ -148,3 +148,4 @@ EXPORTS
        token_FreeSet                                   @146
         xdr_ktc_tokenUnion                              @147
         xdr_ktc_setTokenData                            @148
+       ktc_ListTokensEx                                @149