lib/krb5_wrap: add smb_krb5_principal_get_comp_string().
authorGünther Deschner <gd@samba.org>
Wed, 30 Apr 2014 08:49:14 +0000 (10:49 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 8 Aug 2014 04:02:34 +0000 (06:02 +0200)
Guenther

Signed-off-by: Günther Deschner <gd@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
lib/krb5_wrap/krb5_samba.c
lib/krb5_wrap/krb5_samba.h

index 84a62a690614ba09a4f5e084c39413f784536bdf..ec44f9ade2671dea9004f00fe0c253d0f990838d 100644 (file)
@@ -871,6 +871,43 @@ done:
 }
 #endif
 
+/*
+ * @brief Get talloced string component of a principal
+ *
+ * @param[in] mem_ctx          The TALLOC_CTX
+ * @param[in] context          The krb5_context
+ * @param[in] principal                The principal
+ * @param[in] component                The component
+ * @return string component
+ *
+ * Caller must talloc_free if the return value is not NULL.
+ *
+ */
+
+/* caller has to free returned string with free() */
+char *smb_krb5_principal_get_comp_string(TALLOC_CTX *mem_ctx,
+                                        krb5_context context,
+                                        krb5_const_principal principal,
+                                        unsigned int component)
+{
+#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING)
+       return talloc_strdup(mem_ctx, krb5_principal_get_comp_string(context, principal, component));
+#else
+       krb5_data *data;
+
+       if (component >= krb5_princ_size(context, principal)) {
+               return NULL;
+       }
+
+       data = krb5_princ_component(context, principal, component);
+       if (data == NULL) {
+               return NULL;
+       }
+
+       return talloc_strndup(mem_ctx, data->data, data->length);
+#endif
+}
+
 /* Prototypes */
 
  krb5_error_code smb_krb5_renew_ticket(const char *ccache_string,      /* FILE:/tmp/krb5cc_0 */
index f5a2daa07768ccf5e8fd2081ed8799b55e16210b..5a3d20e1b8e38949ff148fe720051071e15ec3b7 100644 (file)
@@ -316,6 +316,11 @@ krb5_boolean smb_krb5_get_allowed_weak_crypto(krb5_context context);
 #endif
 #endif
 
+char *smb_krb5_principal_get_comp_string(TALLOC_CTX *mem_ctx,
+                                        krb5_context context,
+                                        krb5_const_principal principal,
+                                        unsigned int component);
+
 #endif /* HAVE_KRB5 */
 
 int cli_krb5_get_ticket(TALLOC_CTX *mem_ctx,