Skip to content

Commit

Permalink
s3-lib: Do not set an empty string in split_domain_user()
Browse files Browse the repository at this point in the history
The function should also return if it failed or not.

Signed-off-by: Andreas Schneider <[email protected]>
Reviewed-by: Stefan Metzmacher <[email protected]>

Autobuild-User(master): Stefan Metzmacher <[email protected]>
Autobuild-Date(master): Sun Sep 25 12:56:17 CEST 2016 on sn-devel-144
  • Loading branch information
cryptomilk authored and metze-samba committed Sep 25, 2016
1 parent 0c4e132 commit 631e063
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source3/include/proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 14 additions & 2 deletions source3/lib/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

/****************************************************************
Expand Down
40 changes: 30 additions & 10 deletions source3/libnet/libnet_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
24 changes: 16 additions & 8 deletions source3/rpc_server/wkssvc/srv_wkssvc_nt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 631e063

Please sign in to comment.