pipes.c pipesrvsvc.c :
[kai/samba.git] / source3 / pipesrvsvc.c
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.
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 2 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, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24
25 #include "includes.h"
26 #include "trans2.h"
27 #include "nterr.h"
28
29 extern int DEBUGLEVEL;
30
31
32 BOOL api_srvsvcTNP(int cnum,int uid, char *param,char *data,
33                      int mdrcnt,int mprcnt,
34                      char **rdata,char **rparam,
35                      int *rdata_len,int *rparam_len)
36 {
37   uint16 opnum;
38   char *q;
39   int pkttype;
40   extern pstring myname;
41   char *servername;
42   uint32 level;
43
44   opnum = SVAL(data,22);
45
46   pkttype = CVAL(data, 2);
47   if (pkttype == 0x0b) /* RPC BIND */
48   {
49     DEBUG(4,("srvsvc rpc bind %x\n",pkttype));
50     LsarpcTNP1(data,rdata,rdata_len);
51     return True;
52   }
53
54   DEBUG(4,("srvsvc TransactNamedPipe op %x\n",opnum));
55   initrpcreply(data, *rdata);
56   DEBUG(4,("srvsvc LINE %d\n",__LINE__));
57   get_myname(myname,NULL);
58
59   switch (opnum)
60   {
61     case NETSHAREENUM:
62       q = data + 0x18;
63       servername = q + 16;
64       q = skip_unicode_string(servername,1);
65       if (strlen(unistr(servername)) % 2 == 0)
66       q += 2;
67      level = IVAL(q, 0); q += 4;
68       /* ignore the rest for the moment */
69       q = *rdata + 0x18;
70       SIVAL(q, 0, level); q += 4;
71       SIVAL(q, 0, 1); q += 4; /* switch value */
72       SIVAL(q, 0, 2); q += 4;
73       SIVAL(q, 0, 2); q += 4; /* number of entries */
74       SIVAL(q, 0, 2); q += 4;
75       endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
76       break;
77
78     case NETSERVERGETINFO:
79     {
80       UNISTR2 uni_str;
81       q = data + 0x18;
82       servername = q + 16;
83       q = skip_unicode_string(servername,1);
84       if (strlen(unistr(servername)) % 2 == 0)
85         q += 2;
86     level = IVAL(q, 0); q += 4;
87      /* ignore the rest for the moment */
88       q = *rdata + 0x18;
89       SIVAL(q, 0, 101); q += 4; /* switch value */
90       SIVAL(q, 0, 2); q += 4; /* bufptr */
91       SIVAL(q, 0, 0x1f4); q += 4; /* platform id */
92       SIVAL(q, 0, 2); q += 4; /* bufptr for name */
93       SIVAL(q, 0, 5); q += 4; /* major version */
94       SIVAL(q, 0, 4); q += 4; /* minor version == 5.4 */
95       SIVAL(q, 0, 0x4100B); q += 4; /* type */
96       SIVAL(q, 0, 2); q += 4; /* comment */
97       make_unistr2(&uni_str, myname, strlen(myname));
98       q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
99
100       make_unistr2(&uni_str, lp_serverstring(), strlen(lp_serverstring()));
101       q = smb_io_unistr2(False, &uni_str, q, *rdata, 4, 0);
102
103       q = align_offset(q, *rdata, 4);
104
105       endrpcreply(data, *rdata, q-*rdata, 0, rdata_len);
106       break;
107     }
108     default:
109       DEBUG(4, ("srvsvc, unknown code: %lx\n", opnum));
110   }
111   return(True);
112 }
113