s3:libads: keep service and hostname separately in ads_service_principal
authorStefan Metzmacher <metze@samba.org>
Wed, 2 Mar 2016 10:33:04 +0000 (11:33 +0100)
committerStefan Metzmacher <metze@samba.org>
Mon, 28 Mar 2016 22:41:31 +0000 (00:41 +0200)
Caller will use them instead of the full principal in future.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=11804

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Günther Deschner <gd@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from commit c5d7956364047925dee5d6f71a5b92a38c73e5a6)

source3/libads/sasl.c

index 65d3cc1e034106adc57b2d63f6eb414a04d671dd..5d47fd47439cffc0a1e3543aeead210ed8310138 100644 (file)
@@ -742,14 +742,18 @@ failed:
 
 #ifdef HAVE_KRB5
 struct ads_service_principal {
-        char *string;
+       char *service;
+       char *hostname;
+       char *string;
 #ifdef HAVE_KRB5
-        gss_name_t name;
+       gss_name_t name;
 #endif
 };
 
 static void ads_free_service_principal(struct ads_service_principal *p)
 {
+       SAFE_FREE(p->service);
+       SAFE_FREE(p->hostname);
        SAFE_FREE(p->string);
 
 #ifdef HAVE_KRB5
@@ -761,9 +765,10 @@ static void ads_free_service_principal(struct ads_service_principal *p)
        ZERO_STRUCTP(p);
 }
 
-
-static ADS_STATUS ads_guess_service_principal(ADS_STRUCT *ads,
-                                             char **returned_principal)
+static ADS_STATUS ads_guess_target(ADS_STRUCT *ads,
+                                  char **service,
+                                  char **hostname,
+                                  char **principal)
 {
        ADS_STATUS status = ADS_ERROR(LDAP_NO_MEMORY);
        char *princ = NULL;
@@ -843,13 +848,26 @@ static ADS_STATUS ads_guess_service_principal(ADS_STRUCT *ads,
                goto out;
        }
 
+       *service = SMB_STRDUP("ldap");
+       if (*service == NULL) {
+               status = ADS_ERROR(LDAP_PARAM_ERROR);
+               goto out;
+       }
+       *hostname = SMB_STRDUP(server);
+       if (*hostname == NULL) {
+               SAFE_FREE(*service);
+               status = ADS_ERROR(LDAP_PARAM_ERROR);
+               goto out;
+       }
        rc = asprintf(&princ, "ldap/%s@%s", server, realm);
        if (rc == -1 || princ == NULL) {
+               SAFE_FREE(*service);
+               SAFE_FREE(*hostname);
                status = ADS_ERROR(LDAP_PARAM_ERROR);
                goto out;
        }
 
-       *returned_principal = princ;
+       *principal = princ;
 
        status = ADS_SUCCESS;
 out:
@@ -872,7 +890,10 @@ static ADS_STATUS ads_generate_service_principal(ADS_STRUCT *ads,
 
        ZERO_STRUCTP(p);
 
-       status = ads_guess_service_principal(ads, &p->string);
+       status = ads_guess_target(ads,
+                                 &p->service,
+                                 &p->hostname,
+                                 &p->string);
        if (!ADS_ERR_OK(status)) {
                return status;
        }