Commit | Line | Data |
---|---|---|
05a777d9 RS |
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 | */ | |
17 | ||
eecdc4f3 RS |
18 | #if defined(WIN32) |
19 | #include <winsock2.h> | |
20 | #endif | |
21 | ||
05a777d9 RS |
22 | #include <stdio.h> |
23 | #include <errno.h> | |
24 | #include <sys/stat.h> | |
c353ec24 | 25 | #include <rpc/rpc.h> |
05a777d9 RS |
26 | #include <rpc/xdr.h> |
27 | #include "libnfs.h" | |
28 | #include "libnfs-raw.h" | |
29 | #include "libnfs-private.h" | |
30 | #include "libnfs-raw-rquota.h" | |
31 | ||
32 | ||
33 | ||
34 | char *rquotastat_to_str(int error) | |
35 | { | |
36 | switch (error) { | |
37 | case RQUOTA_OK: return "RQUOTA_OK"; break; | |
38 | case RQUOTA_NOQUOTA: return "RQUOTA_NOQUOTA"; break; | |
39 | case RQUOTA_EPERM: return "RQUOTA_EPERM"; break; | |
40 | }; | |
41 | return "unknown rquota error"; | |
42 | } | |
43 | ||
44 | int rquotastat_to_errno(int error) | |
45 | { | |
46 | switch (error) { | |
47 | case RQUOTA_OK: return 0; break; | |
48 | case RQUOTA_NOQUOTA: return -ENOENT; break; | |
49 | case RQUOTA_EPERM: return -EPERM; break; | |
50 | }; | |
51 | return -ENOENT; | |
52 | } | |
53 | ||
54 | ||
55 | int rpc_rquota1_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
56 | { | |
57 | struct rpc_pdu *pdu; | |
58 | ||
59 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
60 | if (pdu == NULL) { | |
77c23b46 | 61 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/null call"); |
05a777d9 RS |
62 | return -1; |
63 | } | |
64 | ||
65 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
77c23b46 | 66 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/null call"); |
05a777d9 RS |
67 | rpc_free_pdu(rpc, pdu); |
68 | return -2; | |
69 | } | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | int rpc_rquota1_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data) | |
75 | { | |
76 | struct rpc_pdu *pdu; | |
77 | GETQUOTA1args args; | |
78 | ||
79 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
80 | if (pdu == NULL) { | |
77c23b46 | 81 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getquota call"); |
05a777d9 RS |
82 | return -1; |
83 | } | |
84 | ||
85 | args.export = export; | |
86 | args.uid = uid; | |
87 | ||
88 | if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) { | |
89 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args"); | |
90 | rpc_free_pdu(rpc, pdu); | |
91 | return -2; | |
92 | } | |
93 | ||
94 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
77c23b46 | 95 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getquota call"); |
05a777d9 RS |
96 | rpc_free_pdu(rpc, pdu); |
97 | return -3; | |
98 | } | |
99 | ||
100 | return 0; | |
101 | } | |
19e74f5a RS |
102 | |
103 | int rpc_rquota1_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int uid, void *private_data) | |
104 | { | |
105 | struct rpc_pdu *pdu; | |
106 | GETQUOTA1args args; | |
107 | ||
108 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V1, RQUOTA1_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
109 | if (pdu == NULL) { | |
77c23b46 | 110 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota1/getactivequota call"); |
19e74f5a RS |
111 | return -1; |
112 | } | |
113 | ||
114 | args.export = export; | |
115 | args.uid = uid; | |
116 | ||
117 | if (xdr_GETQUOTA1args(&pdu->xdr, &args) == 0) { | |
118 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA1args"); | |
119 | rpc_free_pdu(rpc, pdu); | |
120 | return -2; | |
121 | } | |
122 | ||
123 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
77c23b46 RS |
124 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota1/getactivequota call"); |
125 | rpc_free_pdu(rpc, pdu); | |
126 | return -3; | |
127 | } | |
128 | ||
129 | return 0; | |
130 | } | |
131 | ||
132 | ||
133 | int rpc_rquota2_null_async(struct rpc_context *rpc, rpc_cb cb, void *private_data) | |
134 | { | |
135 | struct rpc_pdu *pdu; | |
136 | ||
137 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_NULL, cb, private_data, (xdrproc_t)xdr_void, 0); | |
138 | if (pdu == NULL) { | |
139 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/null call"); | |
140 | return -1; | |
141 | } | |
142 | ||
143 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
144 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/null call"); | |
145 | rpc_free_pdu(rpc, pdu); | |
146 | return -2; | |
147 | } | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
152 | int rpc_rquota2_getquota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data) | |
153 | { | |
154 | struct rpc_pdu *pdu; | |
155 | GETQUOTA2args args; | |
156 | ||
157 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
158 | if (pdu == NULL) { | |
159 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getquota call"); | |
160 | return -1; | |
161 | } | |
162 | ||
163 | args.export = export; | |
164 | args.type = type; | |
165 | args.uid = uid; | |
166 | ||
167 | if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) { | |
168 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args"); | |
169 | rpc_free_pdu(rpc, pdu); | |
170 | return -2; | |
171 | } | |
172 | ||
173 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
174 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getquota call"); | |
175 | rpc_free_pdu(rpc, pdu); | |
176 | return -3; | |
177 | } | |
178 | ||
179 | return 0; | |
180 | } | |
181 | ||
182 | int rpc_rquota2_getactivequota_async(struct rpc_context *rpc, rpc_cb cb, char *export, int type, int uid, void *private_data) | |
183 | { | |
184 | struct rpc_pdu *pdu; | |
185 | GETQUOTA2args args; | |
186 | ||
187 | pdu = rpc_allocate_pdu(rpc, RQUOTA_PROGRAM, RQUOTA_V2, RQUOTA2_GETACTIVEQUOTA, cb, private_data, (xdrproc_t)xdr_GETQUOTA1res, sizeof(GETQUOTA1res)); | |
188 | if (pdu == NULL) { | |
189 | rpc_set_error(rpc, "Out of memory. Failed to allocate pdu for rquota2/getactivequota call"); | |
190 | return -1; | |
191 | } | |
192 | ||
193 | args.export = export; | |
194 | args.type = type; | |
195 | args.uid = uid; | |
196 | ||
197 | if (xdr_GETQUOTA2args(&pdu->xdr, &args) == 0) { | |
198 | rpc_set_error(rpc, "XDR error: Failed to encode GETQUOTA2args"); | |
199 | rpc_free_pdu(rpc, pdu); | |
200 | return -2; | |
201 | } | |
202 | ||
203 | if (rpc_queue_pdu(rpc, pdu) != 0) { | |
204 | rpc_set_error(rpc, "Out of memory. Failed to queue pdu for rquota2/getactivequota call"); | |
19e74f5a RS |
205 | rpc_free_pdu(rpc, pdu); |
206 | return -3; | |
207 | } | |
208 | ||
209 | return 0; | |
210 | } |