s3:rpc_parse: remove unused init_unistr().
[ira/wip.git] / source3 / rpc_parse / parse_misc.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997.
7  *  Copyright (C) Gerald (Jerry) Carter             2005
8  *  
9  *  This program is free software; you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License as published by
11  *  the Free Software Foundation; either version 3 of the License, or
12  *  (at your option) any later version.
13  *  
14  *  This program is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *  GNU General Public License for more details.
18  *  
19  *  You should have received a copy of the GNU General Public License
20  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
21  */
22
23 #include "includes.h"
24
25 #undef DBGC_CLASS
26 #define DBGC_CLASS DBGC_RPC_PARSE
27
28 /*******************************************************************
29  Reads or writes an NTTIME structure.
30 ********************************************************************/
31
32 bool smb_io_time(const char *desc, NTTIME *nttime, prs_struct *ps, int depth)
33 {
34         uint32 low, high;
35         if (nttime == NULL)
36                 return False;
37
38         prs_debug(ps, depth, desc, "smb_io_time");
39         depth++;
40
41         if(!prs_align(ps))
42                 return False;
43         
44         if (MARSHALLING(ps)) {
45                 low = *nttime & 0xFFFFFFFF;
46                 high = *nttime >> 32;
47         }
48         
49         if(!prs_uint32("low ", ps, depth, &low)) /* low part */
50                 return False;
51         if(!prs_uint32("high", ps, depth, &high)) /* high part */
52                 return False;
53
54         if (UNMARSHALLING(ps)) {
55                 *nttime = (((uint64_t)high << 32) + low);
56         }
57
58         return True;
59 }
60
61 /*******************************************************************
62 ********************************************************************/
63
64 bool smb_io_system_time(const char *desc, prs_struct *ps, int depth, SYSTEMTIME *systime)
65 {
66         if(!prs_uint16("year", ps, depth, &systime->year))
67                 return False;
68         if(!prs_uint16("month", ps, depth, &systime->month))
69                 return False;
70         if(!prs_uint16("dayofweek", ps, depth, &systime->dayofweek))
71                 return False;
72         if(!prs_uint16("day", ps, depth, &systime->day))
73                 return False;
74         if(!prs_uint16("hour", ps, depth, &systime->hour))
75                 return False;
76         if(!prs_uint16("minute", ps, depth, &systime->minute))
77                 return False;
78         if(!prs_uint16("second", ps, depth, &systime->second))
79                 return False;
80         if(!prs_uint16("milliseconds", ps, depth, &systime->milliseconds))
81                 return False;
82
83         return True;
84 }
85
86 /*******************************************************************
87 ********************************************************************/
88
89 bool make_systemtime(SYSTEMTIME *systime, struct tm *unixtime)
90 {
91         systime->year=unixtime->tm_year+1900;
92         systime->month=unixtime->tm_mon+1;
93         systime->dayofweek=unixtime->tm_wday;
94         systime->day=unixtime->tm_mday;
95         systime->hour=unixtime->tm_hour;
96         systime->minute=unixtime->tm_min;
97         systime->second=unixtime->tm_sec;
98         systime->milliseconds=0;
99
100         return True;
101 }
102
103 /*******************************************************************
104  Reads or writes a struct GUID
105 ********************************************************************/
106
107 bool smb_io_uuid(const char *desc, struct GUID *uuid, 
108                  prs_struct *ps, int depth)
109 {
110         if (uuid == NULL)
111                 return False;
112
113         prs_debug(ps, depth, desc, "smb_io_uuid");
114         depth++;
115
116         if(!prs_uint32 ("data   ", ps, depth, &uuid->time_low))
117                 return False;
118         if(!prs_uint16 ("data   ", ps, depth, &uuid->time_mid))
119                 return False;
120         if(!prs_uint16 ("data   ", ps, depth, &uuid->time_hi_and_version))
121                 return False;
122
123         if(!prs_uint8s (False, "data   ", ps, depth, uuid->clock_seq, sizeof(uuid->clock_seq)))
124                 return False;
125         if(!prs_uint8s (False, "data   ", ps, depth, uuid->node, sizeof(uuid->node)))
126                 return False;
127
128         return True;
129 }
130
131 /*******************************************************************
132  Inits a UNISTR2 structure.
133 ********************************************************************/
134
135 void init_unistr2(UNISTR2 *str, const char *buf, enum unistr2_term_codes flags)
136 {
137         size_t len = 0;
138         uint32 num_chars = 0;
139
140         if (buf) {
141                 /* We always null terminate the copy. */
142                 len = strlen(buf) + 1;
143                 if ( flags == UNI_STR_DBLTERMINATE )
144                         len++;
145         }
146
147         if (buf == NULL || len == 0) {
148                 /* no buffer -- nothing to do */
149                 str->uni_max_len = 0;
150                 str->offset = 0;
151                 str->uni_str_len = 0;
152
153                 return;
154         }
155         
156
157         str->buffer = TALLOC_ZERO_ARRAY(talloc_tos(), uint16, len);
158         if (str->buffer == NULL) {
159                 smb_panic("init_unistr2: malloc fail");
160                 return;
161         }
162
163         /* Ensure len is the length in *bytes* */
164         len *= sizeof(uint16);
165
166         /*
167          * The UNISTR2 must be initialized !!!
168          * jfm, 7/7/2001.
169          */
170         if (buf) {
171                 rpcstr_push((char *)str->buffer, buf, len, STR_TERMINATE);
172                 num_chars = strlen_w(str->buffer);
173                 if (flags == UNI_STR_TERMINATE || flags == UNI_MAXLEN_TERMINATE) {
174                         num_chars++;
175                 }
176                 if ( flags == UNI_STR_DBLTERMINATE )
177                         num_chars += 2;
178         }
179
180         str->uni_max_len = num_chars;
181         str->offset = 0;
182         str->uni_str_len = num_chars;
183         if ( num_chars && ((flags == UNI_MAXLEN_TERMINATE) || (flags == UNI_BROKEN_NON_NULL)) )
184                 str->uni_max_len++;
185 }