test-heimdal-20060217
[openafs.git] / src / aklog / aklog_main.c
index b887aea..c5add33 100644 (file)
@@ -10,6 +10,7 @@ static char *rcsid =
        "$Id$";
 #endif /* lint || SABER */
 
+#include <afsconfig.h>
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
@@ -70,7 +71,9 @@ u_long ntohl(u_long x)
 
 #else /* !WINDOWS */
 #include <afs/stds.h>
+#ifndef HAVE_KERBEROSV_HEIM_ERR_H
 #include <afs/com_err.h>
+#endif
 
 #include <afs/param.h>
 #ifdef AFS_SUN5_ENV
@@ -81,6 +84,7 @@ u_long ntohl(u_long x)
 #include <afs/vice.h>
 #include <afs/venus.h>
 #include <afs/ptserver.h>
+#include <afs/ptuser.h>
 #include <afs/dirpath.h>
 #endif /* WINDOWS */
 
@@ -161,6 +165,48 @@ static krb5_error_code get_credv5(krb5_context context, char *, char *,
                                  char *, krb5_creds **);
 static int get_user_realm(krb5_context, char *);
 
+#if defined(HAVE_KRB5_PRINC_SIZE) || defined(krb5_princ_size)
+
+#define get_princ_str(c, p, n) krb5_princ_component(c, p, n)->data
+#define get_princ_len(c, p, n) krb5_princ_component(c, p, n)->length
+#define second_comp(c, p) (krb5_princ_size(c, p) > 1)
+#define realm_data(c, p) krb5_princ_realm(c, p)->data
+#define realm_len(c, p) krb5_princ_realm(c, p)->length
+
+#elif defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING)
+
+#define get_princ_str(c, p, n) krb5_principal_get_comp_string(c, p, n)
+#define get_princ_len(c, p, n) strlen(krb5_principal_get_comp_string(c, p, n))
+#define second_comp(c, p) (krb5_principal_get_comp_string(c, p, 1) != NULL)
+#define realm_data(c, p) krb5_realm_data(krb5_principal_get_realm(c, p))
+#define realm_len(c, p) krb5_realm_length(krb5_principal_get_realm(c, p))
+
+#else
+#error "Must have either krb5_princ_size or krb5_principal_get_comp_string"
+#endif
+
+#if defined(HAVE_KRB5_CREDS_KEYBLOCK)
+
+#define get_cred_keydata(c) c->keyblock.contents
+#define get_cred_keylen(c) c->keyblock.length
+#define get_creds_enctype(c) c->keyblock.enctype
+
+#elif defined(HAVE_KRB5_CREDS_SESSION)
+
+#define get_cred_keydata(c) c->session.keyvalue.data
+#define get_cred_keylen(c) c->session.keyvalue.length
+#define get_creds_enctype(c) c->session.keytype
+
+#else
+#error "Must have either keyblock or session member of krb5_creds"
+#endif
+
+#if !defined(HAVE_KRB5_524_CONVERT_CREDS) && defined(HAVE_KRB524_CONVERT_CREDS_KDC)
+#define krb5_524_convert_creds krb524_convert_creds_kdc
+#elif !defined(HAVE_KRB5_524_CONVERT_CREDS) && !defined(HAVE_KRB524_CONVERT_CREDS_KDC)
+#error "You must have one of krb5_524_convert_creds or krb524_convert_creds_kdc available"
+#endif
+
 #endif /* WINDOWS */
 
 /*
@@ -217,7 +263,6 @@ static int get_cellconfig(char *cell, struct afsconf_cell *cellconfig, char *loc
 {
     int status = AKLOG_SUCCESS;
     struct afsconf_dir *configdir;
-    char *dirpath;
 
     memset(local_cell, 0, sizeof(local_cell));
     memset((char *)cellconfig, 0, sizeof(*cellconfig));
@@ -350,19 +395,11 @@ cm_SearchCellFile_CallBack(void *rock /* cellconfig */,
  * doing anything.  Otherwise, log to it and mark that it has been logged
  * to.
  */
-#ifdef __STDC__
 static int auth_to_cell(krb5_context context, char *cell, char *realm)
-#else
-static int auth_to_cell(context, cell, realm)
-
-  krb5_context context;
-  char *cell;
-  char *realm;
-#endif /* __STDC__ */
 {
     int status = AKLOG_SUCCESS;
     char username[BUFSIZ];     /* To hold client username structure */
-    long viceId;               /* AFS uid of user */
+    afs_int32 viceId;          /* AFS uid of user */
 
     char name[ANAME_SZ];       /* Name of afs key */
     char primary_instance[INST_SZ];    /* Instance of afs key */
@@ -546,7 +583,7 @@ static int auth_to_cell(context, cell, realm)
            }
        }
 
-       if (status != KSUCCESS) {
+       if (status) {
            if (dflag) {
                printf("Kerberos error code returned by get_cred: %d\n",
                        status);
@@ -574,18 +611,18 @@ static int auth_to_cell(context, cell, realm)
            if (dflag)
                printf("Using Kerberos V5 ticket natively\n");
 
-           len = min(v5cred->client->data[0].length,
-                     v5cred->client->length > 1 ? MAXKTCNAMELEN - 2 :
-                     MAXKTCNAMELEN - 1);
-           strncpy(username, v5cred->client->data[0].data, len);
+           len = min(get_princ_len(context, v5cred->client, 0),
+                     second_comp(context, v5cred->client) ?
+                                       MAXKTCNAMELEN - 2 : MAXKTCNAMELEN - 1);
+           strncpy(username, get_princ_str(context, v5cred->client, 0), len);
            username[len] = '\0';
 
-           if (v5cred->client->length > 1) {
+           if (second_comp(context, v5cred->client)) {
                strcat(username, ".");
                p = username + strlen(username);
-               len = min(v5cred->client->data[1].length,
+               len = min(get_princ_len(context, v5cred->client, 1),
                          MAXKTCNAMELEN - strlen(username) - 1);
-               strncpy(p, v5cred->client->data[1].data, len);
+               strncpy(p, get_princ_str(context, v5cred->client, 1), len);
                p[len] = '\0';
            }
 
@@ -593,8 +630,8 @@ static int auth_to_cell(context, cell, realm)
            atoken.kvno = RXKAD_TKT_TYPE_KERBEROS_V5;
            atoken.startTime = v5cred->times.starttime;;
            atoken.endTime = v5cred->times.endtime;
-           memcpy(&atoken.sessionKey, v5cred->keyblock.contents,
-                  v5cred->keyblock.length);
+           memcpy(&atoken.sessionKey, get_cred_keydata(v5cred),
+                  get_cred_keylen(v5cred));
            atoken.ticketLen = v5cred->ticket.length;
            memcpy(atoken.ticket, v5cred->ticket.data, atoken.ticketLen);
        } else {
@@ -660,7 +697,7 @@ static int auth_to_cell(context, cell, realm)
 #ifndef WINDOWS
        }
        else {
-           if ((status = get_user_realm(context, realm_of_user)) != KSUCCESS) {
+           if ((status = get_user_realm(context, realm_of_user))) {
                fprintf(stderr, "%s: Couldn't determine realm of user:)",
                        progname);
                com_err(progname, status, " while getting realm");
@@ -678,7 +715,7 @@ static int auth_to_cell(context, cell, realm)
 
            strcpy(lastcell, aserver.cell);
 
-           if (!pr_Initialize (0, confname, aserver.cell, 0))
+           if (!pr_Initialize (0, confname, aserver.cell))
                    status = pr_SNameToId (username, &viceId);
            
            if (dflag) {
@@ -733,7 +770,7 @@ static int auth_to_cell(context, cell, realm)
                 * level
                 */
 
-               if ((status = pr_Initialize(1L, confname, aserver.cell, 0))) {
+               if ((status = pr_Initialize(1L, confname, aserver.cell))) {
                    printf("Error %d\n", status);
                }
 
@@ -818,14 +855,7 @@ static int auth_to_cell(context, cell, realm)
 
 #ifndef WINDOWS /* struct ViceIoctl missing */
 
-#ifdef __STDC__
 static int get_afs_mountpoint(char *file, char *mountpoint, int size)
-#else
-static int get_afs_mountpoint(file, mountpoint, size)
-  char *file;
-  char *mountpoint;
-  int size;
-#endif /* __STDC__ */
 {
 #ifdef AFS_SUN_ENV
        char V ='V'; /* AFS has problem on Sun with pioctl */
@@ -882,12 +912,7 @@ static int get_afs_mountpoint(file, mountpoint, size)
  * to be descended.  After that, it should be called with the arguemnt
  * NULL.
  */
-#ifdef __STDC__
 static char *next_path(char *origpath)
-#else
-static char *next_path(origpath)
-  char *origpath;
-#endif /* __STDC__ */
 {
     static char path[MAXPATHLEN + 1];
     static char pathtocheck[MAXPATHLEN + 1];
@@ -926,8 +951,8 @@ static char *next_path(origpath)
            ? elast_comp - last_comp : strlen(last_comp);
        strncat(pathtocheck, last_comp, len);
        memset(linkbuf, 0, sizeof(linkbuf));
-       if ((link = readlink(pathtocheck, linkbuf, 
-                                   sizeof(linkbuf))) > 0) {
+       if (link = (readlink(pathtocheck, linkbuf, 
+                                   sizeof(linkbuf)) > 0)) {
            if (++symlinkcount > MAXSYMLINKS) {
                fprintf(stderr, "%s: %s\n", progname, strerror(ELOOP));
                exit(AKLOG_BADPATH);
@@ -1005,12 +1030,7 @@ int dee_gettokens()
 
 #ifndef WINDOWS /* struct ViceIoctl missing */
 
-#ifdef __STDC__
 static void add_hosts(char *file)
-#else
-static void add_hosts(file)
-  char *file;
-#endif /* __STDC__ */
 {
 #ifdef AFS_SUN_ENV
        char V = 'V'; /* AFS has problem on SunOS */
@@ -1077,13 +1097,7 @@ static void add_hosts(file)
  * This routine descends through a path to a directory, logging to 
  * every cell it encounters along the way.
  */
-#ifdef __STDC__
 static int auth_to_path(krb5_context context, char *path)
-#else
-static int auth_to_path(context, path)
-  krb5_context context;
-  char *path;                  /* The path to which we try to authenticate */
-#endif /* __STDC__ */
 {
     int status = AKLOG_SUCCESS;
     int auth_to_cell_status = AKLOG_SUCCESS;
@@ -1101,7 +1115,7 @@ static int auth_to_path(context, path)
     if (path[0] == DIR)
        strcpy(pathtocheck, path);
     else {
-       if (getwd(pathtocheck) == NULL) {
+       if (getcwd(pathtocheck, sizeof(pathtocheck)) == NULL) {
            fprintf(stderr, "Unable to find current working directory:\n");
            fprintf(stderr, "%s\n", pathtocheck);
            fprintf(stderr, "Try an absolute pathname.\n");
@@ -1170,11 +1184,7 @@ static int auth_to_path(context, path)
 
 
 /* Print usage message and exit */
-#ifdef __STDC__
 static void usage(void)
-#else
-static void usage()
-#endif /* __STDC__ */
 {
     fprintf(stderr, "\nUsage: %s %s%s%s\n", progname,
            "[-d] [[-cell | -c] cell [-k krb_realm]] ",
@@ -1514,14 +1524,19 @@ void aklog(int argc, char *argv[])
 }
 
 #ifndef HAVE_ADD_TO_ERROR_TABLE
+
+#define error_table error_table_compat
 #include <afs/error_table.h>
+#undef error_table
 
+#ifndef HAVE_ADD_ERROR_TABLE
 void add_error_table (const struct error_table *);
+#endif /* !HAVE_ADD_ERROR_TABLE */
 
 void
 add_to_error_table(struct et_list *new_table)
 {
-       add_error_table(new_table->table);
+       add_error_table((struct error_table *) new_table->table);
 }
 #endif /* HAVE_ADD_TO_ERROR_TABLE */
 
@@ -1572,7 +1587,7 @@ static krb5_error_code get_credv5(krb5_context context,
     increds.client = client_principal;
     increds.times.endtime = 0;
        /* Ask for DES since that is what V4 understands */
-    increds.keyblock.enctype = ENCTYPE_DES_CBC_CRC;
+    get_creds_enctype((&increds)) = ENCTYPE_DES_CBC_CRC;
 
     r = krb5_get_credentials(context, 0, _krb425_ccache, &increds, creds);
 
@@ -1590,9 +1605,10 @@ static int get_user_realm(krb5_context context, char *realm)
     if (!client_principal)
         krb5_cc_get_principal(context, _krb425_ccache, &client_principal);
 
-    i = krb5_princ_realm(context, client_principal)->length;
+    i = realm_len(context, client_principal);
     if (i > REALM_SZ-1) i = REALM_SZ-1;
-    strncpy(realm,krb5_princ_realm(context, client_principal)->data,i);
+    strncpy(realm,realm_data(context, client_principal), i);
     realm[i] = 0;
-    return(KSUCCESS);
+
+    return(0);
 }