it now all compiles - so try enabling it by default and see what explodes on the...
[samba.git] / source / rpcclient / cmd_srvsvc.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.2
4    RPC pipe client
5
6    Copyright (C) Andrew Tridgell 1992-1999
7    Copyright (C) Luke Kenneth Casson Leighton 1996 - 1999
8    Copyright (C) Tim Potter 2000
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 2 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #include "includes.h"
26
27 extern int DEBUGLEVEL;
28
29 /* Display server query info */
30
31 static char *get_server_type_str(uint32 type)
32 {
33         static fstring typestr;
34         int i;
35
36         if (type == SV_TYPE_ALL) {
37                 fstrcpy(typestr, "All");
38                 return typestr;
39         }
40                 
41         typestr[0] = 0;
42
43         for (i = 0; i < 32; i++) {
44                 if (type & (1 << i)) {
45                         switch (1 << i) {
46                         case SV_TYPE_WORKSTATION:
47                                 fstrcat(typestr, "Wk ");
48                                 break;
49                         case SV_TYPE_SERVER:
50                                 fstrcat(typestr, "Sv ");
51                                 break;
52                         case SV_TYPE_SQLSERVER:
53                                 fstrcat(typestr, "Sql ");
54                                 break;
55                         case SV_TYPE_DOMAIN_CTRL:
56                                 fstrcat(typestr, "PDC ");
57                                 break;
58                         case SV_TYPE_DOMAIN_BAKCTRL:
59                                 fstrcat(typestr, "BDC ");
60                                 break;
61                         case SV_TYPE_TIME_SOURCE:
62                                 fstrcat(typestr, "Tim ");
63                                 break;
64                         case SV_TYPE_AFP:
65                                 fstrcat(typestr, "AFP ");
66                                 break;
67                         case SV_TYPE_NOVELL:
68                                 fstrcat(typestr, "Nov ");
69                                 break;
70                         case SV_TYPE_DOMAIN_MEMBER:
71                                 fstrcat(typestr, "Dom ");
72                                 break;
73                         case SV_TYPE_PRINTQ_SERVER:
74                                 fstrcat(typestr, "PrQ ");
75                                 break;
76                         case SV_TYPE_DIALIN_SERVER:
77                                 fstrcat(typestr, "Din ");
78                                 break;
79                         case SV_TYPE_SERVER_UNIX:
80                                 fstrcat(typestr, "Unx ");
81                                 break;
82                         case SV_TYPE_NT:
83                                 fstrcat(typestr, "NT ");
84                                 break;
85                         case SV_TYPE_WFW:
86                                 fstrcat(typestr, "Wfw ");
87                                 break;
88                         case SV_TYPE_SERVER_MFPN:
89                                 fstrcat(typestr, "Mfp ");
90                                 break;
91                         case SV_TYPE_SERVER_NT:
92                                 fstrcat(typestr, "SNT ");
93                                 break;
94                         case SV_TYPE_POTENTIAL_BROWSER:
95                                 fstrcat(typestr, "PtB ");
96                                 break;
97                         case SV_TYPE_BACKUP_BROWSER:
98                                 fstrcat(typestr, "BMB ");
99                                 break;
100                         case SV_TYPE_MASTER_BROWSER:
101                                 fstrcat(typestr, "LMB ");
102                                 break;
103                         case SV_TYPE_DOMAIN_MASTER:
104                                 fstrcat(typestr, "DMB ");
105                                 break;
106                         case SV_TYPE_SERVER_OSF:
107                                 fstrcat(typestr, "OSF ");
108                                 break;
109                         case SV_TYPE_SERVER_VMS:
110                                 fstrcat(typestr, "VMS ");
111                                 break;
112                         case SV_TYPE_WIN95_PLUS:
113                                 fstrcat(typestr, "W95 ");
114                                 break;
115                         case SV_TYPE_ALTERNATE_XPORT:
116                                 fstrcat(typestr, "Xpt ");
117                                 break;
118                         case SV_TYPE_LOCAL_LIST_ONLY:
119                                 fstrcat(typestr, "Dom ");
120                                 break;
121                         case SV_TYPE_DOMAIN_ENUM:
122                                 fstrcat(typestr, "Loc ");
123                                 break;
124                         }
125                 }
126         }
127
128         i = strlen(typestr) - 1;
129
130         if (typestr[i] == ' ')
131                 typestr[i] = 0;
132         
133         return typestr;
134 }
135
136 static void display_server(char *sname, uint32 type, const char *comment)
137 {
138         printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type), 
139                comment);
140 }
141
142 static void display_srv_info_101(SRV_INFO_101 *sv101)
143 {
144         fstring name;
145         fstring comment;
146
147         unistr2_to_ascii(name, &sv101->uni_name, sizeof(name) - 1);
148         unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment) - 1);
149
150         display_server(name, sv101->srv_type, comment);
151
152         printf("\tplatform_id     :\t%d\n", sv101->platform_id);
153         printf("\tos version      :\t%d.%d\n", sv101->ver_major, 
154                sv101->ver_minor);
155
156         printf("\tserver type     :\t0x%x\n", sv101->srv_type);
157 }
158
159 static void display_srv_info_102(SRV_INFO_102 *sv102)
160 {
161         fstring name;
162         fstring comment;
163         fstring usr_path;
164         
165         unistr2_to_ascii(name, &sv102->uni_name, sizeof(name) - 1);
166         unistr2_to_ascii(comment, &sv102->uni_comment, sizeof(comment) - 1);
167         unistr2_to_ascii(usr_path, &sv102->uni_usr_path, sizeof(usr_path) - 1);
168
169         display_server(name, sv102->srv_type, comment);
170
171         printf("\tplatform_id     :\t%d\n", sv102->platform_id);
172         printf("\tos version      :\t%d.%d\n", sv102->ver_major, 
173                sv102->ver_minor);
174
175         printf("\tusers           :\t%x\n", sv102->users);
176         printf("\tdisc, hidden    :\t%x, %x\n", sv102->disc, sv102->hidden);
177         printf("\tannounce, delta :\t%d, %d\n", sv102->announce, 
178                sv102->ann_delta);
179         printf("\tlicenses        :\t%d\n", sv102->licenses);
180         printf("\tuser path       :\t%s\n", usr_path);
181 }
182
183 /* Server query info */
184
185 static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli, int argc,
186                                         char **argv)
187 {
188         uint32 info_level = 101;
189         SRV_INFO_CTR ctr;
190         TALLOC_CTX *mem_ctx;
191         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
192
193         if (argc > 2) {
194                 printf("Usage: %s [infolevel]\n", argv[0]);
195                 return NT_STATUS_OK;
196         }
197
198         if (argc == 2)
199                 info_level = atoi(argv[1]);
200
201         if (!(mem_ctx = talloc_init())) {
202                 DEBUG(0,("cmd_srvsvc_srv_query_info: talloc_init failed\n"));
203                 return result;
204         }
205
206         /* Initialise RPC connection */
207
208         if (!cli_nt_session_open (cli, PIPE_SRVSVC)) {
209                 DEBUG(0, ("Could not initialize srvsvc pipe!\n"));
210                 goto done;
211         }
212
213         result = cli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
214                                              &ctr);
215         if (!NT_STATUS_IS_OK(result)) {
216                 goto done;
217         }
218
219         /* Display results */
220
221         switch (info_level) {
222         case 101:
223                 display_srv_info_101(&ctr.srv.sv101);
224                 break;
225         case 102:
226                 display_srv_info_102(&ctr.srv.sv102);
227                 break;
228         default:
229                 printf("unsupported info level %d\n", info_level);
230                 break;
231         }
232
233  done:
234         talloc_destroy(mem_ctx);
235
236         return result;
237 }
238
239 /* List of commands exported by this module */
240
241 struct cmd_set srvsvc_commands[] = {
242
243         { "SRVSVC" },
244
245         { "srvinfo",    cmd_srvsvc_srv_query_info,  "Server query info", "" },
246
247         { NULL }
248 };