lib: remove unused function nttime_from_string()
[bbaumbach/samba-autobuild/.git] / source3 / libsmb / clirap.c
index 7e6f8d74ba4620ba4e6bc4032611e995aeb309ab..e80dfc92a77b0bd2dd6c614e6f05d2f24dda8e1e 100644 (file)
@@ -29,6 +29,7 @@
 #include "libsmb/clirap.h"
 #include "trans2.h"
 #include "../libcli/smb/smbXcli_base.h"
+#include "cli_smb2_fnum.h"
 
 #define PIPE_LANMAN   "\\PIPE\\LANMAN"
 
@@ -67,14 +68,14 @@ bool cli_api(struct cli_state *cli,
         * talloc
         */
 
-       *rparam = (char *)memdup(my_rparam, num_my_rparam);
+       *rparam = (char *)smb_memdup(my_rparam, num_my_rparam);
        if (*rparam == NULL) {
                goto fail;
        }
        *rprcnt = num_my_rparam;
        TALLOC_FREE(my_rparam);
 
-       *rdata = (char *)memdup(my_rdata, num_my_rdata);
+       *rdata = (char *)smb_memdup(my_rdata, num_my_rdata);
        if (*rdata == NULL) {
                goto fail;
        }
@@ -165,7 +166,7 @@ bool cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation)
  Call a NetShareEnum - try and browse available connections on a host.
 ****************************************************************************/
 
-int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state)
+int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32_t, const char *, void *), void *state)
 {
        char *rparam = NULL;
        char *rdata = NULL;
@@ -272,8 +273,8 @@ int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, co
  the comment and a state pointer.
 ****************************************************************************/
 
-bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
-                      void (*fn)(const char *, uint32, const char *, void *),
+bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32_t stype,
+                      void (*fn)(const char *, uint32_t, const char *, void *),
                       void *state)
 {
        char *rparam = NULL;
@@ -284,7 +285,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
        char param[1024];
        int uLevel = 1;
        size_t len;
-       uint32 func = RAP_NetServerEnum2;
+       uint32_t func = RAP_NetServerEnum2;
        char *last_entry = NULL;
        int total_cnt = 0;
        int return_cnt = 0;
@@ -327,7 +328,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                sizeof(param) - PTR_DIFF(p,param) - 1,
                                STR_TERMINATE|STR_UPPER);
 
-               if (len == (size_t)-1) {
+               if (len == 0) {
                        SAFE_FREE(last_entry);
                        return false;
                }
@@ -339,7 +340,7 @@ bool cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
                                        sizeof(param) - PTR_DIFF(p,param) - 1,
                                        STR_TERMINATE);
 
-                       if (len == (size_t)-1) {
+                       if (len == 0) {
                                SAFE_FREE(last_entry);
                                return false;
                        }
@@ -626,7 +627,7 @@ NTSTATUS cli_qpathinfo1_recv(struct tevent_req *req,
                             time_t *access_time,
                             time_t *write_time,
                             off_t *size,
-                            uint16 *mode)
+                            uint16_t *mode)
 {
        struct cli_qpathinfo1_state *state = tevent_req_data(
                req, struct cli_qpathinfo1_state);
@@ -668,7 +669,7 @@ NTSTATUS cli_qpathinfo1(struct cli_state *cli,
                        time_t *access_time,
                        time_t *write_time,
                        off_t *size,
-                       uint16 *mode)
+                       uint16_t *mode)
 {
        TALLOC_CTX *frame = talloc_stackframe();
        struct tevent_context *ev;
@@ -709,7 +710,7 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
                               time_t access_time,
                               time_t write_time,
                               time_t change_time,
-                              uint16 mode)
+                              uint16_t mode)
 {
        unsigned int data_len = 0;
        char data[40];
@@ -732,8 +733,17 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
         put_long_date(p, change_time);
         p += 8;
 
-        /* Add attributes */
-        SIVAL(p, 0, mode);
+       if (mode == (uint16_t)-1 || mode == FILE_ATTRIBUTE_NORMAL) {
+               /* No change. */
+               mode = 0;
+       } else if (mode == 0) {
+               /* Clear all existing attributes. */
+               mode = FILE_ATTRIBUTE_NORMAL;
+       }
+
+       /* Add attributes */
+       SIVAL(p, 0, mode);
+
         p += 4;
 
         /* Add padding */
@@ -742,6 +752,19 @@ NTSTATUS cli_setpathinfo_basic(struct cli_state *cli, const char *fname,
 
         data_len = PTR_DIFF(p, data);
 
+       if (smbXcli_conn_protocol(cli->conn) >= PROTOCOL_SMB2_02) {
+               DATA_BLOB in_data = data_blob_const(data, data_len);
+               /*
+                * Split out SMB2 here as we need to select
+                * the correct info type and level.
+                */
+               return cli_smb2_setpathinfo(cli,
+                               fname,
+                               1, /* SMB2_SETINFO_FILE */
+                               SMB_FILE_BASIC_INFORMATION - 1000,
+                               &in_data);
+       }
+
        return cli_setpathinfo(cli, SMB_FILE_BASIC_INFORMATION, fname,
                               (uint8_t *)data, data_len);
 }
@@ -802,7 +825,7 @@ NTSTATUS cli_qpathinfo2_recv(struct tevent_req *req,
                             struct timespec *access_time,
                             struct timespec *write_time,
                             struct timespec *change_time,
-                            off_t *size, uint16 *mode,
+                            off_t *size, uint16_t *mode,
                             SMB_INO_T *ino)
 {
        struct cli_qpathinfo2_state *state = tevent_req_data(
@@ -842,7 +865,7 @@ NTSTATUS cli_qpathinfo2(struct cli_state *cli, const char *fname,
                        struct timespec *access_time,
                        struct timespec *write_time,
                        struct timespec *change_time,
-                       off_t *size, uint16 *mode,
+                       off_t *size, uint16_t *mode,
                        SMB_INO_T *ino)
 {
        TALLOC_CTX *frame = NULL;
@@ -1138,7 +1161,7 @@ NTSTATUS cli_qfilename(struct cli_state *cli, uint16_t fnum,
 ****************************************************************************/
 
 NTSTATUS cli_qfileinfo_basic(struct cli_state *cli, uint16_t fnum,
-                            uint16 *mode, off_t *size,
+                            uint16_t *mode, off_t *size,
                             struct timespec *create_time,
                             struct timespec *access_time,
                             struct timespec *write_time,
@@ -1255,7 +1278,7 @@ static void cli_qpathinfo_basic_done(struct tevent_req *subreq)
 }
 
 NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req,
-                                 SMB_STRUCT_STAT *sbuf, uint32 *attributes)
+                                 SMB_STRUCT_STAT *sbuf, uint32_t *attributes)
 {
        struct cli_qpathinfo_basic_state *state = tevent_req_data(
                req, struct cli_qpathinfo_basic_state);
@@ -1274,7 +1297,7 @@ NTSTATUS cli_qpathinfo_basic_recv(struct tevent_req *req,
 }
 
 NTSTATUS cli_qpathinfo_basic(struct cli_state *cli, const char *name,
-                            SMB_STRUCT_STAT *sbuf, uint32 *attributes)
+                            SMB_STRUCT_STAT *sbuf, uint32_t *attributes)
 {
        TALLOC_CTX *frame = NULL;
        struct tevent_context *ev;
@@ -1420,11 +1443,11 @@ NTSTATUS cli_qpathinfo3(struct cli_state *cli, const char *fname,
                        struct timespec *access_time,
                        struct timespec *write_time,
                        struct timespec *change_time,
-                       off_t *size, uint16 *mode,
+                       off_t *size, uint16_t *mode,
                        SMB_INO_T *ino)
 {
        NTSTATUS status = NT_STATUS_OK;
-       SMB_STRUCT_STAT st;
+       SMB_STRUCT_STAT st = { 0 };
        uint32_t attr;
        uint64_t pos;