kauth: don't call lcstring with a null source argument
[openafs.git] / src / kauth / authclient.c
index fdb321d..10bef97 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
 /* These routines provide a convenient interface to the AuthServer. */
 
 #include <afsconfig.h>
-#if defined(UKERNEL)
-#include "afs/param.h"
-#else
 #include <afs/param.h>
+#include <afs/stds.h>
+
+#include <roken.h>
+#include <afs/opr.h>
+
+#ifdef IGNORE_SOME_GCC_WARNINGS
+# pragma GCC diagnostic warning "-Wstrict-prototypes"
+# pragma GCC diagnostic warning "-Wimplicit-function-declaration"
 #endif
 
-RCSID
-    ("$Header$");
+#include <hcrypto/des.h>
 
 #define UBIK_LEGACY_CALLITER 1
 
-#if defined(UKERNEL)
-#include "afs/sysincludes.h"
-#include "afsincludes.h"
-#include "afs_usrops.h"
-#include "afs/stds.h"
-#include "afs/pthread_glock.h"
-#include "rx/rxkad.h"
-#include "afs/cellconfig.h"
-#include "ubik.h"
-#include "afs/auth.h"
-#include "des/des.h"
-#include "afs/afsutil.h"
-
-#include "afs/kauth.h"
-#include "afs/kautils.h"
-#include "afs/pthread_glock.h"
-
-#else /* defined(UKERNEL) */
-#include <afs/stds.h>
 #include <afs/pthread_glock.h>
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <winsock2.h>
-#else
-#include <sys/socket.h>
-#include <netinet/in.h>
-#endif
-#include <string.h>
 #include <rx/rxkad.h>
+#include <rx/rxkad_convert.h>
 #include <afs/cellconfig.h>
 #include <ubik.h>
 #include <afs/auth.h>
-#include <des.h>
 #include <afs/afsutil.h>
+
 #include "kauth.h"
 #include "kautils.h"
-#endif /* defined(UKERNEL) */
 
+#ifdef UKERNEL
+#include "afs_usrops.h"
+#endif
 
 static struct afsconf_dir *conf = 0;
 static struct afsconf_cell explicit_cell_server_list;
@@ -69,13 +49,13 @@ static int debug = 0;
 #ifdef ENCRYPTIONBLOCKSIZE
 #undef ENCRYPTIONBLOCKSIZE
 #endif
-#define ENCRYPTIONBLOCKSIZE (sizeof(des_cblock))
+#define ENCRYPTIONBLOCKSIZE (sizeof(DES_cblock))
 
 /* Copy the specified list of servers into a specially know cell named
    "explicit".  The cell can then be used to debug experimental servers. */
 
 void
-ka_ExplicitCell(char *cell, afs_int32 serverList[])
+ka_ExplicitCell(char *cell, afs_uint32 serverList[])
 {
     int i;
 
@@ -124,8 +104,8 @@ ka_GetServers(char *cell, struct afsconf_cell * cellinfo)
     char cellname[MAXKTCREALMLEN];
 
     LOCK_GLOBAL_MUTEX;
-    if (cell && !strlen(cell))
-       cell = 0;
+    if (cell == NULL || strlen(cell) == 0)
+       cell = NULL;
     else
        cell = lcstring(cellname, cell, sizeof(cellname));
 
@@ -365,12 +345,10 @@ CheckTicketAnswer(ka_BBS * oanswer, afs_int32 challenge,
                  afs_int32 * pwexpires)
 {
     struct ka_ticketAnswer *answer;
-    afs_uint32 cksum;
     unsigned char tempc;
 
     answer = (struct ka_ticketAnswer *)oanswer->SeqBody;
 
-    cksum = ntohl(answer->cksum);
     if (challenge != ntohl(answer->challenge))
        return KABADPROTOCOL;
     memcpy(&token->sessionKey, &answer->sessionKey,
@@ -396,21 +374,26 @@ CheckTicketAnswer(ka_BBS * oanswer, afs_int32 challenge,
        if ((field) && strcmp (field, strings)) return KABADPROTOCOL;\
        strings += len+1
 
+#define chknostr() \
+       len = strlen(strings); \
+       if (len > MAXKTCNAMELEN) return KABADPROTOCOL; \
+       strings += len+1
+
        if (caller) {
            chkstr(caller->name);
            chkstr(caller->instance);
            chkstr(caller->cell);
        } else {
-           chkstr(0);
-           chkstr(0);
-           chkstr(0);
+           chknostr();
+           chknostr();
+           chknostr();
        }
        if (server) {
            chkstr(server->name);
            chkstr(server->instance);
        } else {
-           chkstr(0);
-           chkstr(0);
+           chknostr();
+           chknostr();
        }
 
        if (oanswer->SeqLen -
@@ -450,11 +433,9 @@ CheckTicketAnswer(ka_BBS * oanswer, afs_int32 challenge,
  * this doesn't handle UNOTSYNC very well, should use ubik_Call if you care
  */
 static afs_int32
-kawrap_ubik_Call(aproc, aclient, aflags, p1, p2, p3, p4, p5, p6, p7, p8)
-     struct ubik_client *aclient;
-     int (*aproc) ();
-     afs_int32 aflags;
-     void *p1, *p2, *p3, *p4, *p5, *p6, *p7, *p8;
+kawrap_ubik_Call(int (*aproc) (), struct ubik_client *aclient,
+                 afs_int32 aflags, void *p1, void *p2, void *p3, void *p4,
+                 void *p5, void *p6, void *p7, void *p8)
 {
     afs_int32 code, lcode;
     int count;
@@ -513,7 +494,7 @@ ka_Authenticate(char *name, char *instance, char *cell, struct ubik_client * con
                struct ktc_token * token, afs_int32 * pwexpires)
 {                              /* days until it expires */
     afs_int32 code;
-    des_key_schedule schedule;
+    DES_key_schedule schedule;
     Date request_time;
     struct ka_gettgtRequest request;
     struct ka_gettgtAnswer answer_old;
@@ -525,7 +506,7 @@ ka_Authenticate(char *name, char *instance, char *cell, struct ubik_client * con
     int version;
 
     LOCK_GLOBAL_MUTEX;
-    if ((code = des_key_sched(key, schedule))) {
+    if ((code = DES_key_sched(ktc_to_cblock(key), &schedule))) {
        UNLOCK_GLOBAL_MUTEX;
        return KABADKEY;
     }
@@ -546,8 +527,8 @@ ka_Authenticate(char *name, char *instance, char *cell, struct ubik_client * con
     memcpy(request.label, req_label, sizeof(request.label));
     arequest.SeqLen = sizeof(request);
     arequest.SeqBody = (char *)&request;
-    des_pcbc_encrypt(arequest.SeqBody, arequest.SeqBody, arequest.SeqLen,
-                    schedule, key, ENCRYPT);
+    DES_pcbc_encrypt(arequest.SeqBody, arequest.SeqBody, arequest.SeqLen,
+                    &schedule, ktc_to_cblockptr(key), ENCRYPT);
 
     oanswer.MaxSeqLen = sizeof(answer);
     oanswer.SeqLen = 0;
@@ -556,22 +537,21 @@ ka_Authenticate(char *name, char *instance, char *cell, struct ubik_client * con
     version = 2;
     code =
        kawrap_ubik_Call(KAA_AuthenticateV2, conn, 0, name, instance,
-                        start, end, &arequest, &oanswer, 0, 0);
+                        (void*)(uintptr_t)start, (void*)(uintptr_t)end, &arequest, &oanswer, 0, 0);
     if (code == RXGEN_OPCODE) {
        oanswer.MaxSeqLen = sizeof(answer);
        oanswer.SeqBody = (char *)&answer;
        version = 1;
        code =
-           ubik_Call(KAA_Authenticate, conn, 0, name, instance, start, end,
-                     &arequest, &oanswer, 0, 0);
+           ubik_KAA_Authenticate(conn, 0, name, instance, start, end,
+                                 &arequest, &oanswer);
        if (code == RXGEN_OPCODE) {
-           extern int KAA_Authenticate_old();
            oanswer.MaxSeqLen = sizeof(answer_old);
            oanswer.SeqBody = (char *)&answer_old;
            version = 0;
            code =
-               ubik_Call(KAA_Authenticate_old, conn, 0, name, instance,
-                         start, end, &arequest, &oanswer);
+               ubik_KAA_Authenticate_old(conn, 0, name, instance,
+                                         start, end, &arequest, &oanswer);
        }
        if (code == RXGEN_OPCODE) {
            code = KAOLDINTERFACE;
@@ -583,8 +563,8 @@ ka_Authenticate(char *name, char *instance, char *cell, struct ubik_client * con
            return code;
        return KAUBIKCALL;
     }
-    des_pcbc_encrypt(oanswer.SeqBody, oanswer.SeqBody, oanswer.SeqLen,
-                    schedule, key, DECRYPT);
+    DES_pcbc_encrypt(oanswer.SeqBody, oanswer.SeqBody, oanswer.SeqLen,
+                    &schedule, ktc_to_cblockptr(key), DECRYPT);
 
     switch (version) {
     case 1:
@@ -652,7 +632,7 @@ ka_GetToken(char *name, char *instance, char *cell, char *cname, char *cinst, st
     ka_BBS oanswer;
     char *strings;
     int len;
-    des_key_schedule schedule;
+    DES_key_schedule schedule;
     int version;
     afs_int32 pwexpires;
 
@@ -660,7 +640,7 @@ ka_GetToken(char *name, char *instance, char *cell, char *cname, char *cinst, st
     aticket.SeqLen = auth_token->ticketLen;
     aticket.SeqBody = auth_token->ticket;
 
-    code = des_key_sched(&auth_token->sessionKey, schedule);
+    code = DES_key_sched(ktc_to_cblock(&auth_token->sessionKey), &schedule);
     if (code) {
        UNLOCK_GLOBAL_MUTEX;
        return KABADKEY;
@@ -668,7 +648,8 @@ ka_GetToken(char *name, char *instance, char *cell, char *cname, char *cinst, st
 
     times.start = htonl(start);
     times.end = htonl(end);
-    des_ecb_encrypt(&times, &times, schedule, ENCRYPT);
+    DES_ecb_encrypt((DES_cblock *)&times, (DES_cblock *)&times, &schedule,
+                   ENCRYPT);
 
     atimes.SeqLen = sizeof(times);
     atimes.SeqBody = (char *)&times;
@@ -679,16 +660,15 @@ ka_GetToken(char *name, char *instance, char *cell, char *cname, char *cinst, st
 
     version = 1;
     code =
-       ubik_Call(KAT_GetTicket, conn, 0, auth_token->kvno, auth_domain,
+       ubik_KAT_GetTicket(conn, 0, auth_token->kvno, auth_domain,
                  &aticket, name, instance, &atimes, &oanswer);
     if (code == RXGEN_OPCODE) {
-       extern int KAT_GetTicket_old();
        oanswer.SeqLen = 0;     /* this may be set by first call */
        oanswer.MaxSeqLen = sizeof(answer_old);
        oanswer.SeqBody = (char *)&answer_old;
        version = 0;
        code =
-           ubik_Call(KAT_GetTicket_old, conn, 0, auth_token->kvno,
+           ubik_KAT_GetTicket_old(conn, 0, auth_token->kvno,
                      auth_domain, &aticket, name, instance, &atimes,
                      &oanswer);
        if (code == RXGEN_OPCODE) {
@@ -702,8 +682,9 @@ ka_GetToken(char *name, char *instance, char *cell, char *cname, char *cinst, st
        return KAUBIKCALL;
     }
 
-    des_pcbc_encrypt(oanswer.SeqBody, oanswer.SeqBody, oanswer.SeqLen,
-                    schedule, &auth_token->sessionKey, DECRYPT);
+    DES_pcbc_encrypt(oanswer.SeqBody, oanswer.SeqBody, oanswer.SeqLen,
+                    &schedule, ktc_to_cblockptr(&auth_token->sessionKey),
+                    DECRYPT);
 
     switch (version) {
     case 1:
@@ -795,14 +776,8 @@ ka_ChangePassword(char *name, char *instance, struct ubik_client * conn,   /* Ubik
     afs_int32 code;
 
     LOCK_GLOBAL_MUTEX;
-#if defined(AFS_S390_LINUX20_ENV) && !defined(AFS_S390X_LINUX20_ENV)
-    code =
-       ubik_Call_New(KAM_SetPassword, conn, 0, name, instance, 0, 0,
-                     *newkey);
-#else
     code =
-       ubik_Call_New(KAM_SetPassword, conn, 0, name, instance, 0, *newkey);
-#endif
+       ubik_KAM_SetPassword(conn, UBIK_CALL_NEW, name, instance, 0, *(EncryptionKey *)newkey);
     UNLOCK_GLOBAL_MUTEX;
     return code;
 }