lib:krb5_wrap: Implement smb_krb5_principal_is_tgs()
authorAndreas Schneider <asn@samba.org>
Tue, 15 Mar 2022 06:30:03 +0000 (07:30 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 17 Mar 2022 00:41:33 +0000 (00:41 +0000)
This will be used later and allows to remove static implementations.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
lib/krb5_wrap/krb5_samba.c
lib/krb5_wrap/krb5_samba.h

index e9eaddac75de9e80879f86e9e814d855e0d90a47..2351d172779e51175d5936615f016c000686bc27 100644 (file)
@@ -3348,6 +3348,34 @@ void smb_krb5_principal_set_type(krb5_context context,
 #endif
 }
 
+/**
+ * @brief Check if a principal is a TGS
+ *
+ * @param[in]  context  The library context
+ *
+ * @param[inout] principal The principal to check.
+ *
+ * @returns 1 if equal, 0 if not and -1 on error.
+ */
+int smb_krb5_principal_is_tgs(krb5_context context,
+                             krb5_const_principal principal)
+{
+       char *p = NULL;
+       int eq = 1;
+
+       p = smb_krb5_principal_get_comp_string(NULL, context, principal, 0);
+       if (p == NULL) {
+               return -1;
+       }
+
+       eq = krb5_princ_size(context, principal) == 2 &&
+            (strequal(p, KRB5_TGS_NAME));
+
+       talloc_free(p);
+
+       return eq;
+}
+
 #if !defined(HAVE_KRB5_WARNX)
 /**
  * @brief Log a Kerberos message
index c8573f52bd93baf7ba152eab82dcd43d3b3087f6..653cd561406ea4c03fd95c65c37723033c8c4780 100644 (file)
@@ -306,6 +306,9 @@ void smb_krb5_principal_set_type(krb5_context context,
                                 krb5_principal principal,
                                 int type);
 
+int smb_krb5_principal_is_tgs(krb5_context context,
+                             krb5_const_principal principal);
+
 krb5_error_code smb_krb5_principal_set_realm(krb5_context context,
                                             krb5_principal principal,
                                             const char *realm);