}
realm_length = krb5_princ_realm(aname)->length;
- if (!(def_realm = malloc(realm_length + 1)))
- return ENOMEM;
- if (retval = krb5_get_default_realm(realm_length+1,def_realm)) {
- free(def_realm);
- return KRB5_LNAME_NOTRANS;
+ if (retval = krb5_get_default_realm(&def_realm)) {
+ return(retval);
}
- if (strncmp(def_realm, krb5_princ_realm(aname)->data, realm_length)) {
+ if ((realm_length != strlen(def_realm)) ||
+ (memcmp(def_realm, krb5_princ_realm(aname)->data, realm_legth))) {
free(def_realm);
return KRB5_LNAME_NOTRANS;
}
#include <stdio.h>
/*
- 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
+ * 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]
+ *
+ * returns system errors, NOT_ENOUGH_SPACE
*/
/*
extern char *krb5_config_file; /* extern so can be set at
load/runtime */
krb5_error_code
-krb5_get_default_realm(lnsize, lrealm)
-const int lnsize;
-char *lrealm;
+krb5_get_default_realm(lrealm)
+char **lrealm;
{
FILE *config_file;
char realmbuf[BUFSIZ];
- krb5_error_code retval;
+ char *cp;
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;
+ if (fscanf(config_file, "%s", realmbuf) != 1) {
+ fclose(config_file);
+ return( KRB5_CONFIG_BADFORMAT);
}
- (void) fclose(config_file);
- return retval;
+ fclose(config_file);
+ if (!(*lrealm = cp = malloc((unsigned int) strlen(realmbuf) + 1)))
+ return ENOMEM;
+ strcpy(cp, realmbuf);
+ return(0);
}