some cleanups in the clientutil.c code.
[Samba.git] / source / pipesrvsvc.c
blob28a304ef4a19e5efae73375f413d734cba161d75
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 /* construct reply. always indicate success */
174 *rdata_len = srv_reply_net_share_enum(&q_n, *rdata + 0x18, *rdata, 0x0);
178 /*******************************************************************
179 receives a srvsvc pipe and responds.
180 ********************************************************************/
181 BOOL api_srvsvcTNP(int cnum,int uid, char *param,char *data,
182 int mdrcnt,int mprcnt,
183 char **rdata,char **rparam,
184 int *rdata_len,int *rparam_len)
186 uint16 opnum;
187 char *q;
188 int pkttype;
189 extern pstring myname;
191 opnum = SVAL(data,22);
193 pkttype = CVAL(data, 2);
194 if (pkttype == 0x0b) /* RPC BIND */
196 DEBUG(4,("srvsvc rpc bind %x\n",pkttype));
197 LsarpcTNP1(data,rdata,rdata_len);
198 return True;
201 DEBUG(4,("srvsvc TransactNamedPipe op %x\n",opnum));
202 initrpcreply(data, *rdata);
203 DEBUG(4,("srvsvc LINE %d\n",__LINE__));
204 get_myname(myname,NULL);
206 switch (opnum)
208 case NETSHAREENUM:
210 api_srv_net_share_info( param, data, rdata, rdata_len);
211 make_rpc_reply(data, *rdata, *rdata_len);
212 break;
215 case NETSERVERGETINFO:
217 char *servername;
218 uint32 level;
219 UNISTR2 uni_str;
220 q = data + 0x18;
221 servername = q + 16;
222 q = skip_unicode_string(servername,1);
223 if (strlen(unistr(servername)) % 2 == 0)
224 q += 2;
225 level = IVAL(q, 0); q += 4;
226 /* ignore the rest for the moment */
227 q = *rdata + 0x18;
228 SIVAL(q, 0, 101); q += 4; /* switch value */
229 SIVAL(q, 0, 2); q += 4; /* bufptr */
230 SIVAL(q, 0, 0x1f4); q += 4; /* platform id */
231 SIVAL(q, 0, 2); q += 4; /* bufptr for name */
232 SIVAL(q, 0, 5); q += 4; /* major version */
233 SIVAL(q, 0, 4); q += 4; /* minor version == 5.4 */
234 SIVAL(q, 0, 0x4100B); q += 4; /* type */
235 SIVAL(q, 0, 2); q += 4; /* comment */
236 make_unistr2(&uni_str, myname, strlen(myname));
237 q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
239 make_unistr2(&uni_str, lp_serverstring(), strlen(lp_serverstring()));
240 q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
242 q = align_offset(q, *rdata, 4);
244 endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
245 break;
247 default:
248 DEBUG(4, ("srvsvc, unknown code: %lx\n", opnum));
250 return(True);