From f4814575629d4565f408507c07e3dd711b26661c Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Sat, 11 Sep 2010 20:49:55 +0100 Subject: [PATCH] ptserver: Merge WhoIsThis and WhoIsThisWithName The functions WhoIsThis and WhoIsThisWithName are pretty much identical, with WhoIsThisWithName just having additional logic for foreign user registration. Merge them together, so that there's only one copy of the code for determining who a user is. Change-Id: Ia6e62ae932219f29e3141fe3c94b4be0110ca17a Reviewed-on: http://gerrit.openafs.org/2756 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/ptserver/ptprocs.c | 89 +++++++++--------------------------------- 1 file changed, 18 insertions(+), 71 deletions(-) diff --git a/src/ptserver/ptprocs.c b/src/ptserver/ptprocs.c index a3e8b2973..99ae041d1 100644 --- a/src/ptserver/ptprocs.c +++ b/src/ptserver/ptprocs.c @@ -176,61 +176,10 @@ CreateOK(struct ubik_trans *ut, afs_int32 cid, afs_int32 oid, afs_int32 flag, afs_int32 WhoIsThis(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid) { - int foreign = 0; - /* aid is set to the identity of the caller, if known, else ANONYMOUSID */ - /* returns -1 and sets aid to ANONYMOUSID on any failure */ - struct rx_connection *tconn; - afs_int32 code; - char tcell[MAXKTCREALMLEN]; - char name[MAXKTCNAMELEN]; - char inst[MAXKTCNAMELEN]; - int ilen; - char vname[256]; - - *aid = ANONYMOUSID; - tconn = rx_ConnectionOf(acall); - code = rx_SecurityClassOf(tconn); - if (code == 0) - return 0; - else if (code == 1) { /* vab class */ - goto done; /* no longer supported */ - } else if (code == 2) { /* kad class */ - if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ , - name, inst, tcell, NULL))) - goto done; -#if 0 - /* This test is unnecessary, since rxkad_GetServerInfo already check. - * In addition, this is wrong since exp must be unsigned. */ - if (exp < FT_ApproxTime()) - goto done; -#endif - if (tcell[0]) - foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName); - - strncpy(vname, name, sizeof(vname)); - if ((ilen = strlen(inst))) { - if (strlen(vname) + 1 + ilen >= sizeof(vname)) - goto done; - strcat(vname, "."); - strcat(vname, inst); - } - if (foreign) { - if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname)) - goto done; - strcat(vname, "@"); - strcat(vname, tcell); - } - if (strcmp(AUTH_SUPERUSER, vname) == 0) - *aid = SYSADMINID; /* special case for the fileserver */ - else { - lcstring(vname, vname, sizeof(vname)); - code = NameToID(at, vname, aid); - } - } - done: - if (code && !pr_noAuth) - return -1; - return 0; + int code = WhoIsThisWithName(acall, at, aid, NULL); + if (code == 2 && *aid == ANONYMOUSID) + return PRNOENT; + return code; } afs_int32 @@ -2158,6 +2107,7 @@ static afs_int32 WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid, char *aname) { + int foreign = 0; /* aid is set to the identity of the caller, if known, else ANONYMOUSID */ /* returns -1 and sets aid to ANONYMOUSID on any failure */ struct rx_connection *tconn; @@ -2176,13 +2126,13 @@ WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid, else if (code == 1) { /* vab class */ goto done; /* no longer supported */ } else if (code == 2) { /* kad class */ - - int clen; - - if ((code = rxkad_GetServerInfo(acall->conn, NULL, 0 /*was &exp */ , + if ((code = rxkad_GetServerInfo(acall->conn, NULL, NULL, name, inst, tcell, NULL))) goto done; + if (tcell[0]) + foreign = afs_is_foreign_ticket_name(name, inst, tcell, + pr_realmName); strncpy(vname, name, sizeof(vname)); if ((ilen = strlen(inst))) { @@ -2191,19 +2141,16 @@ WhoIsThisWithName(struct rx_call *acall, struct ubik_trans *at, afs_int32 *aid, strcat(vname, "."); strcat(vname, inst); } - if ((clen = strlen(tcell))) { - int foreign = afs_is_foreign_ticket_name(name,inst,tcell,pr_realmName); - - if (foreign) { - if (strlen(vname) + 1 + clen >= sizeof(vname)) - goto done; - strcat(vname, "@"); - strcat(vname, tcell); - lcstring(vname, vname, sizeof(vname)); - code = NameToID(at, vname, aid); + if (foreign) { + if (strlen(vname) + strlen(tcell) + 1 >= sizeof(vname)) + goto done; + strcat(vname, "@"); + strcat(vname, tcell); + lcstring(vname, vname, sizeof(vname)); + code = NameToID(at, vname, aid); + if (aname) strcpy(aname, vname); - return 2; - } + return 2; } if (strcmp(AUTH_SUPERUSER, vname) == 0) -- 2.39.5