xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rquota.c (revision 89b2a9fbeabf42fa54594df0e5927bcc50a07cc9)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS	*/
28 
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <setjmp.h>
32 #include <string.h>
33 
34 #include <netinet/in.h>
35 #include <rpc/types.h>
36 #include <rpc/rpc.h>
37 #include <rpc/xdr.h>
38 #include <rpc/auth.h>
39 #include <rpc/clnt.h>
40 #include <rpc/rpc_msg.h>
41 #include <rpcsvc/rquota.h>
42 #include "snoop.h"
43 
44 extern char *dlc_header;
45 extern jmp_buf xdr_err;
46 
47 static char *procnames_short[] = {
48 	"Null",		/*  0 */
49 	"GETQUOTA",	/*  1 */
50 	"GETACTIVE",	/*  2 */
51 };
52 
53 static char *procnames_long[] = {
54 	"Null procedure",	/*  0 */
55 	"Get quotas",		/*  1 */
56 	"Get active quotas",	/*  2 */
57 };
58 
59 #define	MAXPROC	2
60 
61 static void show_quota(void);
62 
63 void
64 interpret_rquota(flags, type, xid, vers, proc, data, len)
65 	int flags, type, xid, vers, proc;
66 	char *data;
67 	int len;
68 {
69 	char *line;
70 	char buff[RQ_PATHLEN + 1];
71 	int status;
72 	int uid;
73 
74 	if (proc < 0 || proc > MAXPROC)
75 		return;
76 
77 	if (flags & F_SUM) {
78 		if (setjmp(xdr_err)) {
79 			return;
80 		}
81 
82 		line = get_sum_line();
83 
84 		if (type == CALL) {
85 			(void) getxdr_string(buff, RQ_PATHLEN);
86 			uid = getxdr_long();
87 			(void) sprintf(line,
88 				"RQUOTA C %s Uid=%d Path=%s",
89 				procnames_short[proc],
90 				uid, buff);
91 
92 			check_retransmit(line, xid);
93 		} else {
94 			(void) sprintf(line, "RQUOTA R %s ",
95 				procnames_short[proc]);
96 			line += strlen(line);
97 			status = getxdr_u_long();
98 			if (status == Q_OK)
99 				(void) sprintf(line, "OK");
100 			else if (status == Q_NOQUOTA)
101 				(void) sprintf(line, "No quota");
102 			else if (status == Q_EPERM)
103 				(void) sprintf(line, "No permission");
104 		}
105 	}
106 
107 	if (flags & F_DTAIL) {
108 		show_header("RQUOTA:  ", "Remote Quota Check", len);
109 		show_space();
110 		if (setjmp(xdr_err)) {
111 			return;
112 		}
113 		(void) sprintf(get_line(0, 0),
114 			"Proc = %d (%s)",
115 			proc, procnames_long[proc]);
116 
117 		if (type == CALL) {
118 			switch (proc) {
119 			case  RQUOTAPROC_GETQUOTA:
120 			case RQUOTAPROC_GETACTIVEQUOTA:
121 				(void) showxdr_string(RQ_PATHLEN,
122 					"Path = %s");
123 				(void) showxdr_long("User id = %d");
124 				break;
125 			}
126 		} else {
127 			status = getxdr_u_long();
128 			(void) sprintf(get_line(0, 0),
129 				"Status = %lu (%s)",
130 				status,
131 				status == Q_OK ? "OK" :
132 				status == Q_NOQUOTA ? "No quota" :
133 				status == Q_EPERM ? "No permission":"");
134 
135 			if (status == Q_OK)
136 				show_quota();
137 		}
138 
139 		show_trailer();
140 	}
141 }
142 
143 static void
144 show_quota()
145 {
146 	int active;
147 
148 	(void) showxdr_u_long("Block size = %lu");
149 	active = getxdr_u_long();
150 	(void) sprintf(get_line(0, 0),
151 		"         Quota checking = %lu (%s)",
152 		active,
153 		active ? "on" : "off");
154 	(void) showxdr_u_long("      Blocks hard limit = %lu");
155 	(void) showxdr_u_long("      Blocks soft limit = %lu");
156 	(void) showxdr_u_long("    Current block count = %lu");
157 	(void) show_space();
158 	(void) showxdr_u_long("        File hard limit = %lu");
159 	(void) showxdr_u_long("        File soft limit = %lu");
160 	(void) showxdr_u_long("     Current file count = %lu");
161 	(void) show_space();
162 	(void) showxdr_u_long("Excessive blocks limit  = %lu sec");
163 	(void) showxdr_u_long("Excessive files  limit  = %lu sec");
164 }
165