Convert all uint32/16/8 to _t in source3/libsmb.
[bbaumbach/samba-autobuild/.git] / source3 / libsmb / clientgen.c
index 98ea7113a29b531e92a9d12a9eea8122f8c42a9f..166918efc4358c280b12add941968999e36c4b09 100644 (file)
@@ -65,72 +65,13 @@ bool cli_set_backup_intent(struct cli_state *cli, bool flag)
        return old_state;
 }
 
-/****************************************************************************
- Initialize Domain, user or password.
-****************************************************************************/
-
-NTSTATUS cli_set_domain(struct cli_state *cli, const char *domain)
-{
-       TALLOC_FREE(cli->domain);
-       cli->domain = talloc_strdup(cli, domain ? domain : "");
-       if (cli->domain == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       return NT_STATUS_OK;
-}
-
-NTSTATUS cli_set_username(struct cli_state *cli, const char *username)
-{
-       TALLOC_FREE(cli->user_name);
-       cli->user_name = talloc_strdup(cli, username ? username : "");
-       if (cli->user_name == NULL) {
-               return NT_STATUS_NO_MEMORY;
-       }
-       return NT_STATUS_OK;
-}
-
-NTSTATUS cli_set_password(struct cli_state *cli, const char *password)
-{
-       TALLOC_FREE(cli->password);
-
-       /* Password can be NULL. */
-       if (password) {
-               cli->password = talloc_strdup(cli, password);
-               if (cli->password == NULL) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-       } else {
-               /* Use zero NTLMSSP hashes and session key. */
-               cli->password = NULL;
-       }
-
-       return NT_STATUS_OK;
-}
-
-/****************************************************************************
- Initialise credentials of a client structure.
-****************************************************************************/
-
-NTSTATUS cli_init_creds(struct cli_state *cli, const char *username, const char *domain, const char *password)
-{
-       NTSTATUS status = cli_set_username(cli, username);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-       status = cli_set_domain(cli, domain);
-       if (!NT_STATUS_IS_OK(status)) {
-               return status;
-       }
-       DEBUG(10,("cli_init_creds: user %s domain %s\n", cli->user_name, cli->domain));
-
-       return cli_set_password(cli, password);
-}
-
 /****************************************************************************
  Initialise a client structure. Always returns a talloc'ed struct.
  Set the signing state (used from the command line).
 ****************************************************************************/
 
+struct GUID cli_state_client_guid;
+
 struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
                                   int fd,
                                   const char *remote_name,
@@ -144,7 +85,13 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
        bool use_level_II_oplocks = false;
        uint32_t smb1_capabilities = 0;
        uint32_t smb2_capabilities = 0;
-       struct GUID client_guid = GUID_random();
+       struct GUID client_guid;
+
+       if (!GUID_all_zero(&cli_state_client_guid)) {
+               client_guid = cli_state_client_guid;
+       } else {
+               client_guid = GUID_random();
+       }
 
        /* Check the effective uid - make sure we are not setuid */
        if (is_setuid_root()) {
@@ -177,7 +124,6 @@ struct cli_state *cli_state_create(TALLOC_CTX *mem_ctx,
        cli->raw_status = NT_STATUS_INTERNAL_ERROR;
        cli->map_dos_errors = true; /* remove this */
        cli->timeout = CLIENT_TIMEOUT;
-       cli->case_sensitive = false;
 
        /* Set the CLI_FORCE_DOSERR environment variable to test
           client routines using DOS errors instead of STATUS32
@@ -372,7 +318,7 @@ uint16_t cli_state_get_vc_num(struct cli_state *cli)
  Set the PID to use for smb messages. Return the old pid.
 ****************************************************************************/
 
-uint16 cli_setpid(struct cli_state *cli, uint16 pid)
+uint16_t cli_setpid(struct cli_state *cli, uint16 pid)
 {
        uint16_t ret = cli->smb1.pid;
        cli->smb1.pid = pid;
@@ -425,8 +371,29 @@ uint16_t cli_state_set_uid(struct cli_state *cli, uint16_t uid)
 
 bool cli_set_case_sensitive(struct cli_state *cli, bool case_sensitive)
 {
-       bool ret = cli->case_sensitive;
-       cli->case_sensitive = case_sensitive;
+       bool ret;
+       uint32_t fs_attrs;
+       struct smbXcli_tcon *tcon;
+
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               tcon = cli->smb2.tcon;
+       } else {
+               tcon = cli->smb1.tcon;
+       }
+
+       fs_attrs = smbXcli_tcon_get_fs_attributes(tcon);
+       if (fs_attrs & FILE_CASE_SENSITIVE_SEARCH) {
+               ret = true;
+       } else {
+               ret = false;
+       }
+       if (case_sensitive) {
+               fs_attrs |= FILE_CASE_SENSITIVE_SEARCH;
+       } else {
+               fs_attrs &= ~FILE_CASE_SENSITIVE_SEARCH;
+       }
+       smbXcli_tcon_set_fs_attributes(tcon, fs_attrs);
+
        return ret;
 }
 
@@ -460,7 +427,7 @@ struct cli_echo_state {
 
 static void cli_echo_done(struct tevent_req *subreq);
 
-struct tevent_req *cli_echo_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
+struct tevent_req *cli_echo_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
                                 struct cli_state *cli, uint16_t num_echos,
                                 DATA_BLOB data)
 {
@@ -538,7 +505,7 @@ NTSTATUS cli_echo_recv(struct tevent_req *req)
 NTSTATUS cli_echo(struct cli_state *cli, uint16_t num_echos, DATA_BLOB data)
 {
        TALLOC_CTX *frame = talloc_stackframe();
-       struct event_context *ev;
+       struct tevent_context *ev;
        struct tevent_req *req;
        NTSTATUS status = NT_STATUS_OK;
 
@@ -550,7 +517,7 @@ NTSTATUS cli_echo(struct cli_state *cli, uint16_t num_echos, DATA_BLOB data)
                goto fail;
        }
 
-       ev = event_context_init(frame);
+       ev = samba_tevent_context_init(frame);
        if (ev == NULL) {
                status = NT_STATUS_NO_MEMORY;
                goto fail;
@@ -613,7 +580,7 @@ NTSTATUS cli_smb(TALLOC_CTX *mem_ctx, struct cli_state *cli,
         if (smbXcli_conn_has_async_calls(cli->conn)) {
                 return NT_STATUS_INVALID_PARAMETER;
         }
-        ev = tevent_context_init(mem_ctx);
+        ev = samba_tevent_context_init(mem_ctx);
         if (ev == NULL) {
                 goto fail;
         }