*** empty log message ***
authorJohn Kohl <jtkohl@mit.edu>
Mon, 22 Jan 1990 13:29:40 +0000 (13:29 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Mon, 22 Jan 1990 13:29:40 +0000 (13:29 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@164 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/os/def_realm.c [new file with mode: 0644]

diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c
new file mode 100644 (file)
index 0000000..a4a45e0
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * krb5_get_default_realm() function.
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_def_realm_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+
+#include <krb5/krb5.h>
+#include <krb5/krb5_err.h>
+
+#include <stdio.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#else
+extern char *malloc(), *index(), *calloc();
+#endif /* __STDC__ */
+
+/*
+ Retrieves the default realm to be used if no user-specified realm is
+ available.  [e.g. to interpret a user-typed principal name with the
+ realm omitted for convenience]
+
+ lnsize specifies the maximum length name that is to be filled into
+ lrealm.
+
+ returns system errors, NOT_ENOUGH_SPACE
+*/
+
+/*
+ * Implementation:  the default realm is stored in a configuration file,
+ * named by krb5_config_file;  the first token in this file is taken as
+ * the default local realm name.
+ */
+
+extern char *krb5_config_file;         /* extern so can be set at
+                                          load/runtime */
+krb5_error_code
+krb5_get_default_realm(lnsize, lrealm)
+int lnsize;
+char *lrealm;
+{
+    FILE *config_file;
+    char realmbuf[BUFSIZ];
+    krb5_error_code retval;
+
+    if (!(config_file = fopen(krb5_config_file, "r")))
+       /* can't open */
+       return KRB5_CONFIG_CANTOPEN;
+
+    if (fscanf(config_file, "%s", realmbuf) != 1)
+       retval = KRB5_CONFIG_BADFORMAT;
+    else {
+       strncpy(lrealm, realmbuf, lnsize);
+       if (lnsize < strlen(realmbuf))
+           retval = KRB5_CONFIG_NOTENUFSPACE;
+       else
+           retval = 0;
+    }
+    (void) fclose(config_file);
+    return retval;
+}