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