summaryrefslogtreecommitdiff
path: root/source4/heimdal/lib/krb5
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2005-09-01 23:31:51 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:36:23 -0500
commitad14812b8f036fb47b4817d5ee391416dd9bf567 (patch)
tree6fb0478aee888469cb96842382deba484fab6165 /source4/heimdal/lib/krb5
parent9b905c9f27f6d7d682085036b27b55d26c1f38ee (diff)
downloadsamba-ad14812b8f036fb47b4817d5ee391416dd9bf567.tar.gz
samba-ad14812b8f036fb47b4817d5ee391416dd9bf567.tar.bz2
samba-ad14812b8f036fb47b4817d5ee391416dd9bf567.zip
r9931: Make use of new 'norealm' parsing functions rather than strchr(p '@').
Merge these norealm functions from lorikeet-heimdal. Andrew Bartlett (This used to be commit 6aef275efd7f434f65824eb3dd129c8e5efd8731)
Diffstat (limited to 'source4/heimdal/lib/krb5')
-rw-r--r--source4/heimdal/lib/krb5/krb5-protos.h13
-rw-r--r--source4/heimdal/lib/krb5/principal.c71
2 files changed, 64 insertions, 20 deletions
diff --git a/source4/heimdal/lib/krb5/krb5-protos.h b/source4/heimdal/lib/krb5/krb5-protos.h
index 71d42b43b8..cc619314a3 100644
--- a/source4/heimdal/lib/krb5/krb5-protos.h
+++ b/source4/heimdal/lib/krb5/krb5-protos.h
@@ -2377,6 +2377,12 @@ krb5_parse_name (
const char */*name*/,
krb5_principal */*principal*/);
+krb5_error_code KRB5_LIB_FUNCTION
+krb5_parse_name_norealm (
+ krb5_context /*context*/,
+ const char */*name*/,
+ krb5_principal */*principal*/);
+
const char* KRB5_LIB_FUNCTION
krb5_passwd_result_to_string (
krb5_context /*context*/,
@@ -3430,6 +3436,13 @@ krb5_write_safe_message (
krb5_error_code KRB5_LIB_FUNCTION
krb5_xfree (void */*ptr*/);
+krb5_error_code
+parse_name (
+ krb5_context /*context*/,
+ const char */*name*/,
+ krb5_boolean /*short_form*/,
+ krb5_principal */*principal*/);
+
#ifdef __cplusplus
}
#endif
diff --git a/source4/heimdal/lib/krb5/principal.c b/source4/heimdal/lib/krb5/principal.c
index 74db080ab7..8540636403 100644
--- a/source4/heimdal/lib/krb5/principal.c
+++ b/source4/heimdal/lib/krb5/principal.c
@@ -91,10 +91,11 @@ krb5_principal_get_comp_string(krb5_context context,
return princ_ncomp(principal, component);
}
-krb5_error_code KRB5_LIB_FUNCTION
-krb5_parse_name(krb5_context context,
- const char *name,
- krb5_principal *principal)
+krb5_error_code
+parse_name(krb5_context context,
+ const char *name,
+ krb5_boolean short_form,
+ krb5_principal *principal)
{
krb5_error_code ret;
heim_general_string *comp;
@@ -184,19 +185,29 @@ krb5_parse_name(krb5_context context,
}
*q++ = c;
}
- if(got_realm){
- realm = malloc(q - start + 1);
- if (realm == NULL) {
- krb5_set_error_string (context, "malloc: out of memory");
- ret = ENOMEM;
+ if (got_realm) {
+ if (short_form) {
+ krb5_set_error_string (context, "realm found in 'short' principal expected to be without one!");
+ ret = KRB5_PARSE_MALFORMED;
goto exit;
+ } else {
+ realm = malloc(q - start + 1);
+ if (realm == NULL) {
+ krb5_set_error_string (context, "malloc: out of memory");
+ ret = ENOMEM;
+ goto exit;
+ }
+ memcpy(realm, start, q - start);
+ realm[q - start] = 0;
}
- memcpy(realm, start, q - start);
- realm[q - start] = 0;
}else{
- ret = krb5_get_default_realm (context, &realm);
- if (ret)
- goto exit;
+ if (short_form) {
+ ret = krb5_get_default_realm (context, &realm);
+ if (ret)
+ goto exit;
+ } else {
+ realm = NULL;
+ }
comp[n] = malloc(q - start + 1);
if (comp[n] == NULL) {
@@ -229,6 +240,21 @@ exit:
return ret;
}
+krb5_error_code KRB5_LIB_FUNCTION
+krb5_parse_name(krb5_context context,
+ const char *name,
+ krb5_principal *principal)
+{
+ return parse_name(context, name, FALSE, principal);
+}
+
+krb5_error_code KRB5_LIB_FUNCTION
+krb5_parse_name_norealm(krb5_context context,
+ const char *name,
+ krb5_principal *principal)
+{
+ return parse_name(context, name, TRUE, principal);
+}
static const char quotable_chars[] = " \n\t\b\\/@";
static const char replace_chars[] = " ntb\\/@";
@@ -323,12 +349,17 @@ unparse_name(krb5_context context,
int i;
krb5_error_code ret;
/* count length */
- plen = strlen(princ_realm(principal));
- if(strcspn(princ_realm(principal), quotable_chars) == plen)
- len += plen;
- else
- len += 2*plen;
- len++;
+ if (!short_flag) {
+ plen = strlen(princ_realm(principal));
+ if(strcspn(princ_realm(principal), quotable_chars) == plen)
+ len += plen;
+ else
+ len += 2*plen;
+ len++;
+ } else {
+ len = 0;
+ }
+
for(i = 0; i < princ_num_comp(principal); i++){
plen = strlen(princ_ncomp(principal, i));
if(strcspn(princ_ncomp(principal, i), quotable_chars) == plen)