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>
45 #include <netncp/ncp_lib.h>
47 extern char *__progname;
49 static struct ncp_conn_stat conndesc;
51 static void help(void);
52 static void show_connlist(void);
53 static void show_serverlist(char *server);
54 static void show_userlist(char *server);
55 static void list_volumes(char *server);
56 static void str_trim_right(char *s, char c);
60 ncp_get_connid(char *server, int justattach)
63 struct ncp_conn_loginfo li;
65 connid = ncp_conn_find(server, NULL);
67 ncp_conn_getinfo(connid, &conndesc);
72 printf("You are not attached to server %s\n",server);
75 printf("You are not attached to any server\n");
78 ncp_li_init(&li, 0, NULL);
80 ncp_li_setserver(&li, server);
81 error = ncp_find_fileserver(&li, AF_IPX, NULL);
83 printf("Could not find server %s\n", li.server);
87 error = ncp_find_fileserver(&li, AF_IPX, NULL);
89 printf("Can't find any file server\n");
93 error = ncp_connect(&li, &connid);
95 printf("Can't attach to a nearest server\n");
98 ncp_conn_getinfo(connid, &conndesc);
102 static struct ncp_bitname conn_statenames [] = {
103 {NCPFL_INVALID, "invalid"},
104 {NCPFL_LOGGED, "active"},
105 {NCPFL_PERMANENT, "permanent"},
106 {NCPFL_PRIMARY, "primary"},
111 str_trim_right(char *s, char c)
115 for (len = strlen(s) - 1; len > 0 && s[len] == c; len--)
125 struct ncp_conn_stat *ncsp;
127 printf("Active NCP connections:\n");
133 printf(" refid server:user(connid), owner:group(mode), refs, <state>\n");
135 ncsp = (struct ncp_conn_stat*)(((int*)p)+1);
137 printf("%6d %s:%s(%d), %s:%s(%o), %d, %s",
138 ncsp->connRef, ncsp->li.server,ncsp->user,ncsp->connid,
139 user_from_uid(ncsp->owner, 0),
140 group_from_gid(ncsp->group, 0),
141 ncsp->li.access_mode,
143 ncp_printb(buf, ncsp->flags, conn_statenames));
152 show_serverlist(char *server)
154 int found = 0, connid;
155 struct ncp_bindery_object obj;
158 connid = ncp_get_connid(server, 1);
161 printf("Visible servers (from %s):\n", conndesc.li.server);
162 printf("Name Network Node Port\n");
163 printf("----------------------------------------------- -------- ------------ ----\n");
164 obj.object_id = 0xffffffff;
166 while (ncp_scan_bindery_object(connid, obj.object_id, NCP_BINDERY_FSERVER,
167 pattern, &obj) == 0) {
168 struct nw_property prop;
169 struct ipx_addr *naddr = (struct ipx_addr *) ∝
172 printf("%-48s", obj.object_name);
174 if (ncp_read_property_value(connid, NCP_BINDERY_FSERVER,
175 obj.object_name, 1, "NET_ADDRESS",
177 ipx_print_addr(naddr);
183 printf("No servers found\n");
190 show_userlist(char *server)
192 int connid, error, i;
193 struct ncp_file_server_info info;
194 struct ncp_bindery_object user;
196 struct ipx_addr addr;
199 connid = ncp_get_connid(server, 0);
200 if (connid < 0) return;
201 if (ncp_get_file_server_information(connid, &info) != 0) {
202 perror("Could not get server information");
205 printf("User information for server %s\n",info.ServerName);
206 printf("\n%-6s%-21s%-27s%-12s\n"
207 "---------------------------------------------"
208 "---------------------------------\n",
213 for (i = 1; i <= info.MaximumServiceConnections; i++) {
216 error = ncp_get_stations_logged_info(connid, i, &user, &login_time);
218 memset(&addr, 0, sizeof(addr));
219 error = ncp_get_internet_address(connid, i, &addr, &conn_type);
221 memcpy(name, user.object_name, 48);
222 str_trim_right(name, ' ');
223 printf("%4d: %-20s ", i, name);
224 ipx_print_addr(&addr);
226 printf("%s", ctime(&login_time));
233 show_queuelist(char *server, char *patt)
235 struct ncp_bindery_object q;
236 int found = 0, connid;
237 char default_pattern[] = "*";
238 char *pattern = default_pattern;
240 connid = ncp_get_connid(server, 1);
241 if (connid < 0) return;
244 ncp_str_upper(pattern);
246 printf("\nServer: %s\n", server);
247 printf("%-52s%-10s\n"
248 "-----------------------------------------------"
252 q.object_id = 0xffffffff;
254 while (ncp_scan_bindery_object(connid, q.object_id,
255 NCP_BINDERY_PQUEUE, pattern, &q) == 0)
258 printf("%-52s", q.object_name);
259 printf("%08X\n", (unsigned int) q.object_id);
263 printf("No queues found\n");
269 list_volumes(char *server)
271 int found = 0, connid, i, error;
272 struct ncp_file_server_info si;
273 char volname[NCP_VOLNAME_LEN+1];
275 connid = ncp_get_connid(server, 1);
276 if (connid < 0) return;
278 error = ncp_get_file_server_information(connid, &si);
280 ncp_error("Can't get information for server %s", error, server);
284 printf("\nMounted volumes on server %s:\n", server);
285 printf("Number Name\n");
286 printf("------ -----------------------------------------------\n");
288 for(i = 0; i < si.NumberMountedVolumes; i++) {
289 if (NWGetVolumeName(connid, i, volname))
292 printf("%6d %s\n", i, volname);
296 printf("No volumes found ?\n");
300 struct ncp_bind_type {
305 static struct ncp_bind_type btypes[] = {
306 {NCP_BINDERY_USER, "USER"},
307 {NCP_BINDERY_UGROUP, "GROUP"},
308 {NCP_BINDERY_PSERVER, "PSERVER"},
314 list_bindery(char *server, char *type, char *patt)
316 struct ncp_bindery_object q;
317 int i, found = 0, connid;
318 char default_pattern[] = "*";
319 char *pattern = default_pattern;
325 for(i = 0; btypes[i].type; i++) {
326 if (strcmp(btypes[i].name, type) == 0) {
327 objtype = btypes[i].type;
332 printf("Bindery object of type %s is unknown\n", type);
337 ncp_str_upper(pattern);
338 connid = ncp_get_connid(server, 1);
339 if (connid < 0) return;
341 connid = ncp_get_connid(server, 1);
342 if (connid < 0) return;
345 printf("\nServer: %s\n", server);
346 printf("%-52s%-10s\n"
347 "-----------------------------------------------"
352 q.object_id = 0xffffffff;
353 while (ncp_scan_bindery_object(connid, q.object_id,
354 objtype, pattern, &q) == 0)
357 printf("%-52s", q.object_name);
358 printf("%08X\n", (unsigned int) q.object_id);
362 printf("No bindery objects found\n");
368 LO_NONE, LO_SERVERS, LO_QUEUES, LO_BINDERY, LO_USERS, LO_VOLUMES
374 main(int argc, char *argv[])
376 int opt, nargs = 0, i;
378 char *args[MAX_ARGS];
380 bzero(args, sizeof(args));
383 while ((opt = getopt(argc, argv, "h")) != -1) {
399 switch(argv[optind++][0]) {
423 printf("Unknown command %s\n", argv[optind-1]);
426 for (i = 0; i < MAX_ARGS; i++) {
428 args[i] = argv[optind++];
429 } else if (i < nargs) {
430 printf("Not enough arguments\n");
438 show_serverlist(args[0]);
441 show_userlist(args[0]);
444 show_queuelist(args[0], args[1]);
447 list_volumes(args[0]);
450 list_bindery(args[0], args[1], args[2]);
462 printf("usage: %s command [args]\n", __progname);
463 printf("where commands are:\n"
464 " b server user|group [pattern] list bindery objects on server\n"
465 " c display opened connections\n"
466 " s [server] display known servers\n"
467 " u server list logged-in users on server\n"
468 " q server [pattern] list print queues on server\n"
469 " v server list mounted volumes on a specified server\n"