s3:rpc_client: Return NTSTATUS for init_samr_CryptPassword()
authorAndreas Schneider <asn@samba.org>
Wed, 29 May 2019 14:22:11 +0000 (16:22 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 26 Jul 2019 01:48:22 +0000 (01:48 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/lib/netapi/user.c
source3/libnet/libnet_join.c
source3/rpc_client/init_samr.c
source3/rpc_client/init_samr.h
source3/rpcclient/cmd_samr.c
source3/utils/net_rpc.c

index 4b66dab2f99ab5dbab1634461c49fa130421849f..2136ef47ee6000149e1ff7a96022cb5643feb8da 100644 (file)
@@ -326,9 +326,12 @@ static NTSTATUS set_user_info_USER_INFO_X(TALLOC_CTX *ctx,
 
                        user_info.info23.info = info21;
 
-                       init_samr_CryptPassword(uX->usriX_password,
-                                               session_key,
-                                               &user_info.info23.password);
+                       status = init_samr_CryptPassword(uX->usriX_password,
+                                                        session_key,
+                                                        &user_info.info23.password);
+                       if (!NT_STATUS_IS_OK(status)) {
+                               return status;
+                       }
 
                        status = dcerpc_samr_SetUserInfo2(b, talloc_tos(),
                                                          user_handle,
index b876d7ea89fb9a9165e100739a91daf9e7227565..4670617d74f1f8f29083f8dae581244faea7d9d8 100644 (file)
@@ -1539,9 +1539,12 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
 
                /* retry with level 24 */
 
-               init_samr_CryptPassword(r->in.machine_password,
-                                       &session_key,
-                                       &crypt_pwd);
+               status = init_samr_CryptPassword(r->in.machine_password,
+                                                &session_key,
+                                                &crypt_pwd);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto error;
+               }
 
                user_info.info24.password = crypt_pwd;
                user_info.info24.password_expired = PASS_DONT_CHANGE_AT_NEXT_LOGON;
@@ -1553,6 +1556,7 @@ static NTSTATUS libnet_join_joindomain_rpc(TALLOC_CTX *mem_ctx,
                                                  &result);
        }
 
+error:
        old_timeout = rpccli_set_timeout(pipe_hnd, old_timeout);
 
        if (!NT_STATUS_IS_OK(status)) {
index d116ece576fff52499594d0869cc051befe4df89..8b41ec2f10f45ec9522c47ec142c97ec041dc0c0 100644 (file)
@@ -81,12 +81,18 @@ out:
  inits a samr_CryptPassword structure
  *************************************************************************/
 
-void init_samr_CryptPassword(const char *pwd,
-                            DATA_BLOB *session_key,
-                            struct samr_CryptPassword *pwd_buf)
+NTSTATUS init_samr_CryptPassword(const char *pwd,
+                                DATA_BLOB *session_key,
+                                struct samr_CryptPassword *pwd_buf)
 {
        /* samr_CryptPassword */
+       bool ok;
 
-       encode_pw_buffer(pwd_buf->data, pwd, STR_UNICODE);
+       ok = encode_pw_buffer(pwd_buf->data, pwd, STR_UNICODE);
+       if (!ok) {
+               return NT_STATUS_INTERNAL_ERROR;
+       }
        arcfour_crypt_blob(pwd_buf->data, 516, session_key);
+
+       return NT_STATUS_OK;
 }
index 223fa91e3d9baeb4e729fe9395211255a715f9d1..4214ab55a0463487f07b2cc94cee6cc804eee428 100644 (file)
@@ -25,8 +25,8 @@
 void init_samr_CryptPasswordEx(const char *pwd,
                               DATA_BLOB *session_key,
                               struct samr_CryptPasswordEx *pwd_buf);
-void init_samr_CryptPassword(const char *pwd,
-                            DATA_BLOB *session_key,
-                            struct samr_CryptPassword *pwd_buf);
+NTSTATUS init_samr_CryptPassword(const char *pwd,
+                                DATA_BLOB *session_key,
+                                struct samr_CryptPassword *pwd_buf);
 
 #endif /* _RPC_CLIENT_INIT_SAMR_H_ */
index 8cbf8ab24bdc78a8f35737e01eeb556cdf1380c6..ccaec1ada407917e51a7f38948548b2592773dbd 100644 (file)
@@ -3063,7 +3063,10 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
                return status;
        }
 
-       init_samr_CryptPassword(param, &session_key, &pwd_buf);
+       status = init_samr_CryptPassword(param, &session_key, &pwd_buf);
+       if (!NT_STATUS_IS_OK(status)) {
+               return status;
+       }
        init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
        nt_lm_owf_gen(param, nt_hash, lm_hash);
 
index a56190f7be51d6ff20fc74b0ef7ee7d406019254..f6fb892a2d9292268a7c77023daf689ba832a9da 100644 (file)
@@ -6195,9 +6195,12 @@ static NTSTATUS rpc_trustdom_add_internals(struct net_context *c,
 
                ZERO_STRUCT(info.info23);
 
-               init_samr_CryptPassword(argv[1],
-                                       &session_key,
-                                       &crypt_pwd);
+               status = init_samr_CryptPassword(argv[1],
+                                                &session_key,
+                                                &crypt_pwd);
+               if (!NT_STATUS_IS_OK(status)) {
+                       goto done;
+               }
 
                info.info23.info.fields_present = SAMR_FIELD_ACCT_FLAGS |
                                                  SAMR_FIELD_NT_PASSWORD_PRESENT;