cleaning up conflicts between group code not yet committed and
[samba.git] / source / rpc_client / cli_reg.c
index e1872bbd7995dfe30f35576e93fad3ea6c54e2bb..5eccdc7826afa8070aadbb7ad626813bb4022868 100644 (file)
@@ -3,9 +3,9 @@
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
  *  RPC Pipe client / server routines
- *  Copyright (C) Andrew Tridgell              1992-1997,
- *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
- *  Copyright (C) Paul Ashton                       1997.
+ *  Copyright (C) Andrew Tridgell              1992-1998,
+ *  Copyright (C) Luke Kenneth Casson Leighton 1996-1998,
+ *  Copyright (C) Paul Ashton                  1997-1998.
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 
 extern int DEBUGLEVEL;
 
-
 /****************************************************************************
 do a REG Open Policy
 ****************************************************************************/
-BOOL do_reg_connect(struct cli_state *cli, char *full_keyname,
-                               POLICY_HND *reg_hnd,
-                               POLICY_HND *key_hnd)
+BOOL do_reg_connect(struct cli_state *cli, char *full_keyname, char *key_name,
+                               POLICY_HND *reg_hnd)
 {
-       fstring key_name;
-       char *srch;
-       BOOL res1;
-       BOOL res;
-       BOOL hklm = False;
-       BOOL hku  = False;
+       BOOL res = True;
+       uint32 reg_type = 0;
 
        if (full_keyname == NULL)
        {
                return False;
        }
 
-       srch = "HKLM";
-       if (strnequal(full_keyname, srch, strlen(srch)))
+       ZERO_STRUCTP(reg_hnd);
+
+       /*
+        * open registry receive a policy handle
+        */
+
+       if (!reg_split_key(full_keyname, &reg_type, key_name))
        {
-               full_keyname += strlen(srch);
-               if (*full_keyname == '\\')
+               DEBUG(0,("do_reg_connect: unrecognised key name %s\n", full_keyname));  
+               return False;
+       }
+
+       switch (reg_type)
+       {
+               case HKEY_LOCAL_MACHINE:
+               {
+                       res = res ? do_reg_open_hklm(cli,
+                                       0x84E0, 0x02000000,
+                                       reg_hnd) : False;
+                       break;
+               }
+       
+               case HKEY_USERS:
                {
-                       full_keyname++;
-                       fstrcpy(key_name, full_keyname);
+                       res = res ? do_reg_open_hku(cli,
+                                       0x84E0, 0x02000000,
+                                       reg_hnd) : False;
+                       break;
                }
-               else if (*full_keyname != 0)
+               default:
                {
+                       DEBUG(0,("do_reg_connect: unrecognised hive key\n"));   
                        return False;
                }
        }
 
-       /* open registry receive a policy handle */
-
-       if (hklm)
-       {
-               res = res ? do_reg_open_hklm(cli,
-                               0x84E0, 0x02000000,
-                               reg_hnd) : False;
-       }
-       
-       if (hku)
-       {
-               res = res ? do_reg_open_hku(cli,
-                               0x84E0, 0x02000000,
-                               reg_hnd) : False;
-       }
-
-       /* open an entry */
-       res1 = res  ? do_reg_open_entry(cli, reg_hnd,
-                                key_name, 0x02000000, key_hnd) : False;
-
-       return res1 && res;
+       return res;
 }
 
 /****************************************************************************
@@ -442,6 +437,54 @@ BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
        return valid_query;
 }
 
+/****************************************************************************
+do a REG Set Key Security 
+****************************************************************************/
+BOOL do_reg_set_key_sec(struct cli_state *cli, POLICY_HND *hnd,
+                               uint32 sec_buf_size, SEC_DESC *sec_buf)
+{
+       prs_struct rbuf;
+       prs_struct buf; 
+       REG_Q_SET_KEY_SEC q_o;
+       BOOL valid_query = False;
+
+       if (hnd == NULL) return False;
+
+       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
+       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
+
+       /* create and send a MSRPC command with api REG_SET_KEY_SEC */
+
+       DEBUG(4,("REG Set Key security.\n"));
+
+       make_reg_q_set_key_sec(&q_o, hnd, sec_buf_size, sec_buf);
+
+       /* turn parameters into data stream */
+       reg_io_q_set_key_sec("", &q_o, &buf, 0);
+
+       /* send the data on \PIPE\ */
+       if (rpc_api_pipe_req(cli, REG_SET_KEY_SEC, &buf, &rbuf))
+       {
+               REG_R_SET_KEY_SEC r_o;
+               BOOL p;
+
+               ZERO_STRUCT(r_o);
+
+               reg_io_r_set_key_sec("", &r_o, &rbuf, 0);
+               p = rbuf.offset != 0;
+
+               if (p && r_o.status != 0)
+               {
+                       valid_query = True;
+               }
+       }
+
+       prs_mem_free(&rbuf);
+       prs_mem_free(&buf );
+
+       return valid_query;
+}
+
 /****************************************************************************
 do a REG Query Key Security 
 ****************************************************************************/
@@ -476,6 +519,10 @@ BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
                ZERO_STRUCT(r_o);
 
                r_o.data = sec_buf;
+               if (*sec_buf_size != 0)
+               {
+                       sec_buf->sec = (SEC_DESC*)malloc(*sec_buf_size);
+               }
                reg_io_r_get_key_sec("", &r_o, &rbuf, 0);
                p = rbuf.offset != 0;
 
@@ -507,6 +554,60 @@ BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
        return valid_query;
 }
 
+/****************************************************************************
+do a REG Delete Value
+****************************************************************************/
+BOOL do_reg_delete_val(struct cli_state *cli, POLICY_HND *hnd, char *val_name)
+{
+       prs_struct rbuf;
+       prs_struct buf; 
+       REG_Q_DELETE_VALUE q_o;
+       BOOL valid_delete = False;
+
+       if (hnd == NULL) return False;
+
+       prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
+       prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );
+
+       /* create and send a MSRPC command with api REG_DELETE_VALUE */
+
+       DEBUG(4,("REG Delete Value: %s\n", val_name));
+
+       make_reg_q_delete_val(&q_o, hnd, val_name);
+
+       /* turn parameters into data stream */
+       reg_io_q_delete_val("", &q_o, &buf, 0);
+
+       /* send the data on \PIPE\ */
+       if (rpc_api_pipe_req(cli, REG_DELETE_VALUE, &buf, &rbuf))
+       {
+               REG_R_DELETE_VALUE r_o;
+               BOOL p;
+
+               ZERO_STRUCT(r_o);
+
+               reg_io_r_delete_val("", &r_o, &rbuf, 0);
+               p = rbuf.offset != 0;
+
+               if (p && r_o.status != 0)
+               {
+                       /* report error code */
+                       DEBUG(0,("REG_DELETE_VALUE: %s\n", get_nt_error_msg(r_o.status)));
+                       p = False;
+               }
+
+               if (p)
+               {
+                       valid_delete = True;
+               }
+       }
+
+       prs_mem_free(&rbuf);
+       prs_mem_free(&buf );
+
+       return valid_delete;
+}
+
 /****************************************************************************
 do a REG Delete Key
 ****************************************************************************/