parse_misc.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 1,878 行 · 第 1/4 页
C
1,878 行
/* * 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) Gerald (Jerry) Carter 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/**************************************************************************** A temporary TALLOC context for things like unistrs, that is valid for the life of a complete RPC call.****************************************************************************/static TALLOC_CTX *current_rpc_talloc = NULL;static TALLOC_CTX *get_current_rpc_talloc(void){ return current_rpc_talloc;}void set_current_rpc_talloc( TALLOC_CTX *ctx){ current_rpc_talloc = ctx;}static TALLOC_CTX *main_loop_talloc = NULL;/*******************************************************************free up temporary memory - called from the main loop********************************************************************/void main_loop_talloc_free(void){ if (!main_loop_talloc) return; talloc_destroy(main_loop_talloc); main_loop_talloc = NULL;}/******************************************************************* Get a talloc context that is freed in the main loop...********************************************************************/TALLOC_CTX *main_loop_talloc_get(void){ if (!main_loop_talloc) { main_loop_talloc = talloc_init("main loop talloc (mainly parse_misc)"); if (!main_loop_talloc) smb_panic("main_loop_talloc: malloc fail\n"); } return main_loop_talloc;}/******************************************************************* Try and get a talloc context. Get the rpc one if possible, else get the main loop one. The main loop one is more dangerous as it goes away between packets, the rpc one will stay around for as long as a current RPC lasts.********************************************************************/ TALLOC_CTX *get_talloc_ctx(void){ TALLOC_CTX *tc = get_current_rpc_talloc(); if (tc) return tc; return main_loop_talloc_get();}/******************************************************************* Reads or writes a UTIME type.********************************************************************/static BOOL smb_io_utime(const char *desc, UTIME *t, prs_struct *ps, int depth){ if (t == NULL) return False; prs_debug(ps, depth, desc, "smb_io_utime"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32 ("time", ps, depth, &t->time)) return False; return True;}/******************************************************************* Reads or writes an NTTIME structure.********************************************************************/BOOL smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth){ if (nttime == NULL) return False; prs_debug(ps, depth, desc, "smb_io_time"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("low ", ps, depth, &nttime->low)) /* low part */ return False; if(!prs_uint32("high", ps, depth, &nttime->high)) /* high part */ return False; return True;}/******************************************************************* Reads or writes an NTTIME structure.********************************************************************/BOOL smb_io_nttime(const char *desc, prs_struct *ps, int depth, NTTIME *nttime){ return smb_io_time( desc, nttime, ps, depth );}/******************************************************************* Gets an enumeration handle from an ENUM_HND structure.********************************************************************/uint32 get_enum_hnd(ENUM_HND *enh){ return (enh && enh->ptr_hnd != 0) ? enh->handle : 0;}/******************************************************************* Inits an ENUM_HND structure.********************************************************************/void init_enum_hnd(ENUM_HND *enh, uint32 hnd){ DEBUG(5,("smb_io_enum_hnd\n")); enh->ptr_hnd = (hnd != 0) ? 1 : 0; enh->handle = hnd;}/******************************************************************* Reads or writes an ENUM_HND structure.********************************************************************/BOOL smb_io_enum_hnd(const char *desc, ENUM_HND *hnd, prs_struct *ps, int depth){ if (hnd == NULL) return False; prs_debug(ps, depth, desc, "smb_io_enum_hnd"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("ptr_hnd", ps, depth, &hnd->ptr_hnd)) /* pointer */ return False; if (hnd->ptr_hnd != 0) { if(!prs_uint32("handle ", ps, depth, &hnd->handle )) /* enum handle */ return False; } return True;}/******************************************************************* Reads or writes a DOM_SID structure.********************************************************************/BOOL smb_io_dom_sid(const char *desc, DOM_SID *sid, prs_struct *ps, int depth){ int i; if (sid == NULL) return False; prs_debug(ps, depth, desc, "smb_io_dom_sid"); depth++; if(!prs_uint8 ("sid_rev_num", ps, depth, &sid->sid_rev_num)) return False; if(!prs_uint8 ("num_auths ", ps, depth, &sid->num_auths)) return False; for (i = 0; i < 6; i++) { fstring tmp; slprintf(tmp, sizeof(tmp) - 1, "id_auth[%d] ", i); if(!prs_uint8 (tmp, ps, depth, &sid->id_auth[i])) return False; } /* oops! XXXX should really issue a warning here... */ if (sid->num_auths > MAXSUBAUTHS) sid->num_auths = MAXSUBAUTHS; if(!prs_uint32s(False, "sub_auths ", ps, depth, sid->sub_auths, sid->num_auths)) return False; return True;}/******************************************************************* Inits a DOM_SID structure. BIG NOTE: this function only does SIDS where the identauth is not >= 2^32 identauth >= 2^32 can be detected because it will be specified in hex********************************************************************/void init_dom_sid(DOM_SID *sid, const char *str_sid){ pstring domsid; int identauth; char *p; if (str_sid == NULL) { DEBUG(4,("netlogon domain SID: none\n")); sid->sid_rev_num = 0; sid->num_auths = 0; return; } pstrcpy(domsid, str_sid); DEBUG(4,("init_dom_sid %d SID: %s\n", __LINE__, domsid)); /* assume, but should check, that domsid starts "S-" */ p = strtok(domsid+2,"-"); sid->sid_rev_num = atoi(p); /* identauth in decimal should be < 2^32 */ /* identauth in hex should be >= 2^32 */ identauth = atoi(strtok(0,"-")); DEBUG(4,("netlogon rev %d\n", sid->sid_rev_num)); DEBUG(4,("netlogon %s ia %d\n", p, identauth)); sid->id_auth[0] = 0; sid->id_auth[1] = 0; sid->id_auth[2] = (identauth & 0xff000000) >> 24; sid->id_auth[3] = (identauth & 0x00ff0000) >> 16; sid->id_auth[4] = (identauth & 0x0000ff00) >> 8; sid->id_auth[5] = (identauth & 0x000000ff); sid->num_auths = 0; while ((p = strtok(0, "-")) != NULL && sid->num_auths < MAXSUBAUTHS) sid->sub_auths[sid->num_auths++] = atoi(p); DEBUG(4,("init_dom_sid: %d SID: %s\n", __LINE__, domsid));}/******************************************************************* Inits a DOM_SID2 structure.********************************************************************/void init_dom_sid2(DOM_SID2 *sid2, const DOM_SID *sid){ sid2->sid = *sid; sid2->num_auths = sid2->sid.num_auths;}/******************************************************************* Reads or writes a DOM_SID2 structure.********************************************************************/BOOL smb_io_dom_sid2_p(const char *desc, prs_struct *ps, int depth, DOM_SID2 **sid2){ uint32 data_p; /* caputure the pointer value to stream */ data_p = *sid2 ? 0xf000baaa : 0; if ( !prs_uint32("dom_sid2_p", ps, depth, &data_p )) return False; /* we're done if there is no data */ if ( !data_p ) return True; if (UNMARSHALLING(ps)) { if ( !(*sid2 = PRS_ALLOC_MEM(ps, DOM_SID2, 1)) ) return False; } return True;}/******************************************************************* Reads or writes a DOM_SID2 structure.********************************************************************/BOOL smb_io_dom_sid2(const char *desc, DOM_SID2 *sid, prs_struct *ps, int depth){ if (sid == NULL) return False; prs_debug(ps, depth, desc, "smb_io_dom_sid2"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("num_auths", ps, depth, &sid->num_auths)) return False; if(!smb_io_dom_sid("sid", &sid->sid, ps, depth)) return False; return True;}/******************************************************************* Reads or writes a struct uuid********************************************************************/BOOL smb_io_uuid(const char *desc, struct uuid *uuid, prs_struct *ps, int depth){ if (uuid == NULL) return False; prs_debug(ps, depth, desc, "smb_io_uuid"); depth++; if(!prs_uint32 ("data ", ps, depth, &uuid->time_low)) return False; if(!prs_uint16 ("data ", ps, depth, &uuid->time_mid)) return False; if(!prs_uint16 ("data ", ps, depth, &uuid->time_hi_and_version)) return False; if(!prs_uint8s (False, "data ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq))) return False; if(!prs_uint8s (False, "data ", ps, depth, uuid->node, sizeof(uuid->node))) return False; return True;}/*******************************************************************creates a STRHDR structure.********************************************************************/void init_str_hdr(STRHDR *hdr, int max_len, int len, uint32 buffer){ hdr->str_max_len = max_len; hdr->str_str_len = len; hdr->buffer = buffer;}/******************************************************************* Reads or writes a STRHDR structure.********************************************************************/BOOL smb_io_strhdr(const char *desc, STRHDR *hdr, prs_struct *ps, int depth){ if (hdr == NULL) return False; prs_debug(ps, depth, desc, "smb_io_strhdr"); depth++; prs_align(ps); if(!prs_uint16("str_str_len", ps, depth, &hdr->str_str_len)) return False; if(!prs_uint16("str_max_len", ps, depth, &hdr->str_max_len)) return False; if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) return False; return True;}/******************************************************************* Inits a UNIHDR structure.********************************************************************/void init_uni_hdr(UNIHDR *hdr, UNISTR2 *str2){ hdr->uni_str_len = 2 * (str2->uni_str_len); hdr->uni_max_len = 2 * (str2->uni_max_len); hdr->buffer = (str2->uni_str_len != 0) ? 1 : 0;}/******************************************************************* Reads or writes a UNIHDR structure.********************************************************************/BOOL smb_io_unihdr(const char *desc, UNIHDR *hdr, prs_struct *ps, int depth){ if (hdr == NULL) return False; prs_debug(ps, depth, desc, "smb_io_unihdr"); depth++; if(!prs_align(ps)) return False; if(!prs_uint16("uni_str_len", ps, depth, &hdr->uni_str_len)) return False; if(!prs_uint16("uni_max_len", ps, depth, &hdr->uni_max_len)) return False; if(!prs_uint32("buffer ", ps, depth, &hdr->buffer)) return False; return True;}/******************************************************************* Inits a BUFHDR structure.********************************************************************/void init_buf_hdr(BUFHDR *hdr, int max_len, int len){ hdr->buf_max_len = max_len; hdr->buf_len = len;}/******************************************************************* prs_uint16 wrapper. Call this and it sets up a pointer to where the uint16 should be stored, or gets the size if reading. ********************************************************************/BOOL smb_io_hdrbuf_pre(const char *desc, BUFHDR *hdr, prs_struct *ps, int depth, uint32 *offset){ (*offset) = prs_offset(ps); if (ps->io) { /* reading. */ if(!smb_io_hdrbuf(desc, hdr, ps, depth)) return False; } else { /* writing. */ if(!prs_set_offset(ps, prs_offset(ps) + (sizeof(uint32) * 2))) return False; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?