mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
rpcclient registry key delete command: "regdeletekey".
This commit is contained in:
parent
5e9567e3c7
commit
20987b6105
@ -1311,6 +1311,7 @@ BOOL do_reg_query_info(struct cli_state *cli, POLICY_HND *hnd,
|
||||
char *type, uint32 *unk_0, uint32 *unk_1);
|
||||
BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
|
||||
uint32 *sec_buf_size, SEC_DESC_BUF *sec_buf);
|
||||
BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name);
|
||||
BOOL do_reg_create_key(struct cli_state *cli, POLICY_HND *hnd,
|
||||
char *key_name, char *key_class,
|
||||
SEC_INFO *sam_access,
|
||||
@ -1620,6 +1621,10 @@ void make_reg_q_create_key(REG_Q_CREATE_KEY *q_c, POLICY_HND *hnd,
|
||||
SEC_INFO *sam_access);
|
||||
void reg_io_q_create_key(char *desc, REG_Q_CREATE_KEY *r_q, prs_struct *ps, int depth);
|
||||
void reg_io_r_create_key(char *desc, REG_R_CREATE_KEY *r_r, prs_struct *ps, int depth);
|
||||
void make_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd,
|
||||
char *name);
|
||||
void reg_io_q_delete_key(char *desc, REG_Q_DELETE_KEY *r_q, prs_struct *ps, int depth);
|
||||
void reg_io_r_delete_key(char *desc, REG_R_DELETE_KEY *r_r, prs_struct *ps, int depth);
|
||||
void make_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd,
|
||||
uint32 max_class_len);
|
||||
void reg_io_q_query_key(char *desc, REG_Q_QUERY_KEY *r_q, prs_struct *ps, int depth);
|
||||
@ -2084,6 +2089,7 @@ void cmd_reg_enum(struct client_info *info);
|
||||
void cmd_reg_query_key(struct client_info *info);
|
||||
void cmd_reg_test2(struct client_info *info);
|
||||
void cmd_reg_create_val(struct client_info *info);
|
||||
void cmd_reg_delete_key(struct client_info *info);
|
||||
void cmd_reg_create_key(struct client_info *info);
|
||||
void cmd_reg_get_key_sec(struct client_info *info);
|
||||
|
||||
|
@ -33,6 +33,7 @@
|
||||
#define REG_QUERY_KEY 0x10
|
||||
#define REG_ENUM_KEY 0x09
|
||||
#define REG_CREATE_KEY 0x06
|
||||
#define REG_DELETE_KEY 0x07
|
||||
#define REG_CREATE_VALUE 0x16
|
||||
#define REG_GET_KEY_SEC 0x0c
|
||||
#define REG_ENUM_VALUE 0x0a
|
||||
@ -211,6 +212,7 @@ typedef struct q_reg_create_key_info
|
||||
BUFFER2 buf_unk; /* 01 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 */
|
||||
|
||||
uint32 unknown_2; /* 0x0000 0000 */
|
||||
|
||||
} REG_Q_CREATE_KEY;
|
||||
|
||||
/* REG_R_CREATE_KEY */
|
||||
@ -223,6 +225,25 @@ typedef struct r_reg_create_key_info
|
||||
|
||||
} REG_R_CREATE_KEY;
|
||||
|
||||
/* REG_Q_DELETE_KEY */
|
||||
typedef struct q_reg_delete_key_info
|
||||
{
|
||||
POLICY_HND pnt_pol; /* parent key policy handle */
|
||||
|
||||
UNIHDR hdr_name;
|
||||
UNISTR2 uni_name;
|
||||
} REG_Q_DELETE_KEY;
|
||||
|
||||
/* REG_R_DELETE_KEY */
|
||||
typedef struct r_reg_delete_key_info
|
||||
{
|
||||
POLICY_HND key_pol; /* policy handle */
|
||||
uint32 unknown; /* 0x0000 0000 */
|
||||
|
||||
uint32 status; /* return status */
|
||||
|
||||
} REG_R_DELETE_KEY;
|
||||
|
||||
/* REG_Q_QUERY_KEY */
|
||||
typedef struct q_reg_query_info
|
||||
{
|
||||
|
@ -450,6 +450,60 @@ BOOL do_reg_get_key_sec(struct cli_state *cli, POLICY_HND *hnd,
|
||||
return valid_query;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
do a REG Delete Key
|
||||
****************************************************************************/
|
||||
BOOL do_reg_delete_key(struct cli_state *cli, POLICY_HND *hnd, char *key_name)
|
||||
{
|
||||
prs_struct rbuf;
|
||||
prs_struct buf;
|
||||
REG_Q_DELETE_KEY 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_KEY */
|
||||
|
||||
DEBUG(4,("REG Delete Key: %s\n", key_name));
|
||||
|
||||
make_reg_q_delete_key(&q_o, hnd, key_name);
|
||||
|
||||
/* turn parameters into data stream */
|
||||
reg_io_q_delete_key("", &q_o, &buf, 0);
|
||||
|
||||
/* send the data on \PIPE\ */
|
||||
if (rpc_api_pipe_req(cli, REG_DELETE_KEY, &buf, &rbuf))
|
||||
{
|
||||
REG_R_DELETE_KEY r_o;
|
||||
BOOL p;
|
||||
|
||||
ZERO_STRUCT(r_o);
|
||||
|
||||
reg_io_r_delete_key("", &r_o, &rbuf, 0);
|
||||
p = rbuf.offset != 0;
|
||||
|
||||
if (p && r_o.status != 0)
|
||||
{
|
||||
/* report error code */
|
||||
DEBUG(0,("REG_DELETE_KEY: %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 Create Key
|
||||
****************************************************************************/
|
||||
|
@ -231,6 +231,57 @@ void reg_io_r_create_key(char *desc, REG_R_CREATE_KEY *r_r, prs_struct *ps, int
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
creates a structure.
|
||||
********************************************************************/
|
||||
void make_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd,
|
||||
char *name)
|
||||
{
|
||||
int len_name = name != NULL ? strlen(name ) + 1: 0;
|
||||
ZERO_STRUCTP(q_c);
|
||||
|
||||
memcpy(&(q_c->pnt_pol), hnd, sizeof(q_c->pnt_pol));
|
||||
|
||||
make_uni_hdr(&(q_c->hdr_name), len_name, len_name, 1);
|
||||
make_unistr2(&(q_c->uni_name), name, len_name);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
reads or writes a structure.
|
||||
********************************************************************/
|
||||
void reg_io_q_delete_key(char *desc, REG_Q_DELETE_KEY *r_q, prs_struct *ps, int depth)
|
||||
{
|
||||
if (r_q == NULL) return;
|
||||
|
||||
prs_debug(ps, depth, desc, "reg_io_q_delete_key");
|
||||
depth++;
|
||||
|
||||
prs_align(ps);
|
||||
|
||||
smb_io_pol_hnd("", &(r_q->pnt_pol), ps, depth);
|
||||
|
||||
smb_io_unihdr ("", &(r_q->hdr_name), ps, depth);
|
||||
smb_io_unistr2("", &(r_q->uni_name), r_q->hdr_name.buffer, ps, depth);
|
||||
prs_align(ps);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
reads or writes a structure.
|
||||
********************************************************************/
|
||||
void reg_io_r_delete_key(char *desc, REG_R_DELETE_KEY *r_r, prs_struct *ps, int depth)
|
||||
{
|
||||
if (r_r == NULL) return;
|
||||
|
||||
prs_debug(ps, depth, desc, "reg_io_r_delete_key");
|
||||
depth++;
|
||||
|
||||
prs_align(ps);
|
||||
|
||||
prs_uint32("status", ps, depth, &(r_r->status));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************
|
||||
creates a structure.
|
||||
********************************************************************/
|
||||
|
@ -512,6 +512,71 @@ void cmd_reg_create_val(struct client_info *info)
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
nt registry delete key
|
||||
****************************************************************************/
|
||||
void cmd_reg_delete_key(struct client_info *info)
|
||||
{
|
||||
BOOL res = True;
|
||||
BOOL res3 = True;
|
||||
BOOL res4 = True;
|
||||
|
||||
POLICY_HND parent_pol;
|
||||
fstring parent_name;
|
||||
fstring key_name;
|
||||
|
||||
DEBUG(5, ("cmd_reg_delete_key: smb_cli->fd:%d\n", smb_cli->fd));
|
||||
|
||||
if (!next_token(NULL, parent_name, NULL, sizeof(parent_name)))
|
||||
{
|
||||
fprintf(out_hnd, "regcreate <parent key name> <key_name>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!next_token(NULL, key_name , NULL, sizeof(key_name )))
|
||||
{
|
||||
fprintf(out_hnd, "regcreate <parent key name> <key_name>\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* open WINREG session. */
|
||||
res = res ? cli_nt_session_open(smb_cli, PIPE_WINREG) : False;
|
||||
|
||||
/* open registry receive a policy handle */
|
||||
res = res ? do_reg_open_policy(smb_cli,
|
||||
0x84E0, 0x02000000,
|
||||
&info->dom.reg_pol_connect) : False;
|
||||
|
||||
/* open an entry */
|
||||
res3 = res ? do_reg_open_entry(smb_cli, &info->dom.reg_pol_connect,
|
||||
parent_name, 0x02000000, &parent_pol) : False;
|
||||
|
||||
/* create an entry */
|
||||
res4 = res3 ? do_reg_delete_key(smb_cli, &parent_pol, key_name) : False;
|
||||
|
||||
/* some sort of "sync" or "refresh" on the parent key? */
|
||||
res4 = res4 ? do_reg_unk_b(smb_cli, &parent_pol) : False;
|
||||
|
||||
/* close the key handle */
|
||||
res3 = res3 ? do_reg_close(smb_cli, &parent_pol) : False;
|
||||
|
||||
/* close the registry handles */
|
||||
res = res ? do_reg_close(smb_cli, &info->dom.reg_pol_connect) : False;
|
||||
|
||||
/* close the session */
|
||||
cli_nt_session_close(smb_cli);
|
||||
|
||||
if (res && res3 && res4)
|
||||
{
|
||||
DEBUG(5,("cmd_reg_delete_key: query succeeded\n"));
|
||||
fprintf(out_hnd,"OK\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG(5,("cmd_reg_delete_key: query failed\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
nt registry create key
|
||||
****************************************************************************/
|
||||
|
@ -106,6 +106,7 @@ struct
|
||||
} commands[] =
|
||||
{
|
||||
{"regenum", cmd_reg_enum, "<keyname> Registry Enumeration (keys, values)"},
|
||||
{"regdeletekey",cmd_reg_delete_key, "<parentname> <keyname> Registry Key Delete"},
|
||||
{"regcreatekey",cmd_reg_create_key, "<parentname> <keyname> [keyclass] Registry Key Create"},
|
||||
{"regquerykey",cmd_reg_query_key, "<keyname> Registry Key Query"},
|
||||
{"regcreateval",cmd_reg_create_val, "<parentname> <valname> <valtype> <value> Registry Key Create"},
|
||||
|
Loading…
Reference in New Issue
Block a user