parse_reg.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,709 行 · 第 1/3 页
C
1,709 行
/* * Unix SMB/CIFS implementation. * 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) Marc Jacobsen 1999. * Copyright (C) Simo Sorce 2000. * Copyright (C) Jeremy Cooper 2004 * Copyright (C) Gerald Carter 2002-2005. * * 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#include "includes.h"#undef DBGC_CLASS#define DBGC_CLASS DBGC_RPC_PARSE/******************************************************************* Fill in a REGVAL_BUFFER for the data given a REGISTRY_VALUE *******************************************************************/uint32 reg_init_regval_buffer( REGVAL_BUFFER *buf2, REGISTRY_VALUE *val ){ uint32 real_size = 0; if ( !buf2 || !val ) return 0; real_size = regval_size(val); init_regval_buffer( buf2, (unsigned char*)regval_data_p(val), real_size ); return real_size;}/******************************************************************* Inits a hive connect request structure********************************************************************/void init_reg_q_open_hive( REG_Q_OPEN_HIVE *q_o, uint32 access_desired ){ q_o->server = TALLOC_P( get_talloc_ctx(), uint16); *q_o->server = 0x1; q_o->access = access_desired;}/*******************************************************************Marshalls a hive connect request********************************************************************/BOOL reg_io_q_open_hive(const char *desc, REG_Q_OPEN_HIVE *q_u, prs_struct *ps, int depth){ prs_debug(ps, depth, desc, "reg_io_q_open_hive"); depth++; if(!prs_align(ps)) return False; if(!prs_pointer("server", ps, depth, (void**)&q_u->server, sizeof(uint16), (PRS_POINTER_CAST)prs_uint16)) return False; if(!prs_align(ps)) return False; if(!prs_uint32("access", ps, depth, &q_u->access)) return False; return True;}/*******************************************************************Unmarshalls a hive connect response********************************************************************/BOOL reg_io_r_open_hive(const char *desc, REG_R_OPEN_HIVE *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_open_hive"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &r_u->pol, ps, depth)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/******************************************************************* Inits a structure.********************************************************************/void init_reg_q_flush_key(REG_Q_FLUSH_KEY *q_u, POLICY_HND *pol){ memcpy(&q_u->pol, pol, sizeof(q_u->pol));}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_q_flush_key(const char *desc, REG_Q_FLUSH_KEY *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_flush_key"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->pol, ps, depth)) return False; return True;}/*******************************************************************Unmarshalls a registry key flush response********************************************************************/BOOL reg_io_r_flush_key(const char *desc, REG_R_FLUSH_KEY *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_flush_key"); depth++; if(!prs_align(ps)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/*******************************************************************reads or writes SEC_DESC_BUF and SEC_DATA structures.********************************************************************/static BOOL reg_io_hdrbuf_sec(uint32 ptr, uint32 *ptr3, BUFHDR *hdr_sec, SEC_DESC_BUF *data, prs_struct *ps, int depth){ if (ptr != 0) { uint32 hdr_offset; uint32 old_offset; if(!smb_io_hdrbuf_pre("hdr_sec", hdr_sec, ps, depth, &hdr_offset)) return False; old_offset = prs_offset(ps); if (ptr3 != NULL) { if(!prs_uint32("ptr3", ps, depth, ptr3)) return False; } if (ptr3 == NULL || *ptr3 != 0) { /* JRA - this next line is probably wrong... */ if(!sec_io_desc_buf("data ", &data, ps, depth)) return False; } if(!smb_io_hdrbuf_post("hdr_sec", hdr_sec, ps, depth, hdr_offset, data->max_len, data->len)) return False; if(!prs_set_offset(ps, old_offset + data->len + sizeof(uint32) * ((ptr3 != NULL) ? 5 : 3))) return False; if(!prs_align(ps)) return False; } return True;}/******************************************************************* Inits a registry key create request********************************************************************/void init_reg_q_create_key_ex(REG_Q_CREATE_KEY_EX *q_c, POLICY_HND *hnd, char *name, char *key_class, uint32 access_desired, SEC_DESC_BUF *sec_buf){ ZERO_STRUCTP(q_c); memcpy(&q_c->handle, hnd, sizeof(q_c->handle)); init_unistr4( &q_c->name, name, UNI_STR_TERMINATE ); init_unistr4( &q_c->key_class, key_class, UNI_STR_TERMINATE ); q_c->access = access_desired; q_c->sec_info = TALLOC_P( get_talloc_ctx(), uint32 ); *q_c->sec_info = DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION; q_c->data = sec_buf; q_c->ptr2 = 1; init_buf_hdr(&q_c->hdr_sec, sec_buf->len, sec_buf->len); q_c->ptr3 = 1; q_c->disposition = TALLOC_P( get_talloc_ctx(), uint32 );}/*******************************************************************Marshalls a registry key create request********************************************************************/BOOL reg_io_q_create_key_ex(const char *desc, REG_Q_CREATE_KEY_EX *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_create_key_ex"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->handle, ps, depth)) return False; if(!prs_unistr4 ("name", ps, depth, &q_u->name)) return False; if(!prs_align(ps)) return False; if(!prs_unistr4 ("key_class", ps, depth, &q_u->key_class)) return False; if(!prs_align(ps)) return False; if(!prs_uint32("options", ps, depth, &q_u->options)) return False; if(!prs_uint32("access", ps, depth, &q_u->access)) return False; if(!prs_pointer("sec_info", ps, depth, (void**)&q_u->sec_info, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32)) return False; if ( q_u->sec_info ) { if(!prs_uint32("ptr2", ps, depth, &q_u->ptr2)) return False; if(!reg_io_hdrbuf_sec(q_u->ptr2, &q_u->ptr3, &q_u->hdr_sec, q_u->data, ps, depth)) return False; } if(!prs_pointer("disposition", ps, depth, (void**)&q_u->disposition, sizeof(uint32), (PRS_POINTER_CAST)prs_uint32)) return False; return True;}/*******************************************************************Unmarshalls a registry key create response********************************************************************/BOOL reg_io_r_create_key_ex(const char *desc, REG_R_CREATE_KEY_EX *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_create_key_ex"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &r_u->handle, ps, depth)) return False; if(!prs_uint32("disposition", ps, depth, &r_u->disposition)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/******************************************************************* Inits a structure.********************************************************************/void init_reg_q_delete_val(REG_Q_DELETE_VALUE *q_c, POLICY_HND *hnd, char *name){ ZERO_STRUCTP(q_c); memcpy(&q_c->handle, hnd, sizeof(q_c->handle)); init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_q_delete_value(const char *desc, REG_Q_DELETE_VALUE *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_delete_value"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->handle, ps, depth)) return False; if(!prs_unistr4("name", ps, depth, &q_u->name)) return False; return True;}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_r_delete_value(const char *desc, REG_R_DELETE_VALUE *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_delete_value"); depth++; if(!prs_align(ps)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/******************************************************************* Inits a structure.********************************************************************/void init_reg_q_delete_key(REG_Q_DELETE_KEY *q_c, POLICY_HND *hnd, char *name){ ZERO_STRUCTP(q_c); memcpy(&q_c->handle, hnd, sizeof(q_c->handle)); init_unistr4(&q_c->name, name, UNI_STR_TERMINATE);}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_q_delete_key(const char *desc, REG_Q_DELETE_KEY *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_delete_key"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->handle, ps, depth)) return False; if(!prs_unistr4("", ps, depth, &q_u->name)) return False; return True;}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_r_delete_key(const char *desc, REG_R_DELETE_KEY *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_delete_key"); depth++; if(!prs_align(ps)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/******************************************************************* Inits a structure.********************************************************************/void init_reg_q_query_key(REG_Q_QUERY_KEY *q_o, POLICY_HND *hnd, const char *key_class){ ZERO_STRUCTP(q_o); memcpy(&q_o->pol, hnd, sizeof(q_o->pol)); init_unistr4(&q_o->key_class, key_class, UNI_STR_TERMINATE);}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_q_query_key(const char *desc, REG_Q_QUERY_KEY *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_query_key"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->pol, ps, depth)) return False; if(!prs_unistr4("key_class", ps, depth, &q_u->key_class)) return False; return True;}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_r_query_key(const char *desc, REG_R_QUERY_KEY *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_query_key"); depth++; if(!prs_align(ps)) return False; if(!prs_unistr4("key_class", ps, depth, &r_u->key_class)) return False; if(!prs_align(ps)) return False; if(!prs_uint32("num_subkeys ", ps, depth, &r_u->num_subkeys)) return False; if(!prs_uint32("max_subkeylen ", ps, depth, &r_u->max_subkeylen)) return False; if(!prs_uint32("reserved ", ps, depth, &r_u->reserved)) return False; if(!prs_uint32("num_values ", ps, depth, &r_u->num_values)) return False; if(!prs_uint32("max_valnamelen", ps, depth, &r_u->max_valnamelen)) return False; if(!prs_uint32("max_valbufsize", ps, depth, &r_u->max_valbufsize)) return False; if(!prs_uint32("sec_desc ", ps, depth, &r_u->sec_desc)) return False; if(!smb_io_time("mod_time ", &r_u->mod_time, ps, depth)) return False; if(!prs_werror("status", ps, depth, &r_u->status)) return False; return True;}/******************************************************************* Inits a structure.********************************************************************/void init_reg_q_getversion(REG_Q_GETVERSION *q_o, POLICY_HND *hnd){ memcpy(&q_o->pol, hnd, sizeof(q_o->pol));}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_q_getversion(const char *desc, REG_Q_GETVERSION *q_u, prs_struct *ps, int depth){ if ( !q_u ) return False; prs_debug(ps, depth, desc, "reg_io_q_getversion"); depth++; if(!prs_align(ps)) return False; if(!smb_io_pol_hnd("", &q_u->pol, ps, depth)) return False; return True;}/*******************************************************************reads or writes a structure.********************************************************************/BOOL reg_io_r_getversion(const char *desc, REG_R_GETVERSION *r_u, prs_struct *ps, int depth){ if ( !r_u ) return False; prs_debug(ps, depth, desc, "reg_io_r_getversion"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("win_version", ps, depth, &r_u->win_version)) return False; if(!prs_werror("status" , ps, depth, &r_u->status)) return False; return True;}/*******************************************************************reads or writes a structure.********************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?