Linux-6.9: file_lock mbrs moved to file_lock_core
[openafs.git] / src / aklog / krb_util.c
index 3c2eb51..ea66732 100644 (file)
@@ -2,22 +2,19 @@
  * This file replaces some of the routines in the Kerberos utilities.
  * It is based on the Kerberos library modules:
  *     send_to_kdc.c
- * 
+ *
  * Copyright 1987, 1988, 1992 by the Massachusetts Institute of Technology.
  *
  * For copying and distribution information, please see the file
  * <mit-copyright.h>.
  */
 
-#ifndef lint
-static char rcsid_send_to_kdc_c[] =
-"$Id$";
-#endif /* lint */
-
-#if 0
-#include <kerberosIV/mit-copyright.h>
-#endif
+#include <afsconfig.h>
 #include <afs/stds.h>
+
+#include <roken.h>
+
+#define KERBEROS_APPLE_DEPRECATED(x)
 #include "aklog.h"
 #include <krb5.h>
 
@@ -25,22 +22,13 @@ static char rcsid_send_to_kdc_c[] =
 #define MAX_HSTNM 100
 #endif
 
-#ifdef WINDOWS
-
-#include "aklog.h"             /* for struct afsconf_cell */
-
-#else /* !WINDOWS */
-
-#include <afs/param.h>
 #include <afs/cellconfig.h>
 
-#endif /* WINDOWS */
-
-#include <string.h>
+#include <ctype.h>
 
 #define S_AD_SZ sizeof(struct sockaddr_in)
 
-char *afs_realm_of_cell(krb5_context context, struct afsconf_cell *cellconfig)
+char *afs_realm_of_cell(krb5_context context, struct afsconf_cell *cellconfig, int fallback)
 {
     static char krbrlm[REALM_SZ+1];
        char **hrealms = 0;
@@ -48,13 +36,26 @@ char *afs_realm_of_cell(krb5_context context, struct afsconf_cell *cellconfig)
 
     if (!cellconfig)
        return 0;
-    if (retval = krb5_get_host_realm(context,
-                               cellconfig->hostName[0], &hrealms))
-               return 0; 
+
+    if (fallback) {
+       char * p;
+       p = strchr(cellconfig->hostName[0], '.');
+       if (p++)
+           strcpy(krbrlm, p);
+       else
+           strcpy(krbrlm, cellconfig->name);
+       for (p=krbrlm; *p; p++) {
+           if (islower(*p))
+               *p = toupper(*p);
+       }
+    } else {
+       if ((retval = krb5_get_host_realm(context,
+                                        cellconfig->hostName[0], &hrealms)))
+           return 0;
        if(!hrealms[0]) return 0;
        strcpy(krbrlm, hrealms[0]);
 
        if (hrealms) krb5_free_host_realm(context, hrealms);
-    
+    }
     return krbrlm;
 }