s4-kdc/db-glue: add principal_comp_str{case}cmp
authorGünther Deschner <gd@samba.org>
Thu, 15 May 2014 13:57:06 +0000 (15:57 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 27 Mar 2015 00:26:16 +0000 (01:26 +0100)
Guenther

Signed-off-by: Günther Deschner <gd@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/kdc/db-glue.c

index 1b663595cba9b36e2833991c5a4fce85bb4c5f84..f12c1f3f705683378781e34307335cad7afbd95b 100644 (file)
@@ -540,6 +540,60 @@ out:
        return ret;
 }
 
+static int principal_comp_strcmp_int(krb5_context context,
+                                    krb5_const_principal principal,
+                                    unsigned int component,
+                                    const char *string,
+                                    bool do_strcasecmp)
+{
+       const char *p;
+       size_t len;
+
+#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING)
+       p = krb5_principal_get_comp_string(context, principal, component);
+       if (p == NULL) {
+               return -1;
+       }
+       len = strlen(p);
+#else
+       krb5_data *d;
+       if (component >= krb5_princ_size(context, principal)) {
+               return -1;
+       }
+
+       d = krb5_princ_component(context, principal, component);
+       if (d == NULL) {
+               return -1;
+       }
+
+       p = d->data;
+       len = d->length;
+#endif
+       if (do_strcasecmp) {
+               return strncasecmp(p, string, len);
+       } else {
+               return strncmp(p, string, len);
+       }
+}
+
+static int principal_comp_strcasecmp(krb5_context context,
+                                    krb5_const_principal principal,
+                                    unsigned int component,
+                                    const char *string)
+{
+       return principal_comp_strcmp_int(context, principal,
+                                        component, string, true);
+}
+
+static int principal_comp_strcmp(krb5_context context,
+                                krb5_const_principal principal,
+                                unsigned int component,
+                                const char *string)
+{
+       return principal_comp_strcmp_int(context, principal,
+                                        component, string, false);
+}
+
 /*
  * Construct an hdb_entry from a directory entry.
  */