Commit | Line | Data |
---|---|---|
dabf4152 AM |
1 | /* |
2 | Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com> | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify | |
5 | it under the terms of the GNU Lesser General Public License as published by | |
6 | the Free Software Foundation; either version 2.1 of the License, or | |
7 | (at your option) any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU Lesser General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU Lesser General Public License | |
15 | along with this program; if not, see <http://www.gnu.org/licenses/>. | |
16 | */ | |
5670ec6e AM |
17 | #ifdef WIN32 |
18 | #include "win32_compat.h" | |
19 | #endif/*WIN32*/ | |
dabf4152 AM |
20 | |
21 | #include <stdio.h> | |
22 | #include <errno.h> | |
23 | #include <sys/stat.h> | |
24 | #include <rpc/rpc.h> | |
25 | #include <rpc/xdr.h> | |
26 | #include "libnfs.h" | |
27 | #include "libnfs-raw.h" | |
28 | #include "libnfs-private.h" | |
29 | #include "libnfs-raw-rquota.h" | |
30 | ||
31 | ||
32 | ||
33 | char *rquotastat_to_str(int error) | |
34 | { | |
35 | switch (error) { | |
36 | case RQUOTA_OK: return "RQUOTA_OK"; break; | |
37 | case RQUOTA_NOQUOTA: return "RQUOTA_NOQUOTA"; break; | |
38 | case RQUOTA_EPERM: return "RQUOTA_EPERM"; break; | |
39 | }; | |
40 | return "unknown rquota error"; | |
41 | } | |
42 | ||
43 | int rquotastat_to_errno(int error) | |
44 | { | |
45 | switch (error) { | |
46 | case RQUOTA_OK: return 0; break; | |
47 | case RQUOTA_NOQUOTA: return -ENOENT; break; | |
48 | case RQUOTA_EPERM: return -EPERM; break; | |
49 | }; | |
50 | return -ENOENT; | |
51 | } | |
52 | ||
53 | ||
54 | int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
55 | { | |
56 | struct rpc_pdu *pdu; | |
57 | ||
58 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
59 | if (pdu == NULL) { | |
60 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/null call"); | |
61 | return -1; | |
62 | } | |
63 | ||
64 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
65 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/null call"); | |
66 | rpc_free_pdu(rpc, pdu); | |
67 | return -2; | |
68 | } | |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data) | |
74 | { | |
75 | struct rpc_pdu *pdu; | |
76 | GETQUOTA1args args; | |
77 | ||
78 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
79 | if (pdu == NULL) { | |
80 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getquota call"); | |
81 | return -1; | |
82 | } | |
83 | ||
84 | args.export = export; | |
85 | args.uid = uid; | |
86 | ||
87 | if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) { | |
88 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args"); | |
89 | rpc_free_pdu(rpc, pdu); | |
90 | return -2; | |
91 | } | |
92 | ||
93 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
94 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getquota call"); | |
95 | rpc_free_pdu(rpc, pdu); | |
96 | return -3; | |
97 | } | |
98 | ||
99 | return 0; | |
100 | } | |
101 | ||
102 | int rpc_rquota1_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data) | |
103 | { | |
104 | struct rpc_pdu *pdu; | |
105 | GETQUOTA1args args; | |
106 | ||
107 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
108 | if (pdu == NULL) { | |
109 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getactivequota call"); | |
110 | return -1; | |
111 | } | |
112 | ||
113 | args.export = export; | |
114 | args.uid = uid; | |
115 | ||
116 | if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) { | |
117 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args"); | |
118 | rpc_free_pdu(rpc, pdu); | |
119 | return -2; | |
120 | } | |
121 | ||
122 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
123 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getactivequota call"); | |
124 | rpc_free_pdu(rpc, pdu); | |
125 | return -3; | |
126 | } | |
127 | ||
128 | return 0; | |
129 | } | |
130 | ||
131 | ||
132 | int rpc_rquota2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
133 | { | |
134 | struct rpc_pdu *pdu; | |
135 | ||
136 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
137 | if (pdu == NULL) { | |
138 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/null call"); | |
139 | return -1; | |
140 | } | |
141 | ||
142 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
143 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/null call"); | |
144 | rpc_free_pdu(rpc, pdu); | |
145 | return -2; | |
146 | } | |
147 | ||
148 | return 0; | |
149 | } | |
150 | ||
151 | int rpc_rquota2_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data) | |
152 | { | |
153 | struct rpc_pdu *pdu; | |
154 | GETQUOTA2args args; | |
155 | ||
156 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
157 | if (pdu == NULL) { | |
158 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getquota call"); | |
159 | return -1; | |
160 | } | |
161 | ||
162 | args.export = export; | |
163 | args.type = type; | |
164 | args.uid = uid; | |
165 | ||
166 | if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) { | |
167 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args"); | |
168 | rpc_free_pdu(rpc, pdu); | |
169 | return -2; | |
170 | } | |
171 | ||
172 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
173 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getquota call"); | |
174 | rpc_free_pdu(rpc, pdu); | |
175 | return -3; | |
176 | } | |
177 | ||
178 | return 0; | |
179 | } | |
180 | ||
181 | int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data) | |
182 | { | |
183 | struct rpc_pdu *pdu; | |
184 | GETQUOTA2args args; | |
185 | ||
186 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
187 | if (pdu == NULL) { | |
188 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getactivequota call"); | |
189 | return -1; | |
190 | } | |
191 | ||
192 | args.export = export; | |
193 | args.type = type; | |
194 | args.uid = uid; | |
195 | ||
196 | if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) { | |
197 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args"); | |
198 | rpc_free_pdu(rpc, pdu); | |
199 | return -2; | |
200 | } | |
201 | ||
202 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
203 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getactivequota call"); | |
204 | rpc_free_pdu(rpc, pdu); | |
205 | return -3; | |
206 | } | |
207 | ||
208 | return 0; | |
209 | } |