svn commit: lorikeet r446 - in trunk/heimdal/lib/krb5: .

abartlet at samba.org abartlet at samba.org
Tue Aug 30 19:52:05 GMT 2005


Author: abartlet
Date: 2005-08-30 19:52:04 +0000 (Tue, 30 Aug 2005)
New Revision: 446

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=lorikeet&rev=446

Log:
Add more principal parsing functions, to try and parse principals
where we explicitly expect and want them to be without a realm.

(I want to use the 'real' krb5 parsing functions in DRSUAPI CrackNames).

Andrew Bartlett

Modified:
   trunk/heimdal/lib/krb5/principal.c
   trunk/heimdal/lib/krb5/test_princ.c


Changeset:
Modified: trunk/heimdal/lib/krb5/principal.c
===================================================================
--- trunk/heimdal/lib/krb5/principal.c	2005-08-29 00:32:59 UTC (rev 445)
+++ trunk/heimdal/lib/krb5/principal.c	2005-08-30 19:52:04 UTC (rev 446)
@@ -91,10 +91,11 @@
     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 @@
 	}
 	*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 @@
     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 @@
     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)

Modified: trunk/heimdal/lib/krb5/test_princ.c
===================================================================
--- trunk/heimdal/lib/krb5/test_princ.c	2005-08-29 00:32:59 UTC (rev 445)
+++ trunk/heimdal/lib/krb5/test_princ.c	2005-08-30 19:52:04 UTC (rev 446)
@@ -107,14 +107,32 @@
 
     ret = krb5_unparse_name_short(context, p, &princ_unparsed);
     if (ret)
-	krb5_err(context, 1, ret, "krb5_parse_name");
+	krb5_err(context, 1, ret, "krb5_unparse_name_short");
 
     if (strcmp(princ, princ_unparsed)) {
 	krb5_errx(context, 1, "%s != %s", princ, princ_unparsed);
     }
     free(princ_unparsed);
 
+    ret = krb5_parse_name_norealm(context, princ, &p2);
+    if (!ret)
+	krb5_err(context, 1, ret, "Should have failed to parse %s a short name", princ);
 
+    ret = krb5_parse_name_norealm(context, princ_short, &p2);
+    if (ret)
+	krb5_err(context, 1, ret, "krb5_parse_name");
+
+    ret = krb5_unparse_name_norealm(context, p2, &princ_unparsed);
+    if (ret)
+	krb5_err(context, 1, ret, "krb5_unparse_name_norealm");
+
+    if (strcmp(princ_short, princ_unparsed)) {
+	krb5_errx(context, 1, "%s != %s", princ_short, princ_unparsed);
+    }
+    free(princ_unparsed);
+
+    
+
     krb5_free_principal(context, p);
 }
 



More information about the samba-cvs mailing list