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
34 #include <sys/param.h>
41 #include <netncp/ncp_lib.h>
43 extern char *__progname;
45 static struct ncp_conn_stat conndesc;
47 static void help(void);
48 static void show_connlist(void);
49 static void show_serverlist(char *server);
50 static void show_userlist(char *server);
51 static void list_volumes(char *server);
52 static void str_trim_right(char *s, char c);
56 ncp_get_connid(char *server, int justattach) {
58 struct ncp_conn_loginfo li;
60 connid = ncp_conn_find(server, NULL);
62 ncp_conn_getinfo(connid, &conndesc);
67 printf("You are not attached to server %s\n",server);
70 printf("You are not attached to any server\n");
73 ncp_li_init(&li, 0, NULL);
75 ncp_li_setserver(&li, server);
76 error = ncp_find_fileserver(&li, AF_IPX, NULL);
78 printf("Could not find server %s\n", li.server);
82 error = ncp_find_fileserver(&li, AF_IPX, NULL);
84 printf("Can't find any file server\n");
88 error = ncp_connect(&li, &connid);
90 printf("Can't attach to a nearest server\n");
93 ncp_conn_getinfo(connid, &conndesc);
97 static struct ncp_bitname conn_statenames [] = {
98 {NCPFL_INVALID, "invalid"},
99 {NCPFL_LOGGED, "active"},
100 {NCPFL_PERMANENT, "permanent"},
101 {NCPFL_PRIMARY, "primary"},
106 str_trim_right(char *s, char c) {
109 for(len = strlen(s) - 1; len > 0 && s[len] == c; len--)
114 show_connlist(void) {
118 struct ncp_conn_stat *ncsp;
120 printf("Active NCP connections:\n");
126 printf(" refid server:user(connid), owner:group(mode), refs, <state>\n");
128 ncsp = (struct ncp_conn_stat*)(((int*)p)+1);
130 printf("%6d %s:%s(%d), %s:%s(%o), %d, %s",
131 ncsp->connRef, ncsp->li.server,ncsp->user,ncsp->connid,
132 user_from_uid(ncsp->owner, 0),
133 group_from_gid(ncsp->group, 0),
134 ncsp->li.access_mode,
136 ncp_printb(buf, ncsp->flags, conn_statenames));
145 show_serverlist(char *server) {
146 int found = 0, connid;
147 struct ncp_bindery_object obj;
150 connid = ncp_get_connid(server, 1);
153 printf("Visible servers (from %s):\n", conndesc.li.server);
154 printf("Name Network Node Port\n");
155 printf("----------------------------------------------- -------- ------------ ----\n");
156 obj.object_id = 0xffffffff;
158 while (ncp_scan_bindery_object(connid, obj.object_id, NCP_BINDERY_FSERVER,
159 pattern, &obj) == 0) {
160 struct nw_property prop;
161 struct ipx_addr *naddr = (struct ipx_addr *) ∝
164 printf("%-48s", obj.object_name);
166 if (ncp_read_property_value(connid, NCP_BINDERY_FSERVER,
167 obj.object_name, 1, "NET_ADDRESS",
169 ipx_print_addr(naddr);
175 printf("No servers found\n");
182 show_userlist(char *server) {
183 int connid, error, i;
184 struct ncp_file_server_info info;
185 struct ncp_bindery_object user;
187 struct ipx_addr addr;
190 connid = ncp_get_connid(server, 0);
191 if (connid < 0) return;
192 if (ncp_get_file_server_information(connid, &info) != 0) {
193 perror("Could not get server information");
196 printf("User information for server %s\n",info.ServerName);
197 printf("\n%-6s%-21s%-27s%-12s\n"
198 "---------------------------------------------"
199 "---------------------------------\n",
204 for (i = 1; i <= info.MaximumServiceConnections; i++) {
207 error = ncp_get_stations_logged_info(connid, i, &user, &login_time);
209 memset(&addr, 0, sizeof(addr));
210 error = ncp_get_internet_address(connid, i, &addr, &conn_type);
212 memcpy(name, user.object_name, 48);
213 str_trim_right(name, ' ');
214 printf("%4d: %-20s ", i, name);
215 ipx_print_addr(&addr);
217 printf("%s", ctime(&login_time));
224 show_queuelist(char *server, char *patt) {
225 struct ncp_bindery_object q;
226 int found = 0, connid;
227 char default_pattern[] = "*";
228 char *pattern = default_pattern;
230 connid = ncp_get_connid(server, 1);
231 if (connid < 0) return;
234 ncp_str_upper(pattern);
236 printf("\nServer: %s\n", server);
237 printf("%-52s%-10s\n"
238 "-----------------------------------------------"
242 q.object_id = 0xffffffff;
244 while (ncp_scan_bindery_object(connid, q.object_id,
245 NCP_BINDERY_PQUEUE, pattern, &q) == 0)
248 printf("%-52s", q.object_name);
249 printf("%08X\n", (unsigned int) q.object_id);
253 printf("No queues found\n");
259 list_volumes(char *server) {
260 int found = 0, connid, i, error;
261 struct ncp_file_server_info si;
262 char volname[NCP_VOLNAME_LEN+1];
264 connid = ncp_get_connid(server, 1);
265 if (connid < 0) return;
267 error = ncp_get_file_server_information(connid, &si);
269 ncp_error("Can't get information for server %s", error, server);
273 printf("\nMounted volumes on server %s:\n", server);
274 printf("Number Name\n");
275 printf("------ -----------------------------------------------\n");
277 for(i = 0; i < si.NumberMountedVolumes; i++) {
278 if (NWGetVolumeName(connid, i, volname))
281 printf("%6d %s\n", i, volname);
285 printf("No volumes found ?\n");
289 struct ncp_bind_type {
294 static struct ncp_bind_type btypes[] = {
295 {NCP_BINDERY_USER, "USER"},
296 {NCP_BINDERY_UGROUP, "GROUP"},
297 {NCP_BINDERY_PSERVER, "PSERVER"},
303 list_bindery(char *server, char *type, char *patt) {
304 struct ncp_bindery_object q;
305 int i, found = 0, connid;
306 char default_pattern[] = "*";
307 char *pattern = default_pattern;
313 for(i = 0; btypes[i].type; i++) {
314 if (strcmp(btypes[i].name, type) == 0) {
315 objtype = btypes[i].type;
320 printf("Bindery object of type %s is unknown\n", type);
325 ncp_str_upper(pattern);
326 connid = ncp_get_connid(server, 1);
327 if (connid < 0) return;
329 connid = ncp_get_connid(server, 1);
330 if (connid < 0) return;
333 printf("\nServer: %s\n", server);
334 printf("%-52s%-10s\n"
335 "-----------------------------------------------"
340 q.object_id = 0xffffffff;
341 while (ncp_scan_bindery_object(connid, q.object_id,
342 objtype, pattern, &q) == 0)
345 printf("%-52s", q.object_name);
346 printf("%08X\n", (unsigned int) q.object_id);
350 printf("No bindery objects found\n");
356 LO_NONE, LO_SERVERS, LO_QUEUES, LO_BINDERY, LO_USERS, LO_VOLUMES
362 main(int argc, char *argv[]) {
363 int opt, wdone = 0, nargs = 0, i;
365 char *args[MAX_ARGS];
367 bzero(args, sizeof(args));
370 while ((opt = getopt(argc, argv, "h")) != EOF) {
386 switch(argv[optind++][0]) {
410 printf("Unknown command %s\n", argv[optind-1]);
413 for (i = 0; i < MAX_ARGS; i++) {
415 args[i] = argv[optind++];
416 } else if (i < nargs) {
417 printf("Not enough arguments\n");
425 show_serverlist(args[0]);
429 show_userlist(args[0]);
433 show_queuelist(args[0], args[1]);
437 list_volumes(args[0]);
441 list_bindery(args[0], args[1], args[2]);
453 printf("usage: %s command [args]\n", __progname);
454 printf("where commands are:\n"
455 " b server user|group [pattern] list bindery objects on server\n"
456 " c display opened connections\n"
457 " s [server] display known servers\n"
458 " u server list logged-in users on server\n"
459 " q server [pattern] list print queues on server\n"
460 " v server list mounted volumes on a specified server\n"