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>
16 #include <sys/param.h>
17 #include <sys/types.h>
23 #include <netinet/in.h>
35 #include <afs/afsint.h>
36 #include <afs/venus.h>
42 * We deal with converting pioctl parameters between host and network order.
43 * Painful but somebody has to do this and pioctl is the best place rather than
44 * leaving it to the calling application programs!
49 #define MAXHOSTS 8 /* XXX HARD Limit limitation XXX */
55 struct AclEntry *pluslist;
56 struct AclEntry *minuslist;
60 struct AclEntry *next;
69 afs_int32 BeginTimestamp;
70 afs_int32 EndTimestamp;
73 char *RSkipLine (astr)
74 register char *astr; {
75 while (*astr !='\n') astr++;
81 struct Acl *RParseAcl(astr)
83 int nplus, nminus, i, trights;
85 struct AclEntry *first, *last, *tl;
87 sscanf(astr, "%d", &nplus);
88 astr = RSkipLine(astr);
89 sscanf(astr, "%d", &nminus);
90 astr = RSkipLine(astr);
92 ta = (struct Acl *) malloc (sizeof (struct Acl));
98 for(i=0;i<nplus;i++) {
99 sscanf(astr, "%100s %d", tname, &trights);
100 astr = RSkipLine(astr);
101 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
102 if (!first) first = tl;
103 strcpy(tl->name, tname);
104 tl->rights = trights;
106 if (last) last->next = tl;
109 ta->pluslist = first;
113 for(i=0;i<nminus;i++) {
114 sscanf(astr, "%100s %d", tname, &trights);
115 astr = RSkipLine(astr);
116 tl = (struct AclEntry *) malloc(sizeof (struct AclEntry));
117 if (!first) first = tl;
118 strcpy(tl->name, tname);
119 tl->rights = trights;
121 if (last) last->next = tl;
124 ta->minuslist = first;
130 int RAclToString(struct Acl *acl, char *mydata, int ntoh_conv)
132 char tstring[MAXSIZE];
135 /* No conversion needed since they're in network order in the first place */
136 sprintf(mydata, "%d\n%d\n", acl->nplus, acl->nminus);
137 for(tp = acl->pluslist;tp;tp=tp->next) {
138 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
139 strcat(mydata, tstring);
141 for(tp = acl->minuslist;tp;tp=tp->next) {
142 sprintf(tstring, "%s %d\n", tp->name, tp->rights);
143 strcat(mydata, tstring);
148 /* Free all malloced stuff */
149 int RCleanAcl(struct Acl *aa)
151 register struct AclEntry *te, *ne;
153 for(te = aa->pluslist; te; te=ne) {
157 for(te = aa->minuslist; te; te=ne) {
165 int RFetchVolumeStatus_conversion(char *data, int ntoh_conv)
167 struct AFSFetchVolumeStatus *status = (AFSFetchVolumeStatus *)data;
169 if (ntoh_conv) { /* Network -> Host */
170 status->Vid = ntohl(status->Vid);
171 status->ParentId = ntohl(status->ParentId);
174 status->OnLine = status->OnLine;
175 status->InService = status->InService;
176 status->Blessed = status->Blessed;
177 status->NeedsSalvage = status->NeedsSalvage;
179 status->Type = ntohl(status->Type);
180 status->MinQuota = ntohl(status->MinQuota);
181 status->MaxQuota = ntohl(status->MaxQuota);
182 status->BlocksInUse = ntohl(status->BlocksInUse);
183 status->PartBlocksAvail = ntohl(status->PartBlocksAvail);
184 status->PartMaxBlocks = ntohl(status->PartMaxBlocks);
185 } else { /* Host -> Network */
186 status->Vid = htonl(status->Vid);
187 status->ParentId = htonl(status->ParentId);
190 status->OnLine = status->OnLine;
191 status->InService = status->InService;
192 status->Blessed = status->Blessed;
193 status->NeedsSalvage = status->NeedsSalvage;
195 status->Type = htonl(status->Type);
196 status->MinQuota = htonl(status->MinQuota);
197 status->MaxQuota = htonl(status->MaxQuota);
198 status->BlocksInUse = htonl(status->BlocksInUse);
199 status->PartBlocksAvail = htonl(status->PartBlocksAvail);
200 status->PartMaxBlocks = htonl(status->PartMaxBlocks);
204 int RClearToken_convert(char *ptr, int ntoh_conv)
206 struct ClearToken *ticket = (struct ClearToken *)ptr;
208 if (ntoh_conv) { /* Network -> host */
209 ticket->AuthHandle = ntohl(ticket->AuthHandle);
210 ticket->ViceId = ntohl(ticket->ViceId);
211 ticket->BeginTimestamp = ntohl(ticket->BeginTimestamp);
212 ticket->EndTimestamp = ntohl(ticket->EndTimestamp);
213 } else { /* Host -> Network */
214 ticket->AuthHandle = htonl(ticket->AuthHandle);
215 ticket->ViceId = htonl(ticket->ViceId);
216 ticket->BeginTimestamp = htonl(ticket->BeginTimestamp);
217 ticket->EndTimestamp = htonl(ticket->EndTimestamp);
221 int inparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
227 switch (cmd & 0xffff) {
228 case VIOCSETAL & 0xffff:
229 acl = RParseAcl(buffer);
230 RAclToString(acl, buffer, ntoh_conv);
233 case VIOCSETTOK & 0xffff:
234 lptr = (afs_int32 *)buffer;
235 /* i is sizeof of the secret ticket */
245 ptr += i; /* skip over the ticket */
246 lptr = (afs_int32 *)ptr;
247 /* i is now size of the clear token */
257 RClearToken_convert(ptr, ntoh_conv);
258 ptr += i; /* sizeof(struct ClearToken) */
259 lptr = (afs_int32 *)ptr;
261 *lptr = ntohl(*lptr);
263 *lptr = htonl(*lptr);
264 lptr++; /* primary flag */
266 case VIOCSETVOLSTAT & 0xffff:
267 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
269 case VIOCGETTOK & 0xffff:
270 lptr = (afs_int32 *)buffer;
272 *lptr = ntohl(*lptr);
274 *lptr = htonl(*lptr);
276 case VIOCCKSERV & 0xffff:
277 lptr = (afs_int32 *)buffer;
279 *lptr = ntohl(*lptr);
281 *lptr = htonl(*lptr);
283 case VIOCACCESS & 0xffff:
284 lptr = (afs_int32 *)buffer;
286 *lptr = ntohl(*lptr);
288 *lptr = htonl(*lptr);
290 case VIOCSETCACHESIZE & 0xffff:
291 lptr = (afs_int32 *)buffer;
293 *lptr = ntohl(*lptr);
295 *lptr = htonl(*lptr);
297 case VIOCGETCELL & 0xffff:
298 lptr = (afs_int32 *)buffer;
300 *lptr = ntohl(*lptr);
302 *lptr = htonl(*lptr);
304 case VIOC_AFS_MARINER_HOST & 0xffff:
305 lptr = (afs_int32 *)buffer;
307 *lptr = ntohl(*lptr);
309 *lptr = htonl(*lptr);
311 case VIOC_VENUSLOG & 0xffff:
312 lptr = (afs_int32 *)buffer;
314 *lptr = ntohl(*lptr);
316 *lptr = htonl(*lptr);
318 case VIOC_SETCELLSTATUS & 0xffff:
319 lptr = (afs_int32 *)buffer;
321 *lptr = ntohl(*lptr);
323 *lptr = htonl(*lptr);
326 *lptr = ntohl(*lptr);
328 *lptr = htonl(*lptr);
330 case VIOC_AFS_SYSNAME & 0xffff:
331 lptr = (afs_int32 *)buffer;
333 *lptr = ntohl(*lptr);
335 *lptr = htonl(*lptr);
337 case VIOC_EXPORTAFS & 0xffff:
338 lptr = (afs_int32 *)buffer;
340 *lptr = ntohl(*lptr);
342 *lptr = htonl(*lptr);
344 case VIOCGETAL & 0xffff:
345 case VIOCGETVOLSTAT & 0xffff:
346 case VIOCGETCACHEPARMS & 0xffff:
347 case VIOCFLUSH & 0xffff:
348 case VIOCSTAT & 0xffff:
349 case VIOCUNLOG & 0xffff:
350 case VIOCCKBACK & 0xffff:
351 case VIOCCKCONN & 0xffff:
352 case VIOCGETTIME & 0xffff: /* Obsolete */
353 case VIOCWHEREIS & 0xffff:
354 case VIOCPREFETCH & 0xffff:
355 case VIOCNOP & 0xffff: /* Obsolete */
356 case VIOCENGROUP & 0xffff: /* Obsolete */
357 case VIOCDISGROUP & 0xffff: /* Obsolete */
358 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
359 case VIOCUNPAG & 0xffff:
360 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
361 case VIOCFLUSHCB & 0xffff:
362 case VIOCNEWCELL & 0xffff:
363 case VIOC_AFS_DELETE_MT_PT & 0xffff:
364 case VIOC_AFS_STAT_MT_PT & 0xffff:
365 case VIOC_FILE_CELL_NAME & 0xffff:
366 case VIOC_GET_WS_CELL & 0xffff:
367 case VIOC_GET_PRIMARY_CELL & 0xffff:
368 case VIOC_GETCELLSTATUS & 0xffff:
369 case VIOC_FLUSHVOLUME & 0xffff:
370 case VIOCGETFID & 0xffff: /* nothing yet */
373 /* Note that new pioctls are supposed to be in network order! */
379 int outparam_conversion(afs_int32 cmd, char *buffer, afs_int32 ntoh_conv)
385 switch (cmd & 0xffff) {
386 case VIOCGETAL & 0xffff:
387 acl = RParseAcl(buffer);
388 RAclToString(acl, buffer, ntoh_conv);
391 case VIOCGETVOLSTAT & 0xffff:
392 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
394 case VIOCSETVOLSTAT & 0xffff:
395 RFetchVolumeStatus_conversion(buffer, ntoh_conv);
397 case VIOCGETTOK & 0xffff:
398 lptr = (afs_int32 *)buffer;
399 /* i is set to sizeof secret ticket */
409 ptr += i; /* skip over the ticket */
410 lptr = (afs_int32 *)ptr;
411 /* i is set to sizeof clear ticket */
421 RClearToken_convert(ptr, ntoh_conv);
422 ptr += i; /* sizeof(struct ClearToken) */
423 lptr = (afs_int32 *)ptr;
425 *lptr = ntohl(*lptr);
427 *lptr = htonl(*lptr);
428 lptr++; /* primary flag */
430 case VIOCCKCONN & 0xffff:
432 *lptr = ntohl(*lptr);
434 *lptr = htonl(*lptr);
436 case VIOC_AFS_MARINER_HOST & 0xffff:
437 lptr = (afs_int32 *)buffer;
439 *lptr = ntohl(*lptr);
441 *lptr = htonl(*lptr);
443 case VIOC_VENUSLOG & 0xffff:
444 lptr = (afs_int32 *)buffer;
446 *lptr = ntohl(*lptr);
448 *lptr = htonl(*lptr);
450 case VIOC_GETCELLSTATUS & 0xffff:
451 lptr = (afs_int32 *)buffer;
453 *lptr = ntohl(*lptr);
455 *lptr = htonl(*lptr);
457 case VIOC_AFS_SYSNAME & 0xffff:
458 lptr = (afs_int32 *)buffer;
460 *lptr = ntohl(*lptr);
462 *lptr = htonl(*lptr);
464 case VIOC_EXPORTAFS & 0xffff:
465 lptr = (afs_int32 *)buffer;
467 *lptr = ntohl(*lptr);
469 *lptr = htonl(*lptr);
471 case VIOCGETCACHEPARMS & 0xffff:
472 lptr = (afs_int32 *)buffer;
473 for (i=0; i < MAXGCSIZE; i++, lptr++) {
475 *lptr = ntohl(*lptr);
477 *lptr = htonl(*lptr);
480 case VIOCUNLOG & 0xffff:
481 case VIOCCKSERV & 0xffff: /* Already in network order */
482 case VIOCCKBACK & 0xffff:
483 case VIOCGETTIME & 0xffff: /* Obsolete */
484 case VIOCWHEREIS & 0xffff: /* Already in network order */
485 case VIOCPREFETCH & 0xffff:
486 case VIOCNOP & 0xffff: /* Obsolete */
487 case VIOCENGROUP & 0xffff: /* Obsolete */
488 case VIOCDISGROUP & 0xffff: /* Obsolete */
489 case VIOCLISTGROUPS & 0xffff: /* Obsolete */
490 case VIOCACCESS & 0xffff:
491 case VIOCUNPAG & 0xffff:
492 case VIOCWAITFOREVER & 0xffff: /* Obsolete */
493 case VIOCSETCACHESIZE & 0xffff:
494 case VIOCFLUSHCB & 0xffff:
495 case VIOCNEWCELL & 0xffff:
496 case VIOCGETCELL & 0xffff: /* Already in network order */
497 case VIOC_AFS_DELETE_MT_PT & 0xffff:
498 case VIOC_AFS_STAT_MT_PT & 0xffff:
499 case VIOC_FILE_CELL_NAME & 0xffff: /* no need to convert */
500 case VIOC_GET_WS_CELL & 0xffff: /* no need to convert */
501 case VIOCGETFID & 0xffff: /* nothing yet */
502 case VIOCSETAL & 0xffff:
503 case VIOCFLUSH & 0xffff:
504 case VIOCSTAT & 0xffff:
505 case VIOCSETTOK & 0xffff:
506 case VIOC_GET_PRIMARY_CELL & 0xffff: /* The cell is returned here */
507 case VIOC_SETCELLSTATUS & 0xffff:
508 case VIOC_FLUSHVOLUME & 0xffff:
511 /* Note that new pioctls are supposed to be in network order! */