From: Simon Wilkinson Date: Sat, 11 Sep 2010 09:11:57 +0000 (+0100) Subject: auth: Add the ktc_ListTokensEx function X-Git-Tag: openafs-devel-1_7_1~1557 X-Git-Url: http://git.openafs.org/?p=openafs.git;a=commitdiff_plain;h=a86ad262d2a8be36f43ab0885a84dde37ddfc464;hp=5c3a1ed88de16db4c2081bbf1a4e397ce459bcf3 auth: Add the ktc_ListTokensEx function 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 Tested-by: Derrick Brashear --- diff --git a/src/auth/auth.p.h b/src/auth/auth.p.h index 84f8c0c..9423dd0 100644 --- a/src/auth/auth.p.h +++ b/src/auth/auth.p.h @@ -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 *); diff --git a/src/auth/ktc.c b/src/auth/ktc.c index a29613c..3e0e0a7 100644 --- a/src/auth/ktc.c +++ b/src/auth/ktc.c @@ -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. */ diff --git a/src/auth/ktc_nt.c b/src/auth/ktc_nt.c index 79ba04b..65aaac2 100644 --- a/src/auth/ktc_nt.c +++ b/src/auth/ktc_nt.c @@ -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; +} + diff --git a/src/libafsauthent/afsauthent.def b/src/libafsauthent/afsauthent.def index e9a1bb5..a0bd567 100644 --- a/src/libafsauthent/afsauthent.def +++ b/src/libafsauthent/afsauthent.def @@ -148,3 +148,4 @@ EXPORTS token_FreeSet @146 xdr_ktc_tokenUnion @147 xdr_ktc_setTokenData @148 + ktc_ListTokensEx @149