f4ff11adf1321a520c1b0c8dbd0555f9698115a9
[sharpe/samba-autobuild/.git] / source3 / 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 #include "rpcclient.h"
27
28 /* Display server query info */
29
30 static char *get_server_type_str(uint32 type)
31 {
32         static fstring typestr;
33         int i;
34
35         if (type == SV_TYPE_ALL) {
36                 fstrcpy(typestr, "All");
37                 return typestr;
38         }
39                 
40         typestr[0] = 0;
41
42         for (i = 0; i < 32; i++) {
43                 if (type & (1 << i)) {
44                         switch (1 << i) {
45                         case SV_TYPE_WORKSTATION:
46                                 fstrcat(typestr, "Wk ");
47                                 break;
48                         case SV_TYPE_SERVER:
49                                 fstrcat(typestr, "Sv ");
50                                 break;
51                         case SV_TYPE_SQLSERVER:
52                                 fstrcat(typestr, "Sql ");
53                                 break;
54                         case SV_TYPE_DOMAIN_CTRL:
55                                 fstrcat(typestr, "PDC ");
56                                 break;
57                         case SV_TYPE_DOMAIN_BAKCTRL:
58                                 fstrcat(typestr, "BDC ");
59                                 break;
60                         case SV_TYPE_TIME_SOURCE:
61                                 fstrcat(typestr, "Tim ");
62                                 break;
63                         case SV_TYPE_AFP:
64                                 fstrcat(typestr, "AFP ");
65                                 break;
66                         case SV_TYPE_NOVELL:
67                                 fstrcat(typestr, "Nov ");
68                                 break;
69                         case SV_TYPE_DOMAIN_MEMBER:
70                                 fstrcat(typestr, "Dom ");
71                                 break;
72                         case SV_TYPE_PRINTQ_SERVER:
73                                 fstrcat(typestr, "PrQ ");
74                                 break;
75                         case SV_TYPE_DIALIN_SERVER:
76                                 fstrcat(typestr, "Din ");
77                                 break;
78                         case SV_TYPE_SERVER_UNIX:
79                                 fstrcat(typestr, "Unx ");
80                                 break;
81                         case SV_TYPE_NT:
82                                 fstrcat(typestr, "NT ");
83                                 break;
84                         case SV_TYPE_WFW:
85                                 fstrcat(typestr, "Wfw ");
86                                 break;
87                         case SV_TYPE_SERVER_MFPN:
88                                 fstrcat(typestr, "Mfp ");
89                                 break;
90                         case SV_TYPE_SERVER_NT:
91                                 fstrcat(typestr, "SNT ");
92                                 break;
93                         case SV_TYPE_POTENTIAL_BROWSER:
94                                 fstrcat(typestr, "PtB ");
95                                 break;
96                         case SV_TYPE_BACKUP_BROWSER:
97                                 fstrcat(typestr, "BMB ");
98                                 break;
99                         case SV_TYPE_MASTER_BROWSER:
100                                 fstrcat(typestr, "LMB ");
101                                 break;
102                         case SV_TYPE_DOMAIN_MASTER:
103                                 fstrcat(typestr, "DMB ");
104                                 break;
105                         case SV_TYPE_SERVER_OSF:
106                                 fstrcat(typestr, "OSF ");
107                                 break;
108                         case SV_TYPE_SERVER_VMS:
109                                 fstrcat(typestr, "VMS ");
110                                 break;
111                         case SV_TYPE_WIN95_PLUS:
112                                 fstrcat(typestr, "W95 ");
113                                 break;
114                         case SV_TYPE_ALTERNATE_XPORT:
115                                 fstrcat(typestr, "Xpt ");
116                                 break;
117                         case SV_TYPE_LOCAL_LIST_ONLY:
118                                 fstrcat(typestr, "Dom ");
119                                 break;
120                         case SV_TYPE_DOMAIN_ENUM:
121                                 fstrcat(typestr, "Loc ");
122                                 break;
123                         }
124                 }
125         }
126
127         i = strlen(typestr) - 1;
128
129         if (typestr[i] == ' ')
130                 typestr[i] = 0;
131         
132         return typestr;
133 }
134
135 static void display_server(char *sname, uint32 type, const char *comment)
136 {
137         printf("\t%-15.15s%-20s %s\n", sname, get_server_type_str(type), 
138                comment);
139 }
140
141 static void display_srv_info_101(SRV_INFO_101 *sv101)
142 {
143         fstring name;
144         fstring comment;
145
146         unistr2_to_ascii(name, &sv101->uni_name, sizeof(name) - 1);
147         unistr2_to_ascii(comment, &sv101->uni_comment, sizeof(comment) - 1);
148
149         display_server(name, sv101->srv_type, comment);
150
151         printf("\tplatform_id     :\t%d\n", sv101->platform_id);
152         printf("\tos version      :\t%d.%d\n", sv101->ver_major, 
153                sv101->ver_minor);
154
155         printf("\tserver type     :\t0x%x\n", sv101->srv_type);
156 }
157
158 static void display_srv_info_102(SRV_INFO_102 *sv102)
159 {
160         fstring name;
161         fstring comment;
162         fstring usr_path;
163         
164         unistr2_to_ascii(name, &sv102->uni_name, sizeof(name) - 1);
165         unistr2_to_ascii(comment, &sv102->uni_comment, sizeof(comment) - 1);
166         unistr2_to_ascii(usr_path, &sv102->uni_usr_path, sizeof(usr_path) - 1);
167
168         display_server(name, sv102->srv_type, comment);
169
170         printf("\tplatform_id     :\t%d\n", sv102->platform_id);
171         printf("\tos version      :\t%d.%d\n", sv102->ver_major, 
172                sv102->ver_minor);
173
174         printf("\tusers           :\t%x\n", sv102->users);
175         printf("\tdisc, hidden    :\t%x, %x\n", sv102->disc, sv102->hidden);
176         printf("\tannounce, delta :\t%d, %d\n", sv102->announce, 
177                sv102->ann_delta);
178         printf("\tlicenses        :\t%d\n", sv102->licenses);
179         printf("\tuser path       :\t%s\n", usr_path);
180 }
181
182 /* Server query info */
183
184 static NTSTATUS cmd_srvsvc_srv_query_info(struct cli_state *cli, 
185                                           TALLOC_CTX *mem_ctx,
186                                           int argc, char **argv)
187 {
188         uint32 info_level = 101;
189         SRV_INFO_CTR ctr;
190         NTSTATUS result = NT_STATUS_UNSUCCESSFUL;
191
192         if (argc > 2) {
193                 printf("Usage: %s [infolevel]\n", argv[0]);
194                 return NT_STATUS_OK;
195         }
196
197         if (argc == 2)
198                 info_level = atoi(argv[1]);
199
200         result = cli_srvsvc_net_srv_get_info(cli, mem_ctx, info_level,
201                                              &ctr);
202
203         if (!NT_STATUS_IS_OK(result)) {
204                 goto done;
205         }
206
207         /* Display results */
208
209         switch (info_level) {
210         case 101:
211                 display_srv_info_101(&ctr.srv.sv101);
212                 break;
213         case 102:
214                 display_srv_info_102(&ctr.srv.sv102);
215                 break;
216         default:
217                 printf("unsupported info level %d\n", info_level);
218                 break;
219         }
220
221  done:
222         return result;
223 }
224
225 /* List of commands exported by this module */
226
227 struct cmd_set srvsvc_commands[] = {
228
229         { "SRVSVC" },
230
231         { "srvinfo",    cmd_srvsvc_srv_query_info,  PIPE_SRVSVC, "Server query info", "" },
232
233         { NULL }
234 };