s3: Convert cli_set_secdesc to cli_trans
authorVolker Lendecke <vl@samba.org>
Sat, 15 Jan 2011 15:20:37 +0000 (16:20 +0100)
committerVolker Lendecke <vl@samba.org>
Sat, 15 Jan 2011 15:34:35 +0000 (16:34 +0100)
source3/include/proto.h
source3/libsmb/clisecdesc.c
source3/libsmb/libsmb_xattr.c
source3/utils/net_rpc_printer.c
source3/utils/smbcacls.c

index 338c27db03d853b439f93cc3e3b13250ac9313a2..0e66a523a848194b9ba6e694a4fb00f0b824bea8 100644 (file)
@@ -2508,7 +2508,8 @@ NTSTATUS cli_push(struct cli_state *cli, uint16_t fnum, uint16_t mode,
 
 struct security_descriptor *cli_query_secdesc(struct cli_state *cli, uint16_t fnum,
                            TALLOC_CTX *mem_ctx);
-bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, struct security_descriptor *sd);
+NTSTATUS cli_set_secdesc(struct cli_state *cli, uint16_t fnum,
+                        struct security_descriptor *sd);
 
 /* The following definitions come from libsmb/clispnego.c  */
 
index 33932a654a0072777d4f730aef751230f54dd4bb..5543ce50330784b0004f6de42cef5f0fe1dfa3eb 100644 (file)
@@ -70,14 +70,11 @@ struct security_descriptor *cli_query_secdesc(struct cli_state *cli, uint16_t fn
 /****************************************************************************
   set the security descriptor for a open file
  ****************************************************************************/
-bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, struct security_descriptor *sd)
+NTSTATUS cli_set_secdesc(struct cli_state *cli, uint16_t fnum,
+                        struct security_descriptor *sd)
 {
-       char param[8];
-       char *rparam=NULL, *rdata=NULL;
-       unsigned int rparam_count=0, rdata_count=0;
+       uint8_t param[8];
        uint32 sec_info = 0;
-       TALLOC_CTX *frame = talloc_stackframe();
-       bool ret = False;
        uint8 *data;
        size_t len;
        NTSTATUS status;
@@ -86,7 +83,7 @@ bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, struct security_descr
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(10, ("marshall_sec_desc failed: %s\n",
                           nt_errstr(status)));
-               goto cleanup;
+               return status;
        }
 
        SIVAL(param, 0, fnum);
@@ -99,32 +96,20 @@ bool cli_set_secdesc(struct cli_state *cli, uint16_t fnum, struct security_descr
                sec_info |= SECINFO_GROUP;
        SSVAL(param, 4, sec_info);
 
-       if (!cli_send_nt_trans(cli, 
-                              NT_TRANSACT_SET_SECURITY_DESC, 
-                              0, 
-                              NULL, 0, 0,
-                              param, 8, 0,
-                              (char *)data, len, 0)) {
-               DEBUG(1,("Failed to send NT_TRANSACT_SET_SECURITY_DESC\n"));
-               goto cleanup;
-       }
-
-
-       if (!cli_receive_nt_trans(cli, 
-                                 &rparam, &rparam_count,
-                                 &rdata, &rdata_count)) {
-               DEBUG(1,("NT_TRANSACT_SET_SECURITY_DESC failed\n"));
-               goto cleanup;
+       status = cli_trans(talloc_tos(), cli, SMBnttrans,
+                          NULL, -1, /* name, fid */
+                          NT_TRANSACT_SET_SECURITY_DESC, 0,
+                          NULL, 0, 0, /* setup */
+                          param, 8, 0, /* param */
+                          data, len, 0, /* data */
+                          NULL,         /* recv_flags2 */
+                          NULL, 0, NULL, /* rsetup */
+                          NULL, 0, NULL, /* rparam */
+                          NULL, 0, NULL); /* rdata */
+       TALLOC_FREE(data);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(1, ("Failed to send NT_TRANSACT_SET_SECURITY_DESC: %s\n",
+                         nt_errstr(status)));
        }
-
-       ret = True;
-
-  cleanup:
-
-       SAFE_FREE(rparam);
-       SAFE_FREE(rdata);
-
-       TALLOC_FREE(frame);
-
-       return ret;
+       return status;
 }
index 7086808f3cfd814ec3bad20d32597ef7f63d856a..155a6b974171b595ea880682a97a9439fff18582 100644 (file)
@@ -1513,6 +1513,7 @@ cacl_set(SMBCCTX *context,
         bool numeric = True;
        char *targetpath = NULL;
        struct cli_state *targetcli = NULL;
+       NTSTATUS status;
 
         /* the_acl will be null for REMOVE_ALL operations */
         if (the_acl) {
@@ -1666,9 +1667,10 @@ cacl_set(SMBCCTX *context,
                return -1;
        }
 
-       if (!cli_set_secdesc(targetcli, fnum, sd)) {
+       status = cli_set_secdesc(targetcli, fnum, sd);
+       if (!NT_STATUS_IS_OK(status)) {
                DEBUG(5, ("ERROR: secdesc set failed: %s\n",
-                       cli_errstr(targetcli)));
+                         nt_errstr(status)));
                ret = -1;
        }
 
index 8408235483ba7e3620b1a2991350b6a6f24226bc..470d61a751fe4db472b89b6a4b0c66eef127687e 100644 (file)
@@ -231,12 +231,14 @@ NTSTATUS net_copy_fileattr(struct net_context *c,
        }
 
        if (copy_acls) {
+               NTSTATUS status;
 
                /* set acls */
-               if (!cli_set_secdesc(cli_share_dst, fnum_dst, sd)) {
-                       DEBUG(0,("could not set secdesc on %s: %s\n",
-                               dst_name, cli_errstr(cli_share_dst)));
-                       nt_status = cli_nt_error(cli_share_dst);
+               status = cli_set_secdesc(cli_share_dst, fnum_dst, sd);
+               if (!NT_STATUS_IS_OK(status)) {
+                       DEBUG(0, ("could not set secdesc on %s: %s\n",
+                                 dst_name, nt_errstr(status)));
+                       nt_status = status;
                        goto out;
                }
        }
index 270af2135d77db6cfc413a1e56e16044551ee4eb..6a8169d39c5886828ddc18055410730055f9708e 100644 (file)
@@ -727,6 +727,7 @@ static bool set_secdesc(struct cli_state *cli, const char *filename,
 {
        uint16_t fnum = (uint16_t)-1;
         bool result=true;
+       NTSTATUS status;
 
        /* The desired access below is the only one I could find that works
           with NT4, W2KP and Samba */
@@ -739,9 +740,10 @@ static bool set_secdesc(struct cli_state *cli, const char *filename,
                return false;
        }
 
-       if (!cli_set_secdesc(cli, fnum, sd)) {
+       status = cli_set_secdesc(cli, fnum, sd);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("ERROR: security description set failed: %s\n",
-                       cli_errstr(cli));
+                       nt_errstr(status));
                result=false;
        }