parse_spoolss.c
来自「samba-3.0.22.tar.gz 编译smb服务器的源码」· C语言 代码 · 共 2,230 行 · 第 1/5 页
C
2,230 行
/* * Unix SMB/CIFS implementation. * RPC Pipe client / server routines * Copyright (C) Andrew Tridgell 1992-2000, * Copyright (C) Luke Kenneth Casson Leighton 1996-2000, * Copyright (C) Jean Fran鏾is Micouleau 1998-2000, * Copyright (C) Gerald Carter 2000-2002, * Copyright (C) Tim Potter 2001-2002. * * 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/*******************************************************************This should be moved in a more generic lib.********************************************************************/ BOOL spoolss_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime){ if(!prs_uint16("year", ps, depth, &systime->year)) return False; if(!prs_uint16("month", ps, depth, &systime->month)) return False; if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek)) return False; if(!prs_uint16("day", ps, depth, &systime->day)) return False; if(!prs_uint16("hour", ps, depth, &systime->hour)) return False; if(!prs_uint16("minute", ps, depth, &systime->minute)) return False; if(!prs_uint16("second", ps, depth, &systime->second)) return False; if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds)) return False; return True;}/***************************************************************************************************************************************/ BOOL make_systemtime(SYSTEMTIME *systime, struct tm *unixtime){ systime->year=unixtime->tm_year+1900; systime->month=unixtime->tm_mon+1; systime->dayofweek=unixtime->tm_wday; systime->day=unixtime->tm_mday; systime->hour=unixtime->tm_hour; systime->minute=unixtime->tm_min; systime->second=unixtime->tm_sec; systime->milliseconds=0; return True;}/*******************************************************************reads or writes an DOC_INFO structure.********************************************************************/ static BOOL smb_io_doc_info_1(const char *desc, DOC_INFO_1 *info_1, prs_struct *ps, int depth){ if (info_1 == NULL) return False; prs_debug(ps, depth, desc, "smb_io_doc_info_1"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("p_docname", ps, depth, &info_1->p_docname)) return False; if(!prs_uint32("p_outputfile", ps, depth, &info_1->p_outputfile)) return False; if(!prs_uint32("p_datatype", ps, depth, &info_1->p_datatype)) return False; if(!smb_io_unistr2("", &info_1->docname, info_1->p_docname, ps, depth)) return False; if(!smb_io_unistr2("", &info_1->outputfile, info_1->p_outputfile, ps, depth)) return False; if(!smb_io_unistr2("", &info_1->datatype, info_1->p_datatype, ps, depth)) return False; return True;}/*******************************************************************reads or writes an DOC_INFO structure.********************************************************************/ static BOOL smb_io_doc_info(const char *desc, DOC_INFO *info, prs_struct *ps, int depth){ uint32 useless_ptr=0; if (info == NULL) return False; prs_debug(ps, depth, desc, "smb_io_doc_info"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("switch_value", ps, depth, &info->switch_value)) return False; if(!prs_uint32("doc_info_X ptr", ps, depth, &useless_ptr)) return False; switch (info->switch_value) { case 1: if(!smb_io_doc_info_1("",&info->doc_info_1, ps, depth)) return False; break; case 2: /* this is just a placeholder MSDN July 1998 says doc_info_2 is only on Windows 95, and as Win95 doesn't do RPC to print this case is nearly impossible Maybe one day with Windows for dishwasher 2037 ... */ /* smb_io_doc_info_2("",&info->doc_info_2, ps, depth); */ break; default: DEBUG(0,("Something is obviously wrong somewhere !\n")); break; } return True;}/*******************************************************************reads or writes an DOC_INFO_CONTAINER structure.********************************************************************/ static BOOL smb_io_doc_info_container(const char *desc, DOC_INFO_CONTAINER *cont, prs_struct *ps, int depth){ if (cont == NULL) return False; prs_debug(ps, depth, desc, "smb_io_doc_info_container"); depth++; if(!prs_align(ps)) return False; if(!prs_uint32("level", ps, depth, &cont->level)) return False; if(!smb_io_doc_info("",&cont->docinfo, ps, depth)) return False; return True;}/*******************************************************************reads or writes an NOTIFY OPTION TYPE structure.********************************************************************/ /* NOTIFY_OPTION_TYPE and NOTIFY_OPTION_TYPE_DATA are really one structure. The _TYPE structure is really the deferred referrants (i.e the notify fields array) of the _TYPE structure. -tpot */static BOOL smb_io_notify_option_type(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth){ prs_debug(ps, depth, desc, "smb_io_notify_option_type"); depth++; if (!prs_align(ps)) return False; if(!prs_uint16("type", ps, depth, &type->type)) return False; if(!prs_uint16("reserved0", ps, depth, &type->reserved0)) return False; if(!prs_uint32("reserved1", ps, depth, &type->reserved1)) return False; if(!prs_uint32("reserved2", ps, depth, &type->reserved2)) return False; if(!prs_uint32("count", ps, depth, &type->count)) return False; if(!prs_uint32("fields_ptr", ps, depth, &type->fields_ptr)) return False; return True;}/*******************************************************************reads or writes an NOTIFY OPTION TYPE DATA.********************************************************************/ static BOOL smb_io_notify_option_type_data(const char *desc, SPOOL_NOTIFY_OPTION_TYPE *type, prs_struct *ps, int depth){ int i; prs_debug(ps, depth, desc, "smb_io_notify_option_type_data"); depth++; /* if there are no fields just return */ if (type->fields_ptr==0) return True; if(!prs_align(ps)) return False; if(!prs_uint32("count2", ps, depth, &type->count2)) return False; if (type->count2 != type->count) DEBUG(4,("What a mess, count was %x now is %x !\n", type->count, type->count2)); /* parse the option type data */ for(i=0;i<type->count2;i++) if(!prs_uint16("fields",ps,depth,&type->fields[i])) return False; return True;}/*******************************************************************reads or writes an NOTIFY OPTION structure.********************************************************************/ static BOOL smb_io_notify_option_type_ctr(const char *desc, SPOOL_NOTIFY_OPTION_TYPE_CTR *ctr , prs_struct *ps, int depth){ int i; prs_debug(ps, depth, desc, "smb_io_notify_option_type_ctr"); depth++; if(!prs_uint32("count", ps, depth, &ctr->count)) return False; /* reading */ if (UNMARSHALLING(ps)) if((ctr->type=PRS_ALLOC_MEM(ps,SPOOL_NOTIFY_OPTION_TYPE,ctr->count)) == NULL) return False; /* the option type struct */ for(i=0;i<ctr->count;i++) if(!smb_io_notify_option_type("", &ctr->type[i] , ps, depth)) return False; /* the type associated with the option type struct */ for(i=0;i<ctr->count;i++) if(!smb_io_notify_option_type_data("", &ctr->type[i] , ps, depth)) return False; return True;}/*******************************************************************reads or writes an NOTIFY OPTION structure.********************************************************************/ static BOOL smb_io_notify_option(const char *desc, SPOOL_NOTIFY_OPTION *option, prs_struct *ps, int depth){ prs_debug(ps, depth, desc, "smb_io_notify_option"); depth++; if(!prs_uint32("version", ps, depth, &option->version)) return False; if(!prs_uint32("flags", ps, depth, &option->flags)) return False; if(!prs_uint32("count", ps, depth, &option->count)) return False; if(!prs_uint32("option_type_ptr", ps, depth, &option->option_type_ptr)) return False; /* marshalling or unmarshalling, that would work */ if (option->option_type_ptr!=0) { if(!smb_io_notify_option_type_ctr("", &option->ctr ,ps, depth)) return False; } else { option->ctr.type=NULL; option->ctr.count=0; } return True;}/*******************************************************************reads or writes an NOTIFY INFO DATA structure.********************************************************************/ static BOOL smb_io_notify_info_data(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth){ uint32 useless_ptr=0x0FF0ADDE; prs_debug(ps, depth, desc, "smb_io_notify_info_data"); depth++; if(!prs_align(ps)) return False; if(!prs_uint16("type", ps, depth, &data->type)) return False; if(!prs_uint16("field", ps, depth, &data->field)) return False; if(!prs_uint32("how many words", ps, depth, &data->size)) return False; if(!prs_uint32("id", ps, depth, &data->id)) return False; if(!prs_uint32("how many words", ps, depth, &data->size)) return False; switch (data->enc_type) { /* One and two value data has two uint32 values */ case NOTIFY_ONE_VALUE: case NOTIFY_TWO_VALUE: if(!prs_uint32("value[0]", ps, depth, &data->notify_data.value[0])) return False; if(!prs_uint32("value[1]", ps, depth, &data->notify_data.value[1])) return False; break; /* Pointers and strings have a string length and a pointer. For a string the length is expressed as the number of uint16 characters plus a trailing \0\0. */ case NOTIFY_POINTER: if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length )) return False; if(!prs_uint32("pointer", ps, depth, &useless_ptr)) return False; break; case NOTIFY_STRING: if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length)) return False; if(!prs_uint32("pointer", ps, depth, &useless_ptr)) return False; break; case NOTIFY_SECDESC: if( !prs_uint32( "sd size", ps, depth, &data->notify_data.sd.size ) ) return False; if( !prs_uint32( "pointer", ps, depth, &useless_ptr ) ) return False; break; default: DEBUG(3, ("invalid enc_type %d for smb_io_notify_info_data\n", data->enc_type)); break; } return True;}/*******************************************************************reads or writes an NOTIFY INFO DATA structure.********************************************************************/ BOOL smb_io_notify_info_data_strings(const char *desc,SPOOL_NOTIFY_INFO_DATA *data, prs_struct *ps, int depth){ prs_debug(ps, depth, desc, "smb_io_notify_info_data_strings"); depth++; if(!prs_align(ps)) return False; switch(data->enc_type) { /* No data for values */ case NOTIFY_ONE_VALUE: case NOTIFY_TWO_VALUE: break; /* Strings start with a length in uint16s */ case NOTIFY_STRING: if (MARSHALLING(ps)) data->notify_data.data.length /= 2; if(!prs_uint32("string length", ps, depth, &data->notify_data.data.length)) return False; if (UNMARSHALLING(ps)) { data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, data->notify_data.data.length); if (!data->notify_data.data.string) return False; } if (!prs_uint16uni(True, "string", ps, depth, data->notify_data.data.string, data->notify_data.data.length)) return False; if (MARSHALLING(ps)) data->notify_data.data.length *= 2; break; case NOTIFY_POINTER: if (UNMARSHALLING(ps)) { data->notify_data.data.string = PRS_ALLOC_MEM(ps, uint16, data->notify_data.data.length); if (!data->notify_data.data.string) return False; } if(!prs_uint8s(True,"buffer",ps,depth,(uint8*)data->notify_data.data.string,data->notify_data.data.length)) return False; break; case NOTIFY_SECDESC:
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?