summaryrefslogtreecommitdiff
path: root/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_rquota.c
blob: 13f5dc6cd3311bf47f44e3112a6ee27a51a7c18e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
 * All rights reserved.
 */

#ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS	*/

#include <sys/types.h>
#include <sys/errno.h>
#include <setjmp.h>
#include <string.h>

#include <netinet/in.h>
#include <rpc/types.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpc/auth.h>
#include <rpc/clnt.h>
#include <rpc/rpc_msg.h>
#include <rpcsvc/rquota.h>
#include "snoop.h"

extern char *dlc_header;
extern jmp_buf xdr_err;

static char *procnames_short[] = {
	"Null",		/*  0 */
	"GETQUOTA",	/*  1 */
	"GETACTIVE",	/*  2 */
};

static char *procnames_long[] = {
	"Null procedure",	/*  0 */
	"Get quotas",		/*  1 */
	"Get active quotas",	/*  2 */
};

#define	MAXPROC	2

static void show_quota(void);

void
interpret_rquota(flags, type, xid, vers, proc, data, len)
	int flags, type, xid, vers, proc;
	char *data;
	int len;
{
	char *line;
	char buff[RQ_PATHLEN + 1];
	int status;
	int uid;

	if (proc < 0 || proc > MAXPROC)
		return;

	if (flags & F_SUM) {
		if (setjmp(xdr_err)) {
			return;
		}

		line = get_sum_line();

		if (type == CALL) {
			(void) getxdr_string(buff, RQ_PATHLEN);
			uid = getxdr_long();
			(void) sprintf(line,
				"RQUOTA C %s Uid=%d Path=%s",
				procnames_short[proc],
				uid, buff);

			check_retransmit(line, xid);
		} else {
			(void) sprintf(line, "RQUOTA R %s ",
				procnames_short[proc]);
			line += strlen(line);
			status = getxdr_u_long();
			if (status == Q_OK)
				(void) sprintf(line, "OK");
			else if (status == Q_NOQUOTA)
				(void) sprintf(line, "No quota");
			else if (status == Q_EPERM)
				(void) sprintf(line, "No permission");
		}
	}

	if (flags & F_DTAIL) {
		show_header("RQUOTA:  ", "Remote Quota Check", len);
		show_space();
		if (setjmp(xdr_err)) {
			return;
		}
		(void) sprintf(get_line(0, 0),
			"Proc = %d (%s)",
			proc, procnames_long[proc]);

		if (type == CALL) {
			switch (proc) {
			case  RQUOTAPROC_GETQUOTA:
			case RQUOTAPROC_GETACTIVEQUOTA:
				(void) showxdr_string(RQ_PATHLEN,
					"Path = %s");
				(void) showxdr_long("User id = %d");
				break;
			}
		} else {
			status = getxdr_u_long();
			(void) sprintf(get_line(0, 0),
				"Status = %lu (%s)",
				status,
				status == Q_OK ? "OK" :
				status == Q_NOQUOTA ? "No quota" :
				status == Q_EPERM ? "No permission":"");

			if (status == Q_OK)
				show_quota();
		}

		show_trailer();
	}
}

static void
show_quota()
{
	int active;

	(void) showxdr_u_long("Block size = %lu");
	active = getxdr_u_long();
	(void) sprintf(get_line(0, 0),
		"         Quota checking = %lu (%s)",
		active,
		active ? "on" : "off");
	(void) showxdr_u_long("      Blocks hard limit = %lu");
	(void) showxdr_u_long("      Blocks soft limit = %lu");
	(void) showxdr_u_long("    Current block count = %lu");
	(void) show_space();
	(void) showxdr_u_long("        File hard limit = %lu");
	(void) showxdr_u_long("        File soft limit = %lu");
	(void) showxdr_u_long("     Current file count = %lu");
	(void) show_space();
	(void) showxdr_u_long("Excessive blocks limit  = %lu sec");
	(void) showxdr_u_long("Excessive files  limit  = %lu sec");
}