2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 #include <afsconfig.h>
11 #include <afs/param.h>
12 #include <afs/afs_consts.h>
15 #include <sys/param.h>
16 #include <sys/types.h>
22 #include <netinet/in.h>
28 #include <afs/afsint.h>
29 #include <afs/venus.h>
35 * We deal with converting pioctl parameters between host and network order.
36 * Painful but somebody has to do this and pioctl is the best place rather than
37 * leaving it to the calling application programs!
46 struct AclEntry *pluslist;
47 struct AclEntry *minuslist;
51 struct AclEntry *next;
60 afs_int32 BeginTimestamp;
61 afs_int32 EndTimestamp;
77 int nplus, nminus, i, trights;
79 struct AclEntry *first, *last, *tl;
81 sscanf(astr, "%d", &nplus);
82 astr = RSkipLine(astr);
83 sscanf(astr, "%d", &nminus);
84 astr = RSkipLine(astr);
86 ta = (struct Acl *)malloc(sizeof(struct Acl));
92 for (i = 0; i < nplus; i++) {
93 sscanf(astr, "%100s %d", tname, &trights);
94 astr = RSkipLine(astr);
95 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
98 strcpy(tl->name, tname);
105 ta->pluslist = first;
109 for (i = 0; i < nminus; i++) {
110 sscanf(astr, "%100s %d", tname, &trights);
111 astr = RSkipLine(astr);
112 tl = (struct AclEntry *)malloc(sizeof(struct AclEntry));
115 strcpy(tl->name, tname);
116 tl->rights = trights;
122 ta->minuslist = first;
129 RAclToString(struct Acl *acl, char *mydata, int ntoh_conv)
131 char tstring[AFS_PIOCTL_MAXSIZE];
134 /* No conversion needed since they're in network order in the first place */
135 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
136 for (tp = acl->pluslist; tp; tp = tp->next) {
137 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
138 strcat(mydata, tstring);
140 for (tp = acl->minuslist; tp; tp = tp->next) {
141 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
142 strcat(mydata, tstring);
147 /* Free all malloced stuff */
149 RCleanAcl(struct Acl *aa)
151 struct AclEntry *te, *ne;
153 for (te = aa->pluslist; te; te = ne) {
157 for (te = aa->minuslist; te; te = ne) {
166 RFetchVolumeStatus_conversion(char *data, int ntoh_conv)
168 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *) data;
170 if (ntoh_conv) { /* Network -> Host */
171 status->Vid = ntohl(status->Vid);
172 status->ParentId = ntohl(status->ParentId);
175 status->OnLine = status->OnLine;
176 status->InService = status->InService;
177 status->Blessed = status->Blessed;
178 status->NeedsSalvage = status->NeedsSalvage;
180 status->Type = ntohl(status->Type);
181 status->MinQuota = ntohl(status->MinQuota);
182 status->MaxQuota = ntohl(status->MaxQuota);
183 status->BlocksInUse = ntohl(status->BlocksInUse);
184 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
185 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
186 } else { /* Host -> Network */
187 status->Vid = htonl(status->Vid);
188 status->ParentId = htonl(status->ParentId);
191 status->OnLine = status->OnLine;
192 status->InService = status->InService;
193 status->Blessed = status->Blessed;
194 status->NeedsSalvage = status->NeedsSalvage;
196 status->Type = htonl(status->Type);
197 status->MinQuota = htonl(status->MinQuota);
198 status->MaxQuota = htonl(status->MaxQuota);
199 status->BlocksInUse = htonl(status->BlocksInUse);
200 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
201 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
206 RClearToken_convert(char *ptr, int ntoh_conv)
208 struct ClearToken *ticket = (struct ClearToken *)ptr;
210 if (ntoh_conv) { /* Network -> host */
211 ticket->AuthHandle = ntohl(ticket->AuthHandle);
212 ticket->ViceId = ntohl(ticket->ViceId);
213 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
214 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
215 } else { /* Host -> Network */
216 ticket->AuthHandle = htonl(ticket->AuthHandle);
217 ticket->ViceId = htonl(ticket->ViceId);
218 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
219 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
224 inparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
230 switch (cmd & 0xffff) {
231 case VIOCSETAL & 0xffff:
232 acl = RParseAcl(buffer);
233 RAclToString(acl, buffer, ntoh_conv);
236 case VIOCSETTOK & 0xffff:
237 lptr = (afs_int32 *) buffer;
238 /* i is sizeof of the secret ticket */
248 ptr += i; /* skip over the ticket */
249 lptr = (afs_int32 *) ptr;
250 /* i is now size of the clear token */
260 RClearToken_convert(ptr, ntoh_conv);
261 ptr += i; /* sizeof(struct ClearToken) */
262 lptr = (afs_int32 *) ptr;
264 *lptr = ntohl(*lptr);
266 *lptr = htonl(*lptr);
267 lptr++; /* primary flag */
269 case VIOCSETVOLSTAT & 0xffff:
270 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
272 case VIOCGETTOK & 0xffff:
273 case VIOCCKSERV & 0xffff:
274 case VIOCACCESS & 0xffff:
275 case VIOCSETCACHESIZE & 0xffff:
276 case VIOCGETCELL & 0xffff:
277 case VIOC_AFS_MARINER_HOST & 0xffff:
278 case VIOC_VENUSLOG & 0xffff:
279 case VIOC_AFS_SYSNAME & 0xffff:
280 case VIOC_EXPORTAFS & 0xffff:
281 lptr = (afs_int32 *) buffer;
283 *lptr = ntohl(*lptr);
285 *lptr = htonl(*lptr);
287 case VIOC_SETCELLSTATUS & 0xffff:
288 lptr = (afs_int32 *) buffer;
290 *lptr = ntohl(*lptr);
292 *lptr = htonl(*lptr);
295 *lptr = ntohl(*lptr);
297 *lptr = htonl(*lptr);
299 case VIOCGETAL & 0xffff:
300 case VIOCGETVOLSTAT & 0xffff:
301 case VIOCGETCACHEPARMS & 0xffff:
302 case VIOCFLUSH & 0xffff:
303 case VIOCSTAT & 0xffff:
304 case VIOCUNLOG & 0xffff:
305 case VIOCCKBACK & 0xffff:
306 case VIOCCKCONN & 0xffff:
307 case VIOCGETTIME & 0xffff: /* Obsolete */
308 case VIOCWHEREIS & 0xffff:
309 case VIOCPREFETCH & 0xffff:
310 case VIOCNOP & 0xffff: /* Obsolete */
311 case VIOCENGROUP & 0xffff: /* Obsolete */
312 case VIOCDISGROUP & 0xffff: /* Obsolete */
313 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
314 case VIOCUNPAG & 0xffff:
315 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
316 case VIOCFLUSHCB & 0xffff:
317 case VIOCNEWCELL & 0xffff:
318 case VIOC_AFS_DELETE_MT_PT & 0xffff:
319 case VIOC_AFS_STAT_MT_PT & 0xffff:
320 case VIOC_FILE_CELL_NAME & 0xffff:
321 case VIOC_GET_WS_CELL & 0xffff:
322 case VIOC_GET_PRIMARY_CELL & 0xffff:
323 case VIOC_GETCELLSTATUS & 0xffff:
324 case VIOC_FLUSHVOLUME & 0xffff:
325 case VIOCGETFID & 0xffff: /* nothing yet */
328 /* Note that new pioctls are supposed to be in network order! */
335 outparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
341 switch (cmd & 0xffff) {
342 case VIOCGETAL & 0xffff:
343 acl = RParseAcl(buffer);
344 RAclToString(acl, buffer, ntoh_conv);
347 case VIOCGETVOLSTAT & 0xffff:
348 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
350 case VIOCSETVOLSTAT & 0xffff:
351 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
353 case VIOCGETTOK & 0xffff:
354 lptr = (afs_int32 *) buffer;
355 /* i is set to sizeof secret ticket */
365 ptr += i; /* skip over the ticket */
366 lptr = (afs_int32 *) ptr;
367 /* i is set to sizeof clear ticket */
377 RClearToken_convert(ptr, ntoh_conv);
378 ptr += i; /* sizeof(struct ClearToken) */
379 lptr = (afs_int32 *) ptr;
381 *lptr = ntohl(*lptr);
383 *lptr = htonl(*lptr);
384 lptr++; /* primary flag */
386 case VIOCCKCONN & 0xffff:
387 case VIOC_AFS_MARINER_HOST & 0xffff:
388 case VIOC_VENUSLOG & 0xffff:
389 case VIOC_GETCELLSTATUS & 0xffff:
390 case VIOC_AFS_SYSNAME & 0xffff:
391 case VIOC_EXPORTAFS & 0xffff:
392 lptr = (afs_int32 *) buffer;
394 *lptr = ntohl(*lptr);
396 *lptr = htonl(*lptr);
398 case VIOCGETCACHEPARMS & 0xffff:
399 lptr = (afs_int32 *) buffer;
400 for (i = 0; i < MAXGCSIZE; i++, lptr++) {
402 *lptr = ntohl(*lptr);
404 *lptr = htonl(*lptr);
407 case VIOCUNLOG & 0xffff:
408 case VIOCCKSERV & 0xffff: /* Already in network order */
409 case VIOCCKBACK & 0xffff:
410 case VIOCGETTIME & 0xffff: /* Obsolete */
411 case VIOCWHEREIS & 0xffff: /* Already in network order */
412 case VIOCPREFETCH & 0xffff:
413 case VIOCNOP & 0xffff: /* Obsolete */
414 case VIOCENGROUP & 0xffff: /* Obsolete */
415 case VIOCDISGROUP & 0xffff: /* Obsolete */
416 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
417 case VIOCACCESS & 0xffff:
418 case VIOCUNPAG & 0xffff:
419 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
420 case VIOCSETCACHESIZE & 0xffff:
421 case VIOCFLUSHCB & 0xffff:
422 case VIOCNEWCELL & 0xffff:
423 case VIOCGETCELL & 0xffff: /* Already in network order */
424 case VIOC_AFS_DELETE_MT_PT & 0xffff:
425 case VIOC_AFS_STAT_MT_PT & 0xffff:
426 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
427 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
428 case VIOCGETFID & 0xffff: /* nothing yet */
429 case VIOCSETAL & 0xffff:
430 case VIOCFLUSH & 0xffff:
431 case VIOCSTAT & 0xffff:
432 case VIOCSETTOK & 0xffff:
433 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
434 case VIOC_SETCELLSTATUS & 0xffff:
435 case VIOC_FLUSHVOLUME & 0xffff:
438 /* Note that new pioctls are supposed to be in network order! */