s3-lib: Do not set an empty string in split_domain_user()
authorAndreas Schneider <asn@samba.org>
Tue, 20 Sep 2016 17:51:15 +0000 (19:51 +0200)
committerStefan Metzmacher <metze@samba.org>
Sun, 25 Sep 2016 10:56:17 +0000 (12:56 +0200)
The function should also return if it failed or not.

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Sun Sep 25 12:56:17 CEST 2016 on sn-devel-144

source3/include/proto.h
source3/lib/util.c
source3/libnet/libnet_join.c
source3/rpc_server/wkssvc/srv_wkssvc_nt.c

index 0aa1009b4ebbe93519067ae5a1f9314ffaf809a2..fe4217d93ef4e3e867578ae753b86e1a1cccd2d4 100644 (file)
@@ -424,7 +424,7 @@ char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off);
 char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off);
 int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval);
 int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval);
-void split_domain_user(TALLOC_CTX *mem_ctx,
+bool split_domain_user(TALLOC_CTX *mem_ctx,
                       const char *full_name,
                       char **domain,
                       char **user);
index ad3362423b41279c192c72853f1da5ea3562dced..bab399824bf811f34fba93ac75c2f6d71e5d0068 100644 (file)
@@ -2103,7 +2103,7 @@ int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, i
  call (they take care of winbind separator and other winbind specific settings).
 ****************************************************************/
 
-void split_domain_user(TALLOC_CTX *mem_ctx,
+bool split_domain_user(TALLOC_CTX *mem_ctx,
                       const char *full_name,
                       char **domain,
                       char **user)
@@ -2115,11 +2115,23 @@ void split_domain_user(TALLOC_CTX *mem_ctx,
        if (p != NULL) {
                *domain = talloc_strndup(mem_ctx, full_name,
                                         PTR_DIFF(p, full_name));
+               if (*domain == NULL) {
+                       return false;
+               }
                *user = talloc_strdup(mem_ctx, p+1);
+               if (*user == NULL) {
+                       TALLOC_FREE(*domain);
+                       return false;
+               }
        } else {
-               *domain = talloc_strdup(mem_ctx, "");
+               *domain = NULL;
                *user = talloc_strdup(mem_ctx, full_name);
+               if (*user == NULL) {
+                       return false;
+               }
        }
+
+       return true;
 }
 
 /****************************************************************
index 3d66eaf6dd5dd3817fe1bf49eef98cfd23952281..bbbd06e1187b7f542201d83f6d936650d051df08 100644 (file)
@@ -2131,11 +2131,21 @@ static WERROR libnet_join_pre_processing(TALLOC_CTX *mem_ctx,
        if (!r->in.admin_domain) {
                char *admin_domain = NULL;
                char *admin_account = NULL;
-               split_domain_user(mem_ctx,
-                                 r->in.admin_account,
-                                 &admin_domain,
-                                 &admin_account);
-               r->in.admin_domain = admin_domain;
+               bool ok;
+
+               ok = split_domain_user(mem_ctx,
+                                      r->in.admin_account,
+                                      &admin_domain,
+                                      &admin_account);
+               if (!ok) {
+                       return WERR_NOMEM;
+               }
+
+               if (admin_domain != NULL) {
+                       r->in.admin_domain = admin_domain;
+               } else {
+                       r->in.admin_domain = r->in.domain_name;
+               }
                r->in.admin_account = admin_account;
        }
 
@@ -2814,11 +2824,21 @@ static WERROR libnet_unjoin_pre_processing(TALLOC_CTX *mem_ctx,
        if (!r->in.admin_domain) {
                char *admin_domain = NULL;
                char *admin_account = NULL;
-               split_domain_user(mem_ctx,
-                                 r->in.admin_account,
-                                 &admin_domain,
-                                 &admin_account);
-               r->in.admin_domain = admin_domain;
+               bool ok;
+
+               ok = split_domain_user(mem_ctx,
+                                      r->in.admin_account,
+                                      &admin_domain,
+                                      &admin_account);
+               if (!ok) {
+                       return WERR_NOMEM;
+               }
+
+               if (admin_domain != NULL) {
+                       r->in.admin_domain = admin_domain;
+               } else {
+                       r->in.admin_domain = r->in.domain_name;
+               }
                r->in.admin_account = admin_account;
        }
 
index 52809a439f5a99c704864827540778119c6d8080..25233e5b07e40df5c81d9e50be1d8f7d85e07f65 100644 (file)
@@ -825,6 +825,7 @@ WERROR _wkssvc_NetrJoinDomain2(struct pipes_struct *p,
        struct security_token *token = p->session_info->security_token;
        NTSTATUS status;
        DATA_BLOB session_key;
+       bool ok;
 
        if (!r->in.domain_name) {
                return WERR_INVALID_PARAM;
@@ -863,10 +864,13 @@ WERROR _wkssvc_NetrJoinDomain2(struct pipes_struct *p,
                return werr;
        }
 
-       split_domain_user(p->mem_ctx,
-                         r->in.admin_account,
-                         &admin_domain,
-                         &admin_account);
+       ok = split_domain_user(p->mem_ctx,
+                              r->in.admin_account,
+                              &admin_domain,
+                              &admin_account);
+       if (!ok) {
+               return WERR_NOMEM;
+       }
 
        werr = libnet_init_JoinCtx(p->mem_ctx, &j);
        if (!W_ERROR_IS_OK(werr)) {
@@ -913,6 +917,7 @@ WERROR _wkssvc_NetrUnjoinDomain2(struct pipes_struct *p,
        struct security_token *token = p->session_info->security_token;
        NTSTATUS status;
        DATA_BLOB session_key;
+       bool ok;
 
        if (!r->in.account || !r->in.encrypted_password) {
                return WERR_INVALID_PARAM;
@@ -942,10 +947,13 @@ WERROR _wkssvc_NetrUnjoinDomain2(struct pipes_struct *p,
                return werr;
        }
 
-       split_domain_user(p->mem_ctx,
-                         r->in.account,
-                         &admin_domain,
-                         &admin_account);
+       ok = split_domain_user(p->mem_ctx,
+                              r->in.account,
+                              &admin_domain,
+                              &admin_account);
+       if (!ok) {
+               return WERR_NOMEM;
+       }
 
        werr = libnet_init_UnjoinCtx(p->mem_ctx, &u);
        if (!W_ERROR_IS_OK(werr)) {