2 * Copyright (c) 1999, Boris Popov
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
47 #include <netncp/ncp_lib.h>
49 extern char *__progname;
51 static struct ncp_conn_stat conndesc;
53 static void help(void);
54 static void show_connlist(void);
55 static void show_serverlist(char *server);
56 static void show_userlist(char *server);
57 static void list_volumes(char *server);
58 static void str_trim_right(char *s, char c);
62 ncp_get_connid(char *server, int justattach)
65 struct ncp_conn_loginfo li;
67 connid = ncp_conn_find(server, NULL);
69 ncp_conn_getinfo(connid, &conndesc);
74 printf("You are not attached to server %s\n",server);
77 printf("You are not attached to any server\n");
80 ncp_li_init(&li, 0, NULL);
82 ncp_li_setserver(&li, server);
83 error = ncp_find_fileserver(&li, AF_IPX, NULL);
85 printf("Could not find server %s\n", li.server);
89 error = ncp_find_fileserver(&li, AF_IPX, NULL);
91 printf("Can't find any file server\n");
95 error = ncp_connect(&li, &connid);
97 printf("Can't attach to a nearest server\n");
100 ncp_conn_getinfo(connid, &conndesc);
104 static struct ncp_bitname conn_statenames [] = {
105 {NCPFL_INVALID, "invalid"},
106 {NCPFL_LOGGED, "active"},
107 {NCPFL_PERMANENT, "permanent"},
108 {NCPFL_PRIMARY, "primary"},
113 str_trim_right(char *s, char c)
117 for (len = strlen(s) - 1; len > 0 && s[len] == c; len--)
127 struct ncp_conn_stat *ncsp;
129 printf("Active NCP connections:\n");
135 printf(" refid server:user(connid), owner:group(mode), refs, <state>\n");
137 ncsp = (struct ncp_conn_stat*)(((int*)p)+1);
139 printf("%6d %s:%s(%d), %s:%s(%o), %d, %s",
140 ncsp->connRef, ncsp->li.server,ncsp->user,ncsp->connid,
141 user_from_uid(ncsp->owner, 0),
142 group_from_gid(ncsp->group, 0),
143 ncsp->li.access_mode,
145 ncp_printb(buf, ncsp->flags, conn_statenames));
154 show_serverlist(char *server)
156 int found = 0, connid;
157 struct ncp_bindery_object obj;
158 const char *pattern = "*";
160 connid = ncp_get_connid(server, 1);
163 printf("Visible servers (from %s):\n", conndesc.li.server);
164 printf("Name Network Node Port\n");
165 printf("----------------------------------------------- -------- ------------ ----\n");
166 obj.object_id = 0xffffffff;
168 while (ncp_scan_bindery_object(connid, obj.object_id, NCP_BINDERY_FSERVER,
169 pattern, &obj) == 0) {
170 struct nw_property prop;
171 struct ipx_addr *naddr = (struct ipx_addr *) ∝
174 printf("%-48s", obj.object_name);
176 if (ncp_read_property_value(connid, NCP_BINDERY_FSERVER,
177 obj.object_name, 1, "NET_ADDRESS",
179 ipx_print_addr(naddr);
185 printf("No servers found\n");
192 show_userlist(char *server)
194 int connid, error, i;
195 struct ncp_file_server_info info;
196 struct ncp_bindery_object user;
198 struct ipx_addr addr;
201 connid = ncp_get_connid(server, 0);
202 if (connid < 0) return;
203 if (ncp_get_file_server_information(connid, &info) != 0) {
204 perror("Could not get server information");
207 printf("User information for server %s\n",info.ServerName);
208 printf("\n%-6s%-21s%-27s%-12s\n"
209 "---------------------------------------------"
210 "---------------------------------\n",
215 for (i = 1; i <= info.MaximumServiceConnections; i++) {
218 error = ncp_get_stations_logged_info(connid, i, &user, &login_time);
220 memset(&addr, 0, sizeof(addr));
221 error = ncp_get_internet_address(connid, i, &addr, &conn_type);
223 memcpy(name, user.object_name, 48);
224 str_trim_right(name, ' ');
225 printf("%4d: %-20s ", i, name);
226 ipx_print_addr(&addr);
228 printf("%s", ctime(&login_time));
235 show_queuelist(char *server, char *patt)
237 struct ncp_bindery_object q;
238 int found = 0, connid;
239 char default_pattern[] = "*";
240 char *pattern = default_pattern;
242 connid = ncp_get_connid(server, 1);
243 if (connid < 0) return;
246 ncp_str_upper(pattern);
248 printf("\nServer: %s\n", server);
249 printf("%-52s%-10s\n"
250 "-----------------------------------------------"
254 q.object_id = 0xffffffff;
256 while (ncp_scan_bindery_object(connid, q.object_id,
257 NCP_BINDERY_PQUEUE, pattern, &q) == 0)
260 printf("%-52s", q.object_name);
261 printf("%08X\n", (unsigned int) q.object_id);
265 printf("No queues found\n");
271 list_volumes(char *server)
273 int found = 0, connid, i, error;
274 struct ncp_file_server_info si;
275 char volname[NCP_VOLNAME_LEN+1];
277 connid = ncp_get_connid(server, 1);
278 if (connid < 0) return;
280 error = ncp_get_file_server_information(connid, &si);
282 ncp_error("Can't get information for server %s", error, server);
286 printf("\nMounted volumes on server %s:\n", server);
287 printf("Number Name\n");
288 printf("------ -----------------------------------------------\n");
290 for(i = 0; i < si.NumberMountedVolumes; i++) {
291 if (NWGetVolumeName(connid, i, volname))
294 printf("%6d %s\n", i, volname);
298 printf("No volumes found ?\n");
302 struct ncp_bind_type {
307 static struct ncp_bind_type btypes[] = {
308 {NCP_BINDERY_USER, "USER"},
309 {NCP_BINDERY_UGROUP, "GROUP"},
310 {NCP_BINDERY_PSERVER, "PSERVER"},
316 list_bindery(char *server, char *type, char *patt)
318 struct ncp_bindery_object q;
319 int i, found = 0, connid;
320 char default_pattern[] = "*";
321 char *pattern = default_pattern;
327 for(i = 0; btypes[i].type; i++) {
328 if (strcmp(btypes[i].name, type) == 0) {
329 objtype = btypes[i].type;
334 printf("Bindery object of type %s is unknown\n", type);
339 ncp_str_upper(pattern);
340 connid = ncp_get_connid(server, 1);
341 if (connid < 0) return;
343 connid = ncp_get_connid(server, 1);
344 if (connid < 0) return;
347 printf("\nServer: %s\n", server);
348 printf("%-52s%-10s\n"
349 "-----------------------------------------------"
354 q.object_id = 0xffffffff;
355 while (ncp_scan_bindery_object(connid, q.object_id,
356 objtype, pattern, &q) == 0)
359 printf("%-52s", q.object_name);
360 printf("%08X\n", (unsigned int) q.object_id);
364 printf("No bindery objects found\n");
370 LO_NONE, LO_SERVERS, LO_QUEUES, LO_BINDERY, LO_USERS, LO_VOLUMES
376 main(int argc, char *argv[])
378 int opt, wdone = 0, nargs = 0, i;
380 char *args[MAX_ARGS];
382 bzero(args, sizeof(args));
385 while ((opt = getopt(argc, argv, "h")) != -1) {
401 switch(argv[optind++][0]) {
425 printf("Unknown command %s\n", argv[optind-1]);
428 for (i = 0; i < MAX_ARGS; i++) {
430 args[i] = argv[optind++];
431 } else if (i < nargs) {
432 printf("Not enough arguments\n");
440 show_serverlist(args[0]);
444 show_userlist(args[0]);
448 show_queuelist(args[0], args[1]);
452 list_volumes(args[0]);
456 list_bindery(args[0], args[1], args[2]);
469 printf("usage: %s command [args]\n", __progname);
470 printf("where commands are:\n"
471 " b server user|group [pattern] list bindery objects on server\n"
472 " c display opened connections\n"
473 " s [server] display known servers\n"
474 " u server list logged-in users on server\n"
475 " q server [pattern] list print queues on server\n"
476 " v server list mounted volumes on a specified server\n"