Chris will be pleased to know that mkproto.awk no longer runs on the
[Samba.git] / source / pipesrvsvc.c
blob6e15b2e14b1f924dc3ca3ac84d1bc204e634747e
1 /*
2 Unix SMB/Netbios implementation.
3 Version 1.9.
4 Pipe SMB reply routines - srvsvc pipe
5 Copyright (C) Andrew Tridgell 1992-1997,
6 Copyright (C) Luke Kenneth Casson Leighton 1996-1997.
7 Copyright (C) Paul Ashton 1997.
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 2 of the License, or
12 (at your option) any later version.
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.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
26 #include "trans2.h"
27 #include "nterr.h"
29 extern int DEBUGLEVEL;
32 /*******************************************************************
33 ********************************************************************/
34 static void make_srv_share_info1_str(SH_INFO_1_STR *sh1, char *net_name, char *remark)
36 if (sh1 == NULL) return;
38 DEBUG(5,("make_srv_share_info1_str: %s %s\n", net_name, remark));
40 make_unistr2(&(sh1->uni_netname), net_name, strlen(net_name)+1);
41 make_unistr2(&(sh1->uni_remark ), remark , strlen(remark )+1);
44 /*******************************************************************
45 ********************************************************************/
46 static void make_srv_share_info1(SH_INFO_1 *sh1, char *net_name, uint32 type, char *remark)
48 if (sh1 == NULL) return;
50 DEBUG(5,("make_srv_share_info1_str: %s %8x %s\n", net_name, type, remark));
52 sh1->ptr_netname = net_name != NULL ? 1 : 0;
53 sh1->type = type;
54 sh1->ptr_remark = remark != NULL ? 1 : 0;
57 /*******************************************************************
58 fill in a share info level 1 structure.
60 this function breaks the rule that i'd like to be in place, namely
61 it doesn't receive its data as arguments: it has to call lp_xxxx()
62 functions itself. yuck.
64 this function is identical to api_RNetShareEnum(). maybe it even
65 generates the same output! (too much to hope for, really...)
67 ********************************************************************/
68 static void make_srv_share_1_ctr(SHARE_INFO_1_CTR *ctr)
70 int snum;
71 int num_entries = 0;
72 int svcs = lp_numservices();
74 if (ctr == NULL) return;
76 DEBUG(5,("make_srv_share_1_ctr\n"));
78 for (snum = 0; snum < svcs && num_entries < MAX_SHARE_ENTRIES; num_entries++, snum++)
80 int len_net_name;
81 pstring net_name;
82 pstring remark;
83 uint32 type;
85 if (lp_browseable(snum) && lp_snum_ok(snum))
87 /* see ipc.c:fill_share_info() */
89 pstrcpy(net_name, lp_servicename(snum));
90 pstrcpy(remark , lp_comment (snum));
91 len_net_name = strlen(net_name);
93 /* work out the share type */
94 type = STYPE_DISKTREE;
96 if (lp_print_ok(snum)) type = STYPE_PRINTQ;
97 if (strequal("IPC$", net_name)) type = STYPE_IPC;
98 if (net_name[len_net_name] == '$') type |= STYPE_HIDDEN;
100 make_srv_share_info1 (&(ctr->info_1 [num_entries]), net_name, type, remark);
101 make_srv_share_info1_str(&(ctr->info_1_str[num_entries]), net_name, remark);
105 ctr->num_entries_read = num_entries;
106 ctr->ptr_share_info = num_entries > 0 ? 1 : 0;
107 ctr->num_entries_read2 = num_entries;
108 ctr->num_entries_read3 = num_entries;
109 ctr->padding = 0;
112 /*******************************************************************
113 ********************************************************************/
114 static void make_srv_net_share_enum(SRV_R_NET_SHARE_ENUM *r_n,
115 int share_level, int switch_value, int status)
117 DEBUG(5,("make_srv_net_share_enum: %d\n", __LINE__));
119 r_n->share_level = share_level;
120 r_n->switch_value = switch_value;
121 r_n->status = status;
123 switch (switch_value)
125 case 1:
127 make_srv_share_1_ctr(&(r_n->share.info1));
128 r_n->ptr_share_info = r_n->share.info1.num_entries_read > 0 ? 1 : 0;
129 break;
131 default:
133 DEBUG(5,("make_srv_net_share_enum: unsupported switch value %d\n",
134 switch_value));
135 r_n->ptr_share_info = 0;
136 break;
141 /*******************************************************************
142 ********************************************************************/
143 static int srv_reply_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n,
144 char *q, char *base,
145 int status)
147 SRV_R_NET_SHARE_ENUM r_n;
149 DEBUG(5,("srv_net_share_enum: %d\n", __LINE__));
151 /* set up the */
152 make_srv_net_share_enum(&r_n, q_n->share_level, q_n->switch_value, status);
154 /* store the response in the SMB stream */
155 q = srv_io_r_net_share_enum(False, &r_n, q, base, 4, 0);
157 DEBUG(5,("srv_srv_pwset: %d\n", __LINE__));
159 /* return length of SMB data stored */
160 return PTR_DIFF(q, base);
163 /*******************************************************************
164 ********************************************************************/
165 static void api_srv_net_share_info( char *param, char *data,
166 char **rdata, int *rdata_len )
168 SRV_Q_NET_SHARE_ENUM q_n;
170 /* grab the net share enum */
171 srv_io_q_net_share_enum(True, &q_n, data + 0x18, data, 4, 0);
173 /* XXXX push the reply buffer size up a bit, and hope it's sufficient */
174 /* for the current maximum limit of 32 share entries */
175 *rdata_len = 4096;
176 *rdata = REALLOC(*rdata, *rdata_len);
178 /* construct reply. always indicate success */
179 *rdata_len = srv_reply_net_share_enum(&q_n, *rdata + 0x18, *rdata, 0x0);
183 /*******************************************************************
184 receives a srvsvc pipe and responds.
185 ********************************************************************/
186 BOOL api_srvsvcTNP(int cnum,int uid, char *param,char *data,
187 int mdrcnt,int mprcnt,
188 char **rdata,char **rparam,
189 int *rdata_len,int *rparam_len)
191 RPC_HDR_RR hdr;
193 if (data == NULL)
195 DEBUG(2,("api_srvsvcTNP: NULL data received\n"));
196 return False;
199 smb_io_rpc_hdr_rr(True, &hdr, data, data, 4, 0);
201 DEBUG(4,("srvsvc TransactNamedPipe op %x\n",hdr.opnum));
203 switch (hdr.opnum)
205 case NETSHAREENUM:
207 api_srv_net_share_info( param, data, rdata, rdata_len);
208 create_rpc_reply(hdr.hdr.call_id, *rdata, *rdata_len);
209 break;
212 case NETSERVERGETINFO:
214 extern pstring myname;
215 char *q;
216 char *servername;
217 uint32 level;
218 UNISTR2 uni_str;
220 q = data + 0x18;
222 servername = q + 16;
223 q = skip_unicode_string(servername,1);
224 if (strlen(unistr(servername)) % 2 == 0)
225 q += 2;
226 level = IVAL(q, 0); q += 4;
228 /* ignore the rest for the moment */
229 initrpcreply(data, *rdata);
230 q = *rdata + 0x18;
232 SIVAL(q, 0, 101); q += 4; /* switch value */
233 SIVAL(q, 0, 2); q += 4; /* bufptr */
234 SIVAL(q, 0, 0x1f4); q += 4; /* platform id */
235 SIVAL(q, 0, 2); q += 4; /* bufptr for name */
236 SIVAL(q, 0, 5); q += 4; /* major version */
237 SIVAL(q, 0, 4); q += 4; /* minor version == 5.4 */
238 SIVAL(q, 0, 0x4100B); q += 4; /* type */
239 SIVAL(q, 0, 2); q += 4; /* comment */
241 get_myname(myname,NULL);
243 make_unistr2(&uni_str, myname, strlen(myname));
244 q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
246 make_unistr2(&uni_str, lp_serverstring(), strlen(lp_serverstring()));
247 q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
249 q = align_offset(q, *rdata, 4);
251 endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
252 break;
255 default:
257 DEBUG(4, ("srvsvc, unknown code: %lx\n", hdr.opnum));
258 break;
262 return(True);