nfs-ganesha 1.4
|
00001 /* 00002 * vim:expandtab:shiftwidth=8:tabstop=8: 00003 * 00004 * Copyright CEA/DAM/DIF (2008) 00005 * contributeur : Philippe DENIEL philippe.deniel@cea.fr 00006 * Thomas LEIBOVICI thomas.leibovici@cea.fr 00007 * 00008 * 00009 * This program is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public 00011 * License as published by the Free Software Foundation; either 00012 * version 3 of the License, or (at your option) any later version. 00013 * 00014 * This program is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00017 * Lesser General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU Lesser General Public 00020 * License along with this library; if not, write to the Free Software 00021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 * 00023 * --------------------------------------- 00024 */ 00025 00106 #ifdef HAVE_CONFIG_H 00107 #include "config.h" 00108 #endif 00109 00110 #ifdef _SOLARIS 00111 #include "solaris_port.h" 00112 #ifndef _USE_SNMP 00113 typedef unsigned long u_long; 00114 #endif 00115 #endif 00116 00117 #include <limits.h> 00118 #include <string.h> 00119 #include <sys/stat.h> 00120 #include "cmd_nfstools.h" 00121 #include "abstract_mem.h" 00122 #include "nfs23.h" 00123 #include "nfs4.h" 00124 #include "mount.h" 00125 #include "nfs_proto_functions.h" 00126 #include "nfs_tools.h" 00127 #include "nfs_proto_tools.h" 00128 #include "nfs_file_handle.h" 00129 #include "cmd_tools.h" 00130 00131 /* 2 char per byte + '\0' */ 00132 #define SIZE_STR_NFSHANDLE2 (2 * NFS2_FHSIZE + 1) 00133 #define SIZE_STR_NFSHANDLE3 (2 * NFS3_FHSIZE + 1) 00134 00135 /* unsolved symbols */ 00136 int get_rpc_xid() 00137 { 00138 return 0; 00139 } 00140 00141 void *rpc_tcp_socket_manager_thread(void *Arg) 00142 { 00143 return NULL; 00144 } 00145 00146 /* encoding/decoding function definitions */ 00147 00148 int cmdnfs_void(cmdnfs_encodetype_t encodeflag, 00149 int argc, char **argv, 00150 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00151 { 00152 if((encodeflag == CMDNFS_ENCODE) && (argc != 0)) 00153 return FALSE; 00154 00155 return TRUE; 00156 } 00157 00158 int cmdnfs_dirpath(cmdnfs_encodetype_t encodeflag, 00159 int argc, char **argv, 00160 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00161 { 00162 size_t len; 00163 dirpath *p_dirpath = (dirpath *) p_nfs_struct; 00164 00165 /* sanity check */ 00166 if(p_dirpath == NULL) 00167 return FALSE; 00168 00169 switch (encodeflag) 00170 { 00171 case CMDNFS_ENCODE: 00172 00173 if(argc != 1) 00174 return FALSE; 00175 00176 len = strlen(argv[0]); 00177 *p_dirpath = gsh_malloc(len + 1); 00178 00179 if(*p_dirpath == NULL) 00180 { 00181 fprintf(stderr, "Not enough memory.\n"); 00182 return FALSE; 00183 } 00184 00185 strcpy(*p_dirpath, argv[0]); 00186 00187 return TRUE; 00188 00189 break; 00190 case CMDNFS_DECODE: 00191 00192 fprintf(out_stream, "%*sdirpath = %s\n", indent, " ", *p_dirpath); 00193 return TRUE; 00194 00195 break; 00196 00197 case CMDNFS_FREE: 00198 00199 gsh_free(*p_dirpath); 00200 break; 00201 00202 default: 00203 return FALSE; 00204 } 00205 return FALSE; 00206 } 00207 00208 int cmdnfs_fhandle2(cmdnfs_encodetype_t encodeflag, 00209 int argc, char **argv, 00210 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00211 { 00212 fhandle2 *p_fhandle = (fhandle2 *) p_nfs_struct; 00213 00214 char *str_handle; 00215 char str_printhandle[SIZE_STR_NFSHANDLE2]; 00216 int rc; 00217 00218 /* sanity check */ 00219 if(p_fhandle == NULL) 00220 return FALSE; 00221 00222 switch (encodeflag) 00223 { 00224 case CMDNFS_ENCODE: 00225 00226 if(argc != 1) 00227 return FALSE; 00228 00229 str_handle = argv[0]; 00230 00231 /* check that it begins with an @ */ 00232 if(str_handle[0] != '@') 00233 return FALSE; 00234 00235 /* escaping the first char @ */ 00236 str_handle++; 00237 00238 rc = sscanmem((caddr_t) p_fhandle, NFS2_FHSIZE, str_handle); 00239 00240 /* we must have read at least the handle size */ 00241 if(rc < 2 * (int)sizeof(file_handle_v2_t)) 00242 return FALSE; 00243 00244 return TRUE; 00245 00246 break; 00247 case CMDNFS_DECODE: 00248 00249 if(snprintmem 00250 (str_printhandle, SIZE_STR_NFSHANDLE2, (caddr_t) p_fhandle, NFS2_FHSIZE) < 0) 00251 { 00252 return FALSE; 00253 } 00254 00255 fprintf(out_stream, "%*sfhandle2 = @%s\n", indent, " ", str_printhandle); 00256 00257 return TRUE; 00258 00259 break; 00260 00261 case CMDNFS_FREE: 00262 00263 /* nothing to do */ 00264 return TRUE; 00265 00266 break; 00267 00268 default: 00269 return FALSE; 00270 } 00271 00272 } 00273 00274 int cmdnfs_fhstatus2(cmdnfs_encodetype_t encodeflag, 00275 int argc, char **argv, 00276 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00277 { 00278 fhstatus2 *p_fhstatus = (fhstatus2 *) p_nfs_struct; 00279 00280 /* sanity check */ 00281 if(p_fhstatus == NULL) 00282 return FALSE; 00283 00284 switch (encodeflag) 00285 { 00286 case CMDNFS_ENCODE: 00287 00288 /* it is never an input */ 00289 return FALSE; 00290 00291 break; 00292 case CMDNFS_DECODE: 00293 00294 fprintf(out_stream, "%*sfhstatus2 =\n", indent, " "); 00295 fprintf(out_stream, "%*s{\n", indent, " "); 00296 00297 /* Convert status to error code */ 00298 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00299 (caddr_t) & p_fhstatus->status) == FALSE) 00300 { 00301 return FALSE; 00302 } 00303 00304 if(p_fhstatus->status == NFS_OK) 00305 { 00306 if(cmdnfs_fhandle2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00307 (caddr_t) & p_fhstatus->fhstatus2_u.directory) == FALSE) 00308 { 00309 return FALSE; 00310 } 00311 } 00312 fprintf(out_stream, "%*s}\n", indent, " "); 00313 00314 return TRUE; 00315 00316 break; 00317 00318 case CMDNFS_FREE: 00319 00320 /* it is never an input (never encoded, never allocated) */ 00321 return FALSE; 00322 00323 break; 00324 00325 default: 00326 return FALSE; 00327 } 00328 } 00329 00330 int cmdnfs_STATFS2res(cmdnfs_encodetype_t encodeflag, 00331 int argc, char **argv, 00332 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00333 { 00334 00335 STATFS2res *p_statres = (STATFS2res *) p_nfs_struct; 00336 00337 /* sanity check */ 00338 if(p_statres == NULL) 00339 return FALSE; 00340 00341 switch (encodeflag) 00342 { 00343 case CMDNFS_ENCODE: 00344 00345 /* it is never an input */ 00346 return FALSE; 00347 00348 break; 00349 case CMDNFS_DECODE: 00350 00351 fprintf(out_stream, "%*sSTATFS2res =\n", indent, " "); 00352 fprintf(out_stream, "%*s{\n", indent, " "); 00353 00354 /* Convert status to error code */ 00355 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00356 (caddr_t) & p_statres->status) == FALSE) 00357 { 00358 return FALSE; 00359 } 00360 00361 if(p_statres->status == NFS_OK) 00362 { 00363 /* print statinfo2 */ 00364 fprintf(out_stream, "%*sinfo =\n", indent + 2, " "); 00365 fprintf(out_stream, "%*s{\n", indent + 2, " "); 00366 fprintf(out_stream, "%*stsize = %u\n", indent + 4, " ", 00367 p_statres->STATFS2res_u.info.tsize); 00368 fprintf(out_stream, "%*sbsize = %u\n", indent + 4, " ", 00369 p_statres->STATFS2res_u.info.bsize); 00370 fprintf(out_stream, "%*sblocks = %u\n", indent + 4, " ", 00371 p_statres->STATFS2res_u.info.blocks); 00372 fprintf(out_stream, "%*sbfree = %u\n", indent + 4, " ", 00373 p_statres->STATFS2res_u.info.bfree); 00374 fprintf(out_stream, "%*sbavail = %u\n", indent + 4, " ", 00375 p_statres->STATFS2res_u.info.bavail); 00376 fprintf(out_stream, "%*s}\n", indent + 2, " "); 00377 00378 } 00379 fprintf(out_stream, "%*s}\n", indent, " "); 00380 00381 return TRUE; 00382 00383 break; 00384 00385 case CMDNFS_FREE: 00386 00387 /* it is never an input (never encoded, never allocated) */ 00388 return FALSE; 00389 00390 break; 00391 00392 default: 00393 return FALSE; 00394 } 00395 00396 } 00397 00398 int cmdnfs_mountlist(cmdnfs_encodetype_t encodeflag, 00399 int argc, char **argv, 00400 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00401 { 00402 mountlist *p_mountlist = (mountlist *) p_nfs_struct; 00403 00404 /* sanity check */ 00405 if(p_mountlist == NULL) 00406 return FALSE; 00407 00408 /* empty list */ 00409 if(*p_mountlist == NULL) 00410 return TRUE; 00411 00412 switch (encodeflag) 00413 { 00414 case CMDNFS_ENCODE: 00415 00416 /* it is never an input */ 00417 return FALSE; 00418 00419 break; 00420 case CMDNFS_DECODE: 00421 00422 fprintf(out_stream, "%*s{\n", indent, " "); 00423 fprintf(out_stream, "%*shostname = %s\n", indent + 2, " ", 00424 (*p_mountlist)->ml_hostname); 00425 fprintf(out_stream, "%*spathname = %s\n", indent + 2, " ", 00426 (*p_mountlist)->ml_directory); 00427 fprintf(out_stream, "%*s}\n", indent, " "); 00428 00429 if(cmdnfs_mountlist(CMDNFS_DECODE, 0, NULL, indent, out_stream, 00430 (caddr_t) & ((*p_mountlist)->ml_next)) == FALSE) 00431 { 00432 return FALSE; 00433 } 00434 00435 return TRUE; 00436 00437 break; 00438 00439 case CMDNFS_FREE: 00440 00441 /* it is never an input (never encoded, never allocated) */ 00442 return FALSE; 00443 00444 break; 00445 00446 default: 00447 return FALSE; 00448 } 00449 00450 } 00451 00452 int cmdnfs_exports(cmdnfs_encodetype_t encodeflag, 00453 int argc, char **argv, 00454 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00455 { 00456 exports *p_exports = (exports *) p_nfs_struct; 00457 00458 groups group_list; 00459 00460 /* sanity check */ 00461 if(p_exports == NULL) 00462 return FALSE; 00463 00464 /* empty list */ 00465 if(*p_exports == NULL) 00466 return TRUE; 00467 00468 switch (encodeflag) 00469 { 00470 case CMDNFS_ENCODE: 00471 00472 /* it is never an input */ 00473 return FALSE; 00474 00475 break; 00476 case CMDNFS_DECODE: 00477 00478 fprintf(out_stream, "%*s{\n", indent, " "); 00479 fprintf(out_stream, "%*sex_dir = %s\n", indent + 2, " ", (*p_exports)->ex_dir); 00480 fprintf(out_stream, "%*sex_groups =\n", indent + 2, " "); 00481 00482 group_list = (*p_exports)->ex_groups; 00483 while(group_list) 00484 { 00485 fprintf(out_stream, "%*sgr_name = %s\n", indent + 4, " ", group_list->gr_name); 00486 group_list = group_list->gr_next; 00487 } 00488 00489 fprintf(out_stream, "%*s}\n", indent, " "); 00490 00491 if(cmdnfs_exports(CMDNFS_DECODE, 0, NULL, indent, out_stream, 00492 (caddr_t) & ((*p_exports)->ex_next)) == FALSE) 00493 { 00494 return FALSE; 00495 } 00496 00497 return TRUE; 00498 00499 break; 00500 00501 case CMDNFS_FREE: 00502 00503 /* it is never an input (never encoded, never allocated) */ 00504 return FALSE; 00505 00506 break; 00507 00508 default: 00509 return FALSE; 00510 } 00511 00512 } 00513 00514 int cmdnfs_fhandle3(cmdnfs_encodetype_t encodeflag, 00515 int argc, char **argv, 00516 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00517 { 00518 fhandle3 *p_fhandle = (fhandle3 *) p_nfs_struct; 00519 00520 char *str_handle; 00521 char str_printhandle[SIZE_STR_NFSHANDLE3]; 00522 int rc; 00523 00524 /* sanity check */ 00525 if(p_fhandle == NULL) 00526 return FALSE; 00527 00528 switch (encodeflag) 00529 { 00530 case CMDNFS_ENCODE: 00531 00532 if(argc != 1) 00533 return FALSE; 00534 00535 str_handle = argv[0]; 00536 00537 /* check that it begins with an @ */ 00538 if(str_handle[0] != '@') 00539 return FALSE; 00540 00541 /* escaping the first char @ */ 00542 str_handle++; 00543 00544 /* Allocation of the nfs3 handle */ 00545 p_fhandle->fhandle3_val = gsh_malloc(sizeof(struct alloc_file_handle_v3)); 00546 00547 if(p_fhandle->fhandle3_val == NULL) 00548 { 00549 fprintf(stderr, "Not enough memory.\n"); 00550 return FALSE; 00551 } 00552 00553 p_fhandle->fhandle3_len = (unsigned int)sizeof(struct alloc_file_handle_v3); 00554 00555 rc = sscanmem((caddr_t) (p_fhandle->fhandle3_val), 00556 (int)sizeof(struct alloc_file_handle_v3), 00557 str_handle); 00558 00559 if(rc < 2 * (int)sizeof(file_handle_v3_t)) 00560 return FALSE; 00561 00562 return TRUE; 00563 00564 break; 00565 case CMDNFS_DECODE: 00566 00567 if(snprintmem 00568 (str_printhandle, SIZE_STR_NFSHANDLE3, (caddr_t) (p_fhandle->fhandle3_val), 00569 p_fhandle->fhandle3_len) < 0) 00570 { 00571 return FALSE; 00572 } 00573 00574 fprintf(out_stream, "%*sfhandle3 = @%s\n", indent, " ", str_printhandle); 00575 00576 return TRUE; 00577 00578 break; 00579 00580 case CMDNFS_FREE: 00581 00582 gsh_free(p_fhandle->fhandle3_val); 00583 return TRUE; 00584 00585 break; 00586 00587 default: 00588 return FALSE; 00589 } 00590 00591 } 00592 00593 #define MNT_HANDLE( p_mount_res3 ) ( (p_mount_res3)->mountres3_u.mountinfo.fhandle ) 00594 #define AUTH_FLAVORS( p_mount_res3 ) ( (p_mount_res3)->mountres3_u.mountinfo.auth_flavors ) 00595 00596 int cmdnfs_mountres3(cmdnfs_encodetype_t encodeflag, 00597 int argc, char **argv, 00598 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00599 { 00600 unsigned int i; 00601 mountres3 *p_mountres = (mountres3 *) p_nfs_struct; 00602 00603 /* sanity check */ 00604 if(p_mountres == NULL) 00605 return FALSE; 00606 00607 switch (encodeflag) 00608 { 00609 case CMDNFS_DECODE: 00610 00611 fprintf(out_stream, "%*smountres3 =\n", indent, " "); 00612 fprintf(out_stream, "%*s{\n", indent, " "); 00613 00615 fprintf(out_stream, "%*sfhs_status = %u\n", indent + 2, " ", 00616 p_mountres->fhs_status); 00617 00618 if(p_mountres->fhs_status == MNT3_OK) 00619 { 00620 fprintf(out_stream, "%*smountinfo =\n", indent + 2, " "); 00621 fprintf(out_stream, "%*s{\n", indent + 2, " "); 00622 00623 if(cmdnfs_fhandle3(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 00624 (caddr_t) & MNT_HANDLE(p_mountres)) == FALSE) 00625 { 00626 return FALSE; 00627 } 00628 00629 for(i = 0; i < AUTH_FLAVORS(p_mountres).auth_flavors_len; i++) 00630 { 00631 fprintf(out_stream, "%*sauth_flavor = %d\n", indent + 4, " ", 00632 AUTH_FLAVORS(p_mountres).auth_flavors_val[i]); 00633 } 00634 00635 fprintf(out_stream, "%*s}\n", indent + 2, " "); 00636 } 00637 00638 fprintf(out_stream, "%*s}\n", indent, " "); 00639 00640 return TRUE; 00641 00642 break; 00643 00644 case CMDNFS_ENCODE: 00645 /* never an input */ 00646 case CMDNFS_FREE: 00647 /* it is never an input (never encoded, never allocated) */ 00648 default: 00649 return FALSE; 00650 } 00651 00652 } 00653 00654 /* undefine dirty macros... */ 00655 #undef MNT_HANDLE 00656 #undef AUTH_FLAVORS 00657 00658 int cmdnfs_nfsstat2(cmdnfs_encodetype_t encodeflag, 00659 int argc, char **argv, 00660 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00661 { 00662 nfsstat2 *p_stat2 = (nfsstat2 *) p_nfs_struct; 00663 00664 /* sanity check */ 00665 if(p_stat2 == NULL) 00666 return FALSE; 00667 00668 switch (encodeflag) 00669 { 00670 case CMDNFS_DECODE: 00671 00672 fprintf(out_stream, "%*sstatus = %d (%s)\n", indent, " ", (int)(*p_stat2), 00673 nfsstat2_to_str(*p_stat2)); 00674 return TRUE; 00675 00676 break; 00677 00678 case CMDNFS_ENCODE: 00679 case CMDNFS_FREE: 00680 /* never encoded */ 00681 default: 00682 return FALSE; 00683 } 00684 00685 } 00686 00687 int cmdnfs_fattr2(cmdnfs_encodetype_t encodeflag, 00688 int argc, char **argv, 00689 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00690 { 00691 fattr2 *p_fattr = (fattr2 *) p_nfs_struct; 00692 char tmp_buff[256] = ""; 00693 00694 struct tm paramtm; 00695 00696 /* sanity check */ 00697 if(p_fattr == NULL) 00698 return FALSE; 00699 00700 switch (encodeflag) 00701 { 00702 case CMDNFS_ENCODE: 00703 00705 return FALSE; 00706 00707 break; 00708 case CMDNFS_DECODE: 00709 00710 fprintf(out_stream, "%*sfattr2 =\n", indent, " "); 00711 fprintf(out_stream, "%*s{\n", indent, " "); 00712 00713 fprintf(out_stream, "%*stype = %d (%s)\n", indent + 2, " ", (int)p_fattr->type, 00714 nfstype2_to_str(p_fattr->type)); 00715 fprintf(out_stream, "%*smode = 0%o\n", indent + 2, " ", p_fattr->mode); 00716 fprintf(out_stream, "%*snlink = %u\n", indent + 2, " ", p_fattr->nlink); 00717 fprintf(out_stream, "%*suid = %u\n", indent + 2, " ", p_fattr->uid); 00718 fprintf(out_stream, "%*sgid = %u\n", indent + 2, " ", p_fattr->gid); 00719 fprintf(out_stream, "%*ssize = %u\n", indent + 2, " ", p_fattr->size); 00720 fprintf(out_stream, "%*sblocksize = %u\n", indent + 2, " ", p_fattr->blocksize); 00721 fprintf(out_stream, "%*srdev = %hu.%hu\n", indent + 2, " ", 00722 (unsigned short)(p_fattr->rdev >> 16), (unsigned short)p_fattr->rdev); 00723 fprintf(out_stream, "%*sblocks = %u\n", indent + 2, " ", p_fattr->blocks); 00724 fprintf(out_stream, "%*sfsid = %#x\n", indent + 2, " ", p_fattr->fsid); 00725 fprintf(out_stream, "%*sfileid = %#x\n", indent + 2, " ", p_fattr->fileid); 00726 00727 strftime(tmp_buff, 256, "%Y-%m-%d %T", 00728 Localtime_r((time_t *) & p_fattr->atime.seconds, ¶mtm)); 00729 fprintf(out_stream, "%*satime = %u.%.6u (%s)\n", indent + 2, " ", 00730 p_fattr->atime.seconds, p_fattr->atime.useconds, tmp_buff); 00731 00732 strftime(tmp_buff, 256, "%Y-%m-%d %T", 00733 Localtime_r((time_t *) & p_fattr->mtime.seconds, ¶mtm)); 00734 fprintf(out_stream, "%*smtime = %u.%.6u (%s)\n", indent + 2, " ", 00735 p_fattr->mtime.seconds, p_fattr->mtime.useconds, tmp_buff); 00736 00737 strftime(tmp_buff, 256, "%Y-%m-%d %T", 00738 Localtime_r((time_t *) & p_fattr->ctime.seconds, ¶mtm)); 00739 fprintf(out_stream, "%*sctime = %u.%.6u (%s)\n", indent + 2, " ", 00740 p_fattr->ctime.seconds, p_fattr->ctime.useconds, tmp_buff); 00741 00742 fprintf(out_stream, "%*s}\n", indent, " "); 00743 00744 return TRUE; 00745 00746 break; 00747 00748 case CMDNFS_FREE: 00749 00751 return FALSE; 00752 00753 break; 00754 00755 default: 00756 return FALSE; 00757 } 00758 00759 } 00760 00761 #define ATTR2_ATTRIBUTES( _p_attr2res ) ( (_p_attr2res)->ATTR2res_u.attributes ) 00762 00763 int cmdnfs_ATTR2res(cmdnfs_encodetype_t encodeflag, 00764 int argc, char **argv, 00765 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00766 { 00767 ATTR2res *p_attr2res = (ATTR2res *) p_nfs_struct; 00768 00769 /* sanity check */ 00770 if(p_attr2res == NULL) 00771 return FALSE; 00772 00773 switch (encodeflag) 00774 { 00775 case CMDNFS_DECODE: 00776 00777 fprintf(out_stream, "%*sATTR2res =\n", indent, " "); 00778 fprintf(out_stream, "%*s{\n", indent, " "); 00779 00780 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00781 (caddr_t) & p_attr2res->status) == FALSE) 00782 { 00783 return FALSE; 00784 } 00785 00786 if(p_attr2res->status == NFS_OK) 00787 { 00788 if(cmdnfs_fattr2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00789 (caddr_t) & ATTR2_ATTRIBUTES(p_attr2res)) == FALSE) 00790 { 00791 return FALSE; 00792 } 00793 00794 } 00795 00796 fprintf(out_stream, "%*s}\n", indent, " "); 00797 00798 return TRUE; 00799 00800 break; 00801 00802 case CMDNFS_ENCODE: 00803 /* never encoded */ 00804 case CMDNFS_FREE: 00805 /* it is never an input (never encoded, never allocated) */ 00806 default: 00807 return FALSE; 00808 } 00809 00810 } 00811 00812 #undef ATTR2_ATTRIBUTES 00813 00814 #define DIROP2_HANDLE( _p_dirop ) ( (_p_dirop)->DIROP2res_u.diropok.file ) 00815 #define DIROP2_ATTRIBUTES( _p_dirop ) ( (_p_dirop)->DIROP2res_u.diropok.attributes ) 00816 00817 int cmdnfs_DIROP2res(cmdnfs_encodetype_t encodeflag, 00818 int argc, char **argv, 00819 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00820 { 00821 DIROP2res *p_dirop2res = (DIROP2res *) p_nfs_struct; 00822 00823 /* sanity check */ 00824 if(p_dirop2res == NULL) 00825 return FALSE; 00826 00827 switch (encodeflag) 00828 { 00829 case CMDNFS_DECODE: 00830 00831 fprintf(out_stream, "%*sDIROP2res =\n", indent, " "); 00832 fprintf(out_stream, "%*s{\n", indent, " "); 00833 00834 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00835 (caddr_t) & p_dirop2res->status) == FALSE) 00836 { 00837 return FALSE; 00838 } 00839 00840 if(p_dirop2res->status == NFS_OK) 00841 { 00842 if(cmdnfs_fhandle2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00843 (caddr_t) & DIROP2_HANDLE(p_dirop2res)) == FALSE) 00844 { 00845 return FALSE; 00846 } 00847 00848 if(cmdnfs_fattr2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00849 (caddr_t) & DIROP2_ATTRIBUTES(p_dirop2res)) == FALSE) 00850 { 00851 return FALSE; 00852 } 00853 } 00854 00855 fprintf(out_stream, "%*s}\n", indent, " "); 00856 00857 return TRUE; 00858 00859 break; 00860 00861 case CMDNFS_ENCODE: 00862 /* never encoded */ 00863 case CMDNFS_FREE: 00864 /* it is never an input (never encoded, never allocated) */ 00865 default: 00866 return FALSE; 00867 } 00868 00869 } 00870 00871 #undef DIROP2_HANDLE 00872 #undef DIROP2_ATTRIBUTES 00873 00874 int cmdnfs_diropargs2(cmdnfs_encodetype_t encodeflag, 00875 int argc, char **argv, 00876 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00877 { 00878 diropargs2 *p_diropargs = (diropargs2 *) p_nfs_struct; 00879 00880 /* sanity check */ 00881 if(p_diropargs == NULL) 00882 return FALSE; 00883 00884 switch (encodeflag) 00885 { 00886 case CMDNFS_ENCODE: 00887 00888 if(argc != 2) 00889 return FALSE; 00890 00891 if(cmdnfs_fhandle2(CMDNFS_ENCODE, 1, argv, 0, NULL, 00892 (caddr_t) & (p_diropargs->dir)) == FALSE) 00893 { 00894 return FALSE; 00895 } 00896 00897 if(cmdnfs_dirpath(CMDNFS_ENCODE, 1, argv + 1, 0, NULL, 00898 (caddr_t) & (p_diropargs->name)) == FALSE) 00899 { 00900 return FALSE; 00901 } 00902 00903 return TRUE; 00904 00905 case CMDNFS_FREE: 00906 cmdnfs_fhandle2(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_diropargs->dir)); 00907 cmdnfs_dirpath(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_diropargs->name)); 00908 break; 00909 00910 case CMDNFS_DECODE: 00911 /* never decoded */ 00912 default: 00913 return FALSE; 00914 } 00915 return FALSE; 00916 } 00917 00918 #define READLINKRES_PATH( _p_rl2res ) ( (_p_rl2res)->READLINK2res_u.data ) 00919 00920 int cmdnfs_READLINK2res(cmdnfs_encodetype_t encodeflag, 00921 int argc, char **argv, 00922 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00923 { 00924 00925 READLINK2res *p_rl2res = (READLINK2res *) p_nfs_struct; 00926 00927 /* sanity check */ 00928 if(p_rl2res == NULL) 00929 return FALSE; 00930 00931 switch (encodeflag) 00932 { 00933 case CMDNFS_DECODE: 00934 00935 fprintf(out_stream, "%*sREADLINK2res =\n", indent, " "); 00936 fprintf(out_stream, "%*s{\n", indent, " "); 00937 00938 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 00939 (caddr_t) & p_rl2res->status) == FALSE) 00940 { 00941 return FALSE; 00942 } 00943 00944 if(p_rl2res->status == NFS_OK) 00945 { 00946 fprintf(out_stream, "%*sdata = \"%s\"\n", indent + 2, " ", 00947 READLINKRES_PATH(p_rl2res)); 00948 } 00949 00950 fprintf(out_stream, "%*s}\n", indent, " "); 00951 00952 return TRUE; 00953 00954 break; 00955 00956 case CMDNFS_ENCODE: 00957 /* never encoded */ 00958 case CMDNFS_FREE: 00959 /* it is never an input (never encoded, never allocated) */ 00960 default: 00961 return FALSE; 00962 } 00963 00964 } 00965 00966 #undef READLINKRES_PATH 00967 00968 int cmdnfs_sattr2(cmdnfs_encodetype_t encodeflag, 00969 int argc, char **argv, 00970 int indent, FILE * out_stream, caddr_t p_nfs_struct) 00971 { 00972 00973 sattr2 *p_sattr2 = (sattr2 *) p_nfs_struct; 00974 00975 char *next_str = NULL; 00976 char *attrib_str; 00977 char *value_str; 00978 00979 int mode, userid, groupid, rc; 00980 time_t a_sec, m_sec; 00981 int a_usec, m_usec; 00982 unsigned long long size; 00983 char *usec_str; 00984 char *time_str; 00985 00986 char tmp_buff[1024]; 00987 00988 /* sanity check */ 00989 if(p_sattr2 == NULL) 00990 return FALSE; 00991 00992 switch (encodeflag) 00993 { 00994 case CMDNFS_ENCODE: 00995 00996 /* inits structure */ 00997 00998 p_sattr2->mode = (unsigned int)-1; 00999 p_sattr2->uid = (unsigned int)-1; 01000 p_sattr2->gid = (unsigned int)-1; 01001 p_sattr2->size = (unsigned int)-1; 01002 p_sattr2->atime.seconds = (unsigned int)-1; 01003 p_sattr2->atime.useconds = (unsigned int)-1; 01004 p_sattr2->mtime.seconds = (unsigned int)-1; 01005 p_sattr2->mtime.useconds = (unsigned int)-1; 01006 01007 if(argc == 0) 01008 return TRUE; 01009 01010 /* at this point it must not be more than one string */ 01011 if(argc != 1) 01012 return FALSE; 01013 01014 /* the attributes are: 01015 * mode, uid, gid, size, atime, mtime 01016 */ 01017 strncpy(tmp_buff, argv[0], 1024); 01018 01019 attrib_str = strtok_r(tmp_buff, ",", &next_str); 01020 01021 if(attrib_str == NULL) 01022 { 01023 #ifdef _DEBUG_NFS_SHELL 01024 printf("Unexpected parsing error.\n"); 01025 #endif 01026 return FALSE; 01027 } 01028 01029 while(attrib_str != NULL) 01030 { 01031 01032 /* retrieving attribute name and value */ 01033 attrib_str = strtok_r(attrib_str, "=", &value_str); 01034 01035 if((attrib_str == NULL) || (value_str == NULL)) 01036 { 01037 #ifdef _DEBUG_NFS_SHELL 01038 printf 01039 ("Syntax error for sattr2.\nExpected syntax: <attr>=<value>,<attr>=<value>,...\n"); 01040 #endif 01041 return FALSE; 01042 } 01043 #ifdef _DEBUG_NFS_SHELL 01044 printf("Attribute: \"%s\", Value: \"%s\"\n", attrib_str, value_str); 01045 #endif 01046 01047 if(!strcasecmp(attrib_str, "mode")) 01048 { 01049 mode = atomode(value_str); 01050 if(mode < 0) 01051 return FALSE; 01052 p_sattr2->mode = (unsigned int)mode; 01053 #ifdef _DEBUG_NFS_SHELL 01054 printf(" mode = 0%o\n", p_sattr2->mode); 01055 #endif 01056 } 01057 else if(!strcasecmp(attrib_str, "uid")) 01058 { 01059 userid = my_atoi(value_str); 01060 if(userid < 0) 01061 return FALSE; 01062 p_sattr2->uid = (unsigned int)userid; 01063 #ifdef _DEBUG_NFS_SHELL 01064 printf(" uid = %u\n", p_sattr2->uid); 01065 #endif 01066 } 01067 else if(!strcasecmp(attrib_str, "gid")) 01068 { 01069 groupid = my_atoi(value_str); 01070 if(groupid < 0) 01071 return FALSE; 01072 p_sattr2->gid = (unsigned int)groupid; 01073 #ifdef _DEBUG_NFS_SHELL 01074 printf(" gid = %u\n", p_sattr2->gid); 01075 #endif 01076 } 01077 else if(!strcasecmp(attrib_str, "size")) 01078 { 01079 rc = ato64(value_str, &size); 01080 if(rc) 01081 return FALSE; 01082 if(size > (unsigned long long)UINT_MAX) 01083 return FALSE; 01084 p_sattr2->size = (unsigned int)size; 01085 #ifdef _DEBUG_NFS_SHELL 01086 printf(" size = %u\n", p_sattr2->size); 01087 #endif 01088 } 01089 else if(!strcasecmp(attrib_str, "atime")) 01090 { 01091 time_str = strtok_r(value_str, ".", &usec_str); 01092 01093 a_sec = atotime(time_str); 01094 if(a_sec == ((time_t) - 1)) 01095 return FALSE; 01096 01097 if(usec_str == NULL) 01098 { 01099 a_usec = 0; 01100 } 01101 else 01102 { 01103 a_usec = my_atoi(usec_str); 01104 /* 1 million is authorized and is interpreted by server as a "set to server time" */ 01105 if((a_usec < 0) || (a_usec > 1000000)) 01106 return FALSE; 01107 } 01108 p_sattr2->atime.seconds = (unsigned int)a_sec; 01109 p_sattr2->atime.useconds = (unsigned int)a_usec; 01110 01111 #ifdef _DEBUG_NFS_SHELL 01112 printf(" atime = %u.%.6u\n", p_sattr2->atime.seconds, 01113 p_sattr->atime.useconds); 01114 #endif 01115 } 01116 else if(!strcasecmp(attrib_str, "mtime")) 01117 { 01118 time_str = strtok_r(value_str, ".", &usec_str); 01119 01120 m_sec = atotime(time_str); 01121 if(m_sec == ((time_t) - 1)) 01122 return FALSE; 01123 01124 if(usec_str == NULL) 01125 { 01126 m_usec = 0; 01127 } 01128 else 01129 { 01130 m_usec = my_atoi(usec_str); 01131 /* 1 million is authorized and is interpreted by server as a "set to server time" */ 01132 if((m_usec < 0) || (m_usec > 1000000)) 01133 return FALSE; 01134 } 01135 p_sattr2->mtime.seconds = (unsigned int)m_sec; 01136 p_sattr2->mtime.useconds = (unsigned int)m_usec; 01137 01138 #ifdef _DEBUG_NFS_SHELL 01139 printf(" mtime = %u.%.6u\n", p_sattr2->mtime.seconds, 01140 p_sattr->mtime.useconds); 01141 #endif 01142 } 01143 else 01144 { 01145 #ifdef _DEBUG_NFS_SHELL 01146 printf 01147 ("Syntax error for sattr2.\n<attr> must be one of the following: mode, uid, gid, size, atime, mtime.\n"); 01148 #endif 01149 return FALSE; 01150 } 01151 01152 attrib_str = next_str; 01153 01154 next_str = NULL; /* paranoid setting */ 01155 value_str = NULL; /* paranoid setting */ 01156 01157 if(attrib_str != NULL) 01158 attrib_str = strtok_r(attrib_str, ",", &next_str); 01159 01160 } 01161 01162 return TRUE; 01163 01164 case CMDNFS_FREE: 01165 /* nothing to do */ 01166 return TRUE; 01167 break; 01168 01169 case CMDNFS_DECODE: 01170 /* never decoded */ 01171 default: 01172 return FALSE; 01173 } 01174 01175 } 01176 01177 int cmdnfs_CREATE2args(cmdnfs_encodetype_t encodeflag, 01178 int argc, char **argv, 01179 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01180 { 01181 CREATE2args *p_create2args = (CREATE2args *) p_nfs_struct; 01182 01183 /* sanity check */ 01184 if(p_create2args == NULL) 01185 return FALSE; 01186 01187 switch (encodeflag) 01188 { 01189 case CMDNFS_ENCODE: 01190 01191 if(cmdnfs_diropargs2(CMDNFS_ENCODE, 2, argv, 0, NULL, 01192 (caddr_t) & (p_create2args->where)) == FALSE) 01193 { 01194 return FALSE; 01195 } 01196 01197 /* optional sattr2 parameters */ 01198 if(cmdnfs_sattr2(CMDNFS_ENCODE, argc - 2, argv + 2, 0, NULL, 01199 (caddr_t) & (p_create2args->attributes)) == FALSE) 01200 { 01201 return FALSE; 01202 } 01203 01204 return TRUE; 01205 01206 case CMDNFS_FREE: 01207 cmdnfs_diropargs2(CMDNFS_FREE, 0, NULL, 0, NULL, 01208 (caddr_t) & (p_create2args->where)); 01209 cmdnfs_sattr2(CMDNFS_FREE, 0, NULL, 0, NULL, 01210 (caddr_t) & (p_create2args->attributes)); 01211 break; 01212 01213 case CMDNFS_DECODE: 01214 /* never decoded */ 01215 default: 01216 return FALSE; 01217 } 01218 return FALSE; 01219 } 01220 01221 int cmdnfs_SETATTR2args(cmdnfs_encodetype_t encodeflag, 01222 int argc, char **argv, 01223 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01224 { 01225 SETATTR2args *p_SETATTR2args = (SETATTR2args *) p_nfs_struct; 01226 01227 /* sanity check */ 01228 if(p_SETATTR2args == NULL) 01229 return FALSE; 01230 01231 switch (encodeflag) 01232 { 01233 case CMDNFS_ENCODE: 01234 01235 if(argc != 2) 01236 return FALSE; 01237 01238 if(cmdnfs_fhandle2(CMDNFS_ENCODE, 1, argv, 0, NULL, 01239 (caddr_t) & (p_SETATTR2args->file)) == FALSE) 01240 { 01241 return FALSE; 01242 } 01243 01244 /* mandatory sattr2 parameter */ 01245 if(cmdnfs_sattr2(CMDNFS_ENCODE, argc - 1, argv + 1, 0, NULL, 01246 (caddr_t) & (p_SETATTR2args->attributes)) == FALSE) 01247 { 01248 return FALSE; 01249 } 01250 01251 return TRUE; 01252 01253 case CMDNFS_FREE: 01254 cmdnfs_fhandle2(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_SETATTR2args->file)); 01255 cmdnfs_sattr2(CMDNFS_FREE, 0, NULL, 0, NULL, 01256 (caddr_t) & (p_SETATTR2args->attributes)); 01257 break; 01258 01259 case CMDNFS_DECODE: 01260 /* never decoded */ 01261 default: 01262 return FALSE; 01263 } 01264 return FALSE; 01265 } 01266 01267 int cmdnfs_READDIR2args(cmdnfs_encodetype_t encodeflag, 01268 int argc, char **argv, 01269 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01270 { 01271 caddr_t p_cookie; 01272 int count; 01273 int cookie; 01274 READDIR2args *p_READDIR2args = (READDIR2args *) p_nfs_struct; 01275 01276 /* sanity check */ 01277 if(p_READDIR2args == NULL) 01278 return FALSE; 01279 01280 switch (encodeflag) 01281 { 01282 case CMDNFS_ENCODE: 01283 01284 if(argc != 3) 01285 return FALSE; 01286 01287 if(cmdnfs_fhandle2(CMDNFS_ENCODE, 1, argv, 0, NULL, 01288 (caddr_t) & (p_READDIR2args->dir)) == FALSE) 01289 { 01290 return FALSE; 01291 } 01292 01293 /* cookie = 4 octets */ 01294 01295 cookie = my_atoi(argv[1]); 01296 if(cookie < 0) 01297 return FALSE; 01298 p_cookie = (caddr_t) & (p_READDIR2args->cookie); 01299 01300 memcpy(p_cookie, &cookie, 4); 01301 01302 /* count */ 01303 01304 count = my_atoi(argv[2]); 01305 if(count < 0) 01306 return FALSE; 01307 p_READDIR2args->count = (unsigned int)count; 01308 01309 return TRUE; 01310 01311 case CMDNFS_FREE: 01312 cmdnfs_fhandle2(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_READDIR2args->dir)); 01313 01314 break; 01315 01316 case CMDNFS_DECODE: 01317 /* never decoded */ 01318 default: 01319 return FALSE; 01320 } 01321 return FALSE; 01322 } 01323 01324 static int cmdnfs_READDIR2resok(cmdnfs_encodetype_t encodeflag, 01325 int argc, char **argv, 01326 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01327 { 01328 READDIR2resok *p_READDIR2resok = (READDIR2resok *) p_nfs_struct; 01329 01330 entry2 *p_entry2 = p_READDIR2resok->entries; 01331 01332 switch (encodeflag) 01333 { 01334 case CMDNFS_DECODE: 01335 01336 /* print the list of entries */ 01337 if(p_entry2 != NULL) 01338 fprintf(out_stream, "%*sDirEntries:\n", indent, " "); 01339 01340 while(p_entry2) 01341 { 01342 fprintf(out_stream, "%*s{\n", indent + 2, " "); 01343 fprintf(out_stream, "%*sfileid = %#x\n", indent + 4, " ", p_entry2->fileid); 01344 fprintf(out_stream, "%*sname = %s\n", indent + 4, " ", p_entry2->name); 01345 fprintf(out_stream, "%*scookie = %u\n", indent + 4, " ", 01346 *(p_entry2->cookie)); 01347 fprintf(out_stream, "%*s}\n", indent + 2, " "); 01348 01349 p_entry2 = p_entry2->nextentry; 01350 } 01351 01352 /* prinf the eof boolean */ 01353 01354 if(p_READDIR2resok->eof) 01355 fprintf(out_stream, "%*seof = TRUE\n", indent, " "); 01356 else 01357 fprintf(out_stream, "%*seof = FALSE\n", indent, " "); 01358 01359 return TRUE; 01360 break; 01361 01362 case CMDNFS_ENCODE: 01363 /* never encoded */ 01364 case CMDNFS_FREE: 01365 /* it is never an input (never encoded, never allocated) */ 01366 default: 01367 return FALSE; 01368 } 01369 } 01370 01371 int cmdnfs_READDIR2res(cmdnfs_encodetype_t encodeflag, 01372 int argc, char **argv, 01373 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01374 { 01375 READDIR2res *p_READDIR2res = (READDIR2res *) p_nfs_struct; 01376 01377 /* sanity check */ 01378 if(p_READDIR2res == NULL) 01379 return FALSE; 01380 01381 switch (encodeflag) 01382 { 01383 case CMDNFS_ENCODE: 01384 01385 /* it is never an input */ 01386 return FALSE; 01387 01388 break; 01389 case CMDNFS_DECODE: 01390 01391 fprintf(out_stream, "%*sREADDIR2res =\n", indent, " "); 01392 fprintf(out_stream, "%*s{\n", indent, " "); 01393 01394 /* Convert status to error code */ 01395 if(cmdnfs_nfsstat2(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 01396 (caddr_t) & p_READDIR2res->status) == FALSE) 01397 { 01398 return FALSE; 01399 } 01400 01401 if(p_READDIR2res->status == NFS_OK) 01402 { 01403 if(cmdnfs_READDIR2resok(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 01404 (caddr_t) & p_READDIR2res->READDIR2res_u.readdirok) == 01405 FALSE) 01406 { 01407 return FALSE; 01408 } 01409 } 01410 fprintf(out_stream, "%*s}\n", indent, " "); 01411 01412 return TRUE; 01413 01414 break; 01415 01416 case CMDNFS_FREE: 01417 01418 /* it is never an input (never encoded, never allocated) */ 01419 return FALSE; 01420 01421 break; 01422 01423 default: 01424 return FALSE; 01425 } 01426 } 01427 01428 int cmdnfs_RENAME2args(cmdnfs_encodetype_t encodeflag, 01429 int argc, char **argv, 01430 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01431 { 01432 RENAME2args *p_RENAME2args = (RENAME2args *) p_nfs_struct; 01433 01434 /* sanity check */ 01435 if(p_RENAME2args == NULL) 01436 return FALSE; 01437 01438 switch (encodeflag) 01439 { 01440 case CMDNFS_ENCODE: 01441 01442 if(argc != 4) 01443 return FALSE; 01444 01445 /* The first 2 args */ 01446 if(cmdnfs_diropargs2(CMDNFS_ENCODE, 2, argv, 0, NULL, 01447 (caddr_t) & (p_RENAME2args->from)) == FALSE) 01448 { 01449 return FALSE; 01450 } 01451 01452 /* The last 2 args */ 01453 if(cmdnfs_diropargs2(CMDNFS_ENCODE, argc - 2, argv + 2, 0, NULL, 01454 (caddr_t) & (p_RENAME2args->to)) == FALSE) 01455 { 01456 return FALSE; 01457 } 01458 01459 return TRUE; 01460 01461 case CMDNFS_FREE: 01462 cmdnfs_diropargs2(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_RENAME2args->from)); 01463 cmdnfs_diropargs2(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_RENAME2args->to)); 01464 return TRUE; 01465 break; 01466 01467 case CMDNFS_DECODE: 01468 /* never decoded */ 01469 default: 01470 return FALSE; 01471 } 01472 } 01473 01474 int cmdnfs_nfsstat3(cmdnfs_encodetype_t encodeflag, 01475 int argc, char **argv, 01476 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01477 { 01478 nfsstat3 *p_stat3 = (nfsstat3 *) p_nfs_struct; 01479 01480 /* sanity check */ 01481 if(p_stat3 == NULL) 01482 return FALSE; 01483 01484 switch (encodeflag) 01485 { 01486 case CMDNFS_DECODE: 01487 01488 fprintf(out_stream, "%*sstatus = %d (%s)\n", indent, " ", (int)(*p_stat3), 01489 nfsstat3_to_str(*p_stat3)); 01490 return TRUE; 01491 01492 break; 01493 01494 case CMDNFS_ENCODE: 01495 case CMDNFS_FREE: 01496 /* never encoded */ 01497 default: 01498 return FALSE; 01499 } 01500 01501 } 01502 01503 int cmdnfs_fattr3(cmdnfs_encodetype_t encodeflag, 01504 int argc, char **argv, 01505 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01506 { 01507 fattr3 *p_fattr = (fattr3 *) p_nfs_struct; 01508 char tmp_buff[256] = ""; 01509 struct tm paramtm; 01510 01511 /* sanity check */ 01512 if(p_fattr == NULL) 01513 return FALSE; 01514 01515 switch (encodeflag) 01516 { 01517 case CMDNFS_ENCODE: 01518 01520 return FALSE; 01521 01522 break; 01523 case CMDNFS_DECODE: 01524 01525 fprintf(out_stream, "%*sfattr3 =\n", indent, " "); 01526 fprintf(out_stream, "%*s{\n", indent, " "); 01527 01528 fprintf(out_stream, "%*stype = %d (%s)\n", indent + 2, " ", (int)p_fattr->type, 01529 nfstype3_to_str(p_fattr->type)); 01530 fprintf(out_stream, "%*smode = 0%o\n", indent + 2, " ", p_fattr->mode); 01531 fprintf(out_stream, "%*snlink = %u\n", indent + 2, " ", p_fattr->nlink); 01532 fprintf(out_stream, "%*suid = %u\n", indent + 2, " ", p_fattr->uid); 01533 fprintf(out_stream, "%*sgid = %u\n", indent + 2, " ", p_fattr->gid); 01534 fprintf(out_stream, "%*ssize = %llu\n", indent + 2, " ", p_fattr->size); 01535 fprintf(out_stream, "%*sused = %llu\n", indent + 2, " ", p_fattr->used); 01536 fprintf(out_stream, "%*srdev = %u.%u\n", indent + 2, " ", p_fattr->rdev.specdata1, 01537 p_fattr->rdev.specdata2); 01538 fprintf(out_stream, "%*sfsid = %#llx\n", indent + 2, " ", p_fattr->fsid); 01539 fprintf(out_stream, "%*sfileid = %#llx\n", indent + 2, " ", p_fattr->fileid); 01540 01541 strftime(tmp_buff, 256, "%Y-%m-%d %T", 01542 Localtime_r((time_t *) & p_fattr->atime.seconds, ¶mtm)); 01543 fprintf(out_stream, "%*satime = %u.%.9u (%s)\n", indent + 2, " ", 01544 p_fattr->atime.seconds, p_fattr->atime.nseconds, tmp_buff); 01545 01546 strftime(tmp_buff, 256, "%Y-%m-%d %T", 01547 Localtime_r((time_t *) & p_fattr->mtime.seconds, ¶mtm)); 01548 fprintf(out_stream, "%*smtime = %u.%.9u (%s)\n", indent + 2, " ", 01549 p_fattr->mtime.seconds, p_fattr->mtime.nseconds, tmp_buff); 01550 01551 strftime(tmp_buff, 256, "%Y-%m-%d %T", 01552 Localtime_r((time_t *) & p_fattr->ctime.seconds, ¶mtm)); 01553 fprintf(out_stream, "%*sctime = %u.%.9u (%s)\n", indent + 2, " ", 01554 p_fattr->ctime.seconds, p_fattr->ctime.nseconds, tmp_buff); 01555 01556 fprintf(out_stream, "%*s}\n", indent, " "); 01557 01558 return TRUE; 01559 01560 break; 01561 01562 case CMDNFS_FREE: 01563 01565 return FALSE; 01566 01567 break; 01568 01569 default: 01570 return FALSE; 01571 } 01572 01573 } 01574 01575 /* interprets a list of attributes separated with a colon : 01576 * mode=0755,uid=...,gid=...,etc... 01577 */ 01578 int cmdnfs_sattr3(cmdnfs_encodetype_t encodeflag, 01579 int argc, char **argv, 01580 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01581 { 01582 sattr3 *p_sattr = (sattr3 *) p_nfs_struct; 01583 char *next_str = NULL; 01584 char *attrib_str; 01585 char *value_str; 01586 01587 int mode, userid, groupid, rc; 01588 time_t a_sec, m_sec; 01589 int a_nsec, m_nsec; 01590 unsigned long long size; 01591 char *nsec_str; 01592 char *time_str; 01593 char tmp_buff[1024]; 01594 01595 /* sanity check */ 01596 if(p_sattr == NULL) 01597 return FALSE; 01598 01599 switch (encodeflag) 01600 { 01601 case CMDNFS_ENCODE: 01602 01603 /* inits structure */ 01604 memset((caddr_t) p_sattr, 0, sizeof(sattr3)); 01605 01606 p_sattr->mode.set_it = FALSE; 01607 p_sattr->uid.set_it = FALSE; 01608 p_sattr->gid.set_it = FALSE; 01609 p_sattr->size.set_it = FALSE; 01610 p_sattr->atime.set_it = DONT_CHANGE; 01611 p_sattr->mtime.set_it = DONT_CHANGE; 01612 01613 if(argc == 0) 01614 return TRUE; 01615 01616 /* at this point it must not be more than one string */ 01617 if(argc != 1) 01618 return FALSE; 01619 01620 /* the attributes are: 01621 * mode, uid, gid, size, atime, mtime 01622 */ 01623 strncpy(tmp_buff, argv[0], 1024); 01624 01625 attrib_str = strtok_r(tmp_buff, ",", &next_str); 01626 01627 if(attrib_str == NULL) 01628 { 01629 #ifdef _DEBUG_NFS_SHELL 01630 printf("Unexpected parsing error.\n"); 01631 #endif 01632 return FALSE; 01633 } 01634 01635 while(attrib_str != NULL) 01636 { 01637 01638 /* retrieving attribute value */ 01639 attrib_str = strtok_r(attrib_str, "=", &value_str); 01640 01641 if((attrib_str == NULL) || (value_str == NULL)) 01642 { 01643 #ifdef _DEBUG_NFS_SHELL 01644 printf 01645 ("Syntax error for sattr3.\nExpected syntax: <attr>=<value>,<attr>=<value>,...\n"); 01646 #endif 01647 return FALSE; 01648 } 01649 #ifdef _DEBUG_NFS_SHELL 01650 printf("Attribute: \"%s\", Value: \"%s\"\n", attrib_str, value_str); 01651 #endif 01652 01653 if(!strcasecmp(attrib_str, "mode")) 01654 { 01655 mode = atomode(value_str); 01656 if(mode < 0) 01657 return FALSE; 01658 p_sattr->mode.set_it = TRUE; 01659 p_sattr->mode.set_mode3_u.mode = (unsigned int)mode; 01660 #ifdef _DEBUG_NFS_SHELL 01661 printf(" mode = 0%o\n", p_sattr->mode.set_mode3_u.mode); 01662 #endif 01663 } 01664 else if(!strcasecmp(attrib_str, "uid")) 01665 { 01666 userid = my_atoi(value_str); 01667 if(userid < 0) 01668 return FALSE; 01669 p_sattr->uid.set_it = TRUE; 01670 p_sattr->uid.set_uid3_u.uid = (unsigned int)userid; 01671 #ifdef _DEBUG_NFS_SHELL 01672 printf(" uid = %u\n", p_sattr->uid.set_uid3_u.uid); 01673 #endif 01674 } 01675 else if(!strcasecmp(attrib_str, "gid")) 01676 { 01677 groupid = my_atoi(value_str); 01678 if(groupid < 0) 01679 return FALSE; 01680 p_sattr->gid.set_it = TRUE; 01681 p_sattr->gid.set_gid3_u.gid = (unsigned int)groupid; 01682 #ifdef _DEBUG_NFS_SHELL 01683 printf(" gid = %u\n", p_sattr->gid.set_gid3_u.gid); 01684 #endif 01685 } 01686 else if(!strcasecmp(attrib_str, "size")) 01687 { 01688 rc = ato64(value_str, &size); 01689 if(rc) 01690 return FALSE; 01691 p_sattr->size.set_it = TRUE; 01692 p_sattr->size.set_size3_u.size = (size3) size; 01693 #ifdef _DEBUG_NFS_SHELL 01694 printf(" size = %llu\n", p_sattr->size.set_size3_u.size); 01695 #endif 01696 } 01697 else if(!strcasecmp(attrib_str, "atime")) 01698 { 01699 time_str = strtok_r(value_str, ".", &nsec_str); 01700 01701 a_sec = atotime(time_str); 01702 if(a_sec == ((time_t) - 1)) 01703 return FALSE; 01704 01705 if(nsec_str == NULL) 01706 { 01707 a_nsec = 0; 01708 } 01709 else 01710 { 01711 a_nsec = my_atoi(nsec_str); 01712 if((a_nsec < 0) || (a_nsec > 999999999)) 01713 return FALSE; 01714 } 01715 01716 p_sattr->atime.set_it = SET_TO_CLIENT_TIME; 01717 p_sattr->atime.set_atime_u.atime.seconds = a_sec; 01718 p_sattr->atime.set_atime_u.atime.nseconds = a_nsec; 01719 01720 #ifdef _DEBUG_NFS_SHELL 01721 printf(" atime = %u.%.9u\n", p_sattr->atime.set_atime_u.atime.seconds, 01722 p_sattr->atime.set_atime_u.atime.nseconds); 01723 #endif 01724 } 01725 else if(!strcasecmp(attrib_str, "mtime")) 01726 { 01727 time_str = strtok_r(value_str, ".", &nsec_str); 01728 01729 m_sec = atotime(time_str); 01730 if(m_sec == ((time_t) - 1)) 01731 return FALSE; 01732 01733 if(nsec_str == NULL) 01734 { 01735 m_nsec = 0; 01736 } 01737 else 01738 { 01739 m_nsec = my_atoi(nsec_str); 01740 if((m_nsec < 0) || (m_nsec > 999999999)) 01741 return FALSE; 01742 } 01743 01744 p_sattr->mtime.set_it = SET_TO_CLIENT_TIME; 01745 p_sattr->mtime.set_mtime_u.mtime.seconds = m_sec; 01746 p_sattr->mtime.set_mtime_u.mtime.nseconds = m_nsec; 01747 #ifdef _DEBUG_NFS_SHELL 01748 printf(" mtime = %u.%.9u\n", p_sattr->mtime.set_mtime_u.mtime.seconds, 01749 p_sattr->mtime.set_mtime_u.mtime.nseconds); 01750 #endif 01751 } 01752 else 01753 { 01754 #ifdef _DEBUG_NFS_SHELL 01755 printf 01756 ("Syntax error for sattr3.\n<attr> must be one of the following: mode, uid, gid, size, atime, mtime.\n"); 01757 #endif 01758 return FALSE; 01759 } 01760 01761 attrib_str = next_str; 01762 01763 next_str = NULL; /* paranoid setting */ 01764 value_str = NULL; /* paranoid setting */ 01765 01766 if(attrib_str != NULL) 01767 attrib_str = strtok_r(attrib_str, ",", &next_str); 01768 01769 } 01770 01771 return TRUE; 01772 break; 01773 01774 case CMDNFS_FREE: 01775 /* nothing to do */ 01776 return TRUE; 01777 break; 01778 01779 case CMDNFS_DECODE: 01780 /* never decoded */ 01781 default: 01782 return FALSE; 01783 } 01784 01785 } /* cmdnfs_sattr3 */ 01786 01787 #define GETATTR3_ATTRIBUTES( _p_GETATTR3res ) ( (_p_GETATTR3res)->GETATTR3res_u.resok.obj_attributes ) 01788 01789 int cmdnfs_GETATTR3res(cmdnfs_encodetype_t encodeflag, 01790 int argc, char **argv, 01791 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01792 { 01793 GETATTR3res *p_gattr3res = (GETATTR3res *) p_nfs_struct; 01794 01795 /* sanity check */ 01796 if(p_gattr3res == NULL) 01797 return FALSE; 01798 01799 switch (encodeflag) 01800 { 01801 case CMDNFS_DECODE: 01802 01803 fprintf(out_stream, "%*sGETATTR3res =\n", indent, " "); 01804 fprintf(out_stream, "%*s{\n", indent, " "); 01805 01806 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 01807 (caddr_t) & p_gattr3res->status) == FALSE) 01808 { 01809 return FALSE; 01810 } 01811 01812 if(p_gattr3res->status == NFS3_OK) 01813 { 01814 if(cmdnfs_fattr3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 01815 (caddr_t) & GETATTR3_ATTRIBUTES(p_gattr3res)) == FALSE) 01816 { 01817 return FALSE; 01818 } 01819 01820 } 01821 01822 fprintf(out_stream, "%*s}\n", indent, " "); 01823 01824 return TRUE; 01825 01826 break; 01827 01828 case CMDNFS_ENCODE: 01829 /* never encoded */ 01830 case CMDNFS_FREE: 01831 /* it is never an input (never encoded, never allocated) */ 01832 default: 01833 return FALSE; 01834 } 01835 01836 } 01837 01838 #undef GETATTR3_ATTRIBUTES 01839 01840 int cmdnfs_diropargs3(cmdnfs_encodetype_t encodeflag, 01841 int argc, char **argv, 01842 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01843 { 01844 diropargs3 *p_dirop3 = (diropargs3 *) p_nfs_struct; 01845 01846 /* sanity check */ 01847 if(p_dirop3 == NULL) 01848 return FALSE; 01849 01850 switch (encodeflag) 01851 { 01852 case CMDNFS_ENCODE: 01853 01854 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 01855 (caddr_t) & (p_dirop3->dir)) == FALSE) 01856 { 01857 return FALSE; 01858 } 01859 01860 if(cmdnfs_dirpath(CMDNFS_ENCODE, argc - 1, argv + 1, 0, NULL, 01861 (caddr_t) & (p_dirop3->name)) == FALSE) 01862 { 01863 return FALSE; 01864 } 01865 01866 return TRUE; 01867 01868 case CMDNFS_FREE: 01869 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_dirop3->dir)); 01870 cmdnfs_dirpath(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_dirop3->name)); 01871 break; 01872 01873 case CMDNFS_DECODE: 01874 /* never decoded */ 01875 default: 01876 return FALSE; 01877 } 01878 return FALSE; 01879 } 01880 01881 int cmdnfs_postopattr(cmdnfs_encodetype_t encodeflag, 01882 int argc, char **argv, 01883 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01884 { 01885 post_op_attr *p_opattr = (post_op_attr *) p_nfs_struct; 01886 01887 /* sanity check */ 01888 if(p_opattr == NULL) 01889 return FALSE; 01890 01891 switch (encodeflag) 01892 { 01893 case CMDNFS_DECODE: 01894 01895 if(p_opattr->attributes_follow) 01896 { 01897 return cmdnfs_fattr3(CMDNFS_DECODE, 0, NULL, indent, out_stream, 01898 (caddr_t) & (p_opattr->post_op_attr_u.attributes)); 01899 } 01900 else 01901 { 01902 fprintf(out_stream, "%*sN/A\n", indent, " "); 01903 return TRUE; 01904 } 01905 01906 break; 01907 01908 case CMDNFS_ENCODE: 01909 /* never encoded */ 01910 case CMDNFS_FREE: 01911 /* it is never an input (never encoded, never allocated) */ 01912 default: 01913 return FALSE; 01914 } 01915 } 01916 01917 int cmdnfs_postopfh3(cmdnfs_encodetype_t encodeflag, 01918 int argc, char **argv, 01919 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01920 { 01921 post_op_fh3 *p_opfh3 = (post_op_fh3 *) p_nfs_struct; 01922 01923 /* sanity check */ 01924 if(p_opfh3 == NULL) 01925 return FALSE; 01926 01927 switch (encodeflag) 01928 { 01929 case CMDNFS_DECODE: 01930 01931 if(p_opfh3->handle_follows) 01932 { 01933 return cmdnfs_fhandle3(CMDNFS_DECODE, 0, NULL, indent, out_stream, 01934 (caddr_t) & (p_opfh3->post_op_fh3_u.handle)); 01935 } 01936 else 01937 { 01938 fprintf(out_stream, "%*sN/A\n", indent, " "); 01939 return TRUE; 01940 } 01941 01942 break; 01943 01944 case CMDNFS_ENCODE: 01945 /* never encoded */ 01946 case CMDNFS_FREE: 01947 /* it is never an input (never encoded, never allocated) */ 01948 default: 01949 return FALSE; 01950 } 01951 } 01952 01953 #define LOOKUP3_OK_HANDLE( _p_LOOKUP3res ) ( (_p_LOOKUP3res)->LOOKUP3res_u.resok.object ) 01954 #define LOOKUP3_OK_OBJATTR( _p_LOOKUP3res ) ( (_p_LOOKUP3res)->LOOKUP3res_u.resok.obj_attributes ) 01955 #define LOOKUP3_OK_DIRATTR( _p_LOOKUP3res ) ( (_p_LOOKUP3res)->LOOKUP3res_u.resok.dir_attributes ) 01956 #define LOOKUP3_FAIL_DIRATTR( _p_LOOKUP3res ) ( (_p_LOOKUP3res)->LOOKUP3res_u.resfail.dir_attributes ) 01957 01958 int cmdnfs_LOOKUP3res(cmdnfs_encodetype_t encodeflag, 01959 int argc, char **argv, 01960 int indent, FILE * out_stream, caddr_t p_nfs_struct) 01961 { 01962 LOOKUP3res *p_lkup3res = (LOOKUP3res *) p_nfs_struct; 01963 01964 /* sanity check */ 01965 if(p_lkup3res == NULL) 01966 return FALSE; 01967 01968 switch (encodeflag) 01969 { 01970 case CMDNFS_DECODE: 01971 01972 fprintf(out_stream, "%*sLOOKUP3res =\n", indent, " "); 01973 fprintf(out_stream, "%*s{\n", indent, " "); 01974 01975 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 01976 (caddr_t) & p_lkup3res->status) == FALSE) 01977 { 01978 return FALSE; 01979 } 01980 01981 if(p_lkup3res->status == NFS3_OK) 01982 { 01983 01984 fprintf(out_stream, "%*sObject Handle:\n", indent + 2, " "); 01985 if(cmdnfs_fhandle3(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 01986 (caddr_t) & LOOKUP3_OK_HANDLE(p_lkup3res)) == FALSE) 01987 { 01988 return FALSE; 01989 } 01990 01991 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 01992 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 01993 (caddr_t) & LOOKUP3_OK_OBJATTR(p_lkup3res)) == FALSE) 01994 { 01995 return FALSE; 01996 } 01997 01998 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 01999 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02000 (caddr_t) & LOOKUP3_OK_DIRATTR(p_lkup3res)) == FALSE) 02001 { 02002 return FALSE; 02003 } 02004 02005 } 02006 else 02007 { 02008 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 02009 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02010 (caddr_t) & LOOKUP3_FAIL_DIRATTR(p_lkup3res)) == FALSE) 02011 { 02012 return FALSE; 02013 } 02014 } 02015 02016 fprintf(out_stream, "%*s}\n", indent, " "); 02017 02018 return TRUE; 02019 02020 break; 02021 02022 case CMDNFS_ENCODE: 02023 /* never encoded */ 02024 case CMDNFS_FREE: 02025 /* it is never an input (never encoded, never allocated) */ 02026 default: 02027 return FALSE; 02028 } 02029 02030 } 02031 02032 #undef LOOKUP3_OK_HANDLE 02033 #undef LOOKUP3_OK_OBJATTR 02034 #undef LOOKUP3_OK_DIRATTR 02035 #undef LOOKUP3_FAIL_DIRATTR 02036 02037 static int cmdnfs_verf3(cmdnfs_encodetype_t encodeflag, int argc, char **argv, int indent, FILE * out_stream, caddr_t p_nfs_struct, char *verfname /* name to be printed for the verifier (DECODE mode only) */ 02038 ) 02039 { 02040 /* pointer to an opaque buff */ 02041 caddr_t p_verf = p_nfs_struct; 02042 02043 char *str_verf; 02044 char str_printverf[17]; 02045 int rc; 02046 02047 /* sanity check */ 02048 if(p_verf == NULL) 02049 return FALSE; 02050 02051 switch (encodeflag) 02052 { 02053 case CMDNFS_ENCODE: 02054 02055 if(argc != 1) 02056 return FALSE; 02057 02058 str_verf = argv[0]; 02059 02060 memset(p_verf, 0, 8); 02061 02062 rc = sscanmem(p_verf, 8, str_verf); 02063 02064 #ifdef _DEBUG_NFS_SHELL 02065 fprintf(stderr, "verf = \"%s\"\n", str_verf); 02066 fprintf(stderr, "-> %d bytes read.\n", rc); 02067 fprintf(stderr, "buffer=%02X.%02X.%02X.%02X.%02X.%02X.%02X.%02X\n", 02068 p_verf[0], p_verf[1], p_verf[2], p_verf[3], 02069 p_verf[4], p_verf[5], p_verf[6], p_verf[7]); 02070 02071 #endif 02072 02073 /* we must have read at least the verf size */ 02074 if(rc < 0) 02075 return FALSE; 02076 02077 return TRUE; 02078 02079 break; 02080 case CMDNFS_DECODE: 02081 02082 if(snprintmem(str_printverf, 17, p_verf, 8) < 0) 02083 { 02084 return FALSE; 02085 } 02086 02087 fprintf(out_stream, "%*s%s = %s\n", indent, " ", verfname, str_printverf); 02088 02089 return TRUE; 02090 break; 02091 02092 case CMDNFS_FREE: 02093 /* nothing to do */ 02094 return TRUE; 02095 break; 02096 02097 default: 02098 return FALSE; 02099 } 02100 } 02101 02102 static int cmdnfs_dirlist3(cmdnfs_encodetype_t encodeflag, 02103 int argc, char **argv, 02104 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02105 { 02106 dirlist3 *p_dirlist3 = (dirlist3 *) p_nfs_struct; 02107 02108 entry3 *p_entry = NULL; 02109 02110 /* sanity check */ 02111 if(p_dirlist3 == NULL) 02112 return FALSE; 02113 02114 switch (encodeflag) 02115 { 02116 case CMDNFS_DECODE: 02117 02118 /* print the list of entries */ 02119 p_entry = p_dirlist3->entries; 02120 02121 fprintf(out_stream, "%*sDirEntries:\n", indent, " "); 02122 while(p_entry) 02123 { 02124 fprintf(out_stream, "%*s{\n", indent + 2, " "); 02125 fprintf(out_stream, "%*sfileid = %#llx\n", indent + 4, " ", p_entry->fileid); 02126 fprintf(out_stream, "%*sname = %s\n", indent + 4, " ", p_entry->name); 02127 fprintf(out_stream, "%*scookie = %llu\n", indent + 4, " ", p_entry->cookie); 02128 fprintf(out_stream, "%*s}\n", indent + 2, " "); 02129 02130 p_entry = p_entry->nextentry; 02131 } 02132 02133 /* prinf the eof boolean */ 02134 02135 if(p_dirlist3->eof) 02136 fprintf(out_stream, "%*seof = TRUE\n", indent, " "); 02137 else 02138 fprintf(out_stream, "%*seof = FALSE\n", indent, " "); 02139 02140 return TRUE; 02141 break; 02142 02143 case CMDNFS_ENCODE: 02144 /* never encoded */ 02145 case CMDNFS_FREE: 02146 /* it is never an input (never encoded, never allocated) */ 02147 default: 02148 return FALSE; 02149 } 02150 } 02151 02152 int cmdnfs_READDIR3args(cmdnfs_encodetype_t encodeflag, 02153 int argc, char **argv, 02154 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02155 { 02156 READDIR3args *p_rd3arg = (READDIR3args *) p_nfs_struct; 02157 unsigned long long tmp64; 02158 int rc; 02159 02160 /* sanity check */ 02161 if(p_rd3arg == NULL) 02162 return FALSE; 02163 02164 switch (encodeflag) 02165 { 02166 case CMDNFS_ENCODE: 02167 02168 if(argc != 4) 02169 return FALSE; 02170 02171 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 02172 (caddr_t) & (p_rd3arg->dir)) == FALSE) 02173 { 02174 #ifdef _DEBUG_NFS_SHELL 02175 fprintf(stderr, "dir_handle error.\n"); 02176 #endif 02177 return FALSE; 02178 } 02179 02180 rc = ato64(argv[1], &tmp64); 02181 if(rc) 02182 { 02183 #ifdef _DEBUG_NFS_SHELL 02184 fprintf(stderr, "cookie error.\n"); 02185 #endif 02186 return FALSE; 02187 } 02188 p_rd3arg->cookie = tmp64; 02189 02190 #ifdef _DEBUG_NFS_SHELL 02191 fprintf(stderr, "cookie = %llu.\n", tmp64); 02192 #endif 02193 02194 if(cmdnfs_verf3(CMDNFS_ENCODE, 1, argv + 2, 0, NULL, 02195 (caddr_t) & (p_rd3arg->cookieverf), NULL) == FALSE) 02196 { 02197 #ifdef _DEBUG_NFS_SHELL 02198 fprintf(stderr, "cookieverf error.\n"); 02199 #endif 02200 return FALSE; 02201 } 02202 02203 rc = ato64(argv[3], &tmp64); 02204 if(rc) 02205 { 02206 #ifdef _DEBUG_NFS_SHELL 02207 fprintf(stderr, "count error (not a number).\n"); 02208 #endif 02209 return FALSE; 02210 } 02211 if(tmp64 > (unsigned long long)UINT_MAX) 02212 { 02213 #ifdef _DEBUG_NFS_SHELL 02214 fprintf(stderr, "count error (number too big).\n"); 02215 #endif 02216 return FALSE; 02217 } 02218 02219 p_rd3arg->count = (unsigned int)tmp64; 02220 #ifdef _DEBUG_NFS_SHELL 02221 fprintf(stderr, "count = %u\n", p_rd3arg->count); 02222 #endif 02223 02224 return TRUE; 02225 02226 case CMDNFS_FREE: 02227 02228 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_rd3arg->dir)); 02229 02230 break; 02231 02232 case CMDNFS_DECODE: 02233 /* never decoded */ 02234 default: 02235 return FALSE; 02236 } 02237 return FALSE; 02238 } 02239 02240 #define READDIR3_OK( _p_READDIR3res ) ( (_p_READDIR3res)->READDIR3res_u.resok ) 02241 #define READDIR3_FAIL( _p_READDIR3res ) ( (_p_READDIR3res)->READDIR3res_u.resfail ) 02242 02243 int cmdnfs_READDIR3res(cmdnfs_encodetype_t encodeflag, 02244 int argc, char **argv, 02245 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02246 { 02247 READDIR3res *p_rd3res = (READDIR3res *) p_nfs_struct; 02248 02249 /* sanity check */ 02250 if(p_rd3res == NULL) 02251 return FALSE; 02252 02253 switch (encodeflag) 02254 { 02255 case CMDNFS_DECODE: 02256 02257 fprintf(out_stream, "%*sREADDIR3res =\n", indent, " "); 02258 fprintf(out_stream, "%*s{\n", indent, " "); 02259 02260 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02261 (caddr_t) & p_rd3res->status) == FALSE) 02262 { 02263 return FALSE; 02264 } 02265 02266 if(p_rd3res->status == NFS3_OK) 02267 { 02268 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 02269 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02270 (caddr_t) & (READDIR3_OK(p_rd3res).dir_attributes)) == 02271 FALSE) 02272 { 02273 return FALSE; 02274 } 02275 if(cmdnfs_verf3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02276 (caddr_t) & (READDIR3_OK(p_rd3res).cookieverf), 02277 "cookieverf") == FALSE) 02278 { 02279 return FALSE; 02280 } 02281 02282 if(cmdnfs_dirlist3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02283 (caddr_t) & (READDIR3_OK(p_rd3res).reply)) == FALSE) 02284 { 02285 return FALSE; 02286 } 02287 02288 } 02289 else 02290 { 02291 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 02292 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02293 (caddr_t) & (READDIR3_FAIL(p_rd3res).dir_attributes)) == 02294 FALSE) 02295 { 02296 return FALSE; 02297 } 02298 } 02299 02300 fprintf(out_stream, "%*s}\n", indent, " "); 02301 02302 return TRUE; 02303 02304 break; 02305 02306 case CMDNFS_ENCODE: 02307 /* never encoded */ 02308 case CMDNFS_FREE: 02309 /* it is never an input (never encoded, never allocated) */ 02310 default: 02311 return FALSE; 02312 } 02313 } 02314 02315 #undef READDIR3_OK 02316 #undef READDIR3_FAIL 02317 02318 int cmdnfs_READDIRPLUS3args(cmdnfs_encodetype_t encodeflag, 02319 int argc, char **argv, 02320 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02321 { 02322 READDIRPLUS3args *p_rdp3arg = (READDIRPLUS3args *) p_nfs_struct; 02323 unsigned long long tmp64; 02324 int rc; 02325 02326 /* sanity check */ 02327 if(p_rdp3arg == NULL) 02328 return FALSE; 02329 02330 switch (encodeflag) 02331 { 02332 case CMDNFS_ENCODE: 02333 02334 if(argc != 5) 02335 return FALSE; 02336 02337 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 02338 (caddr_t) & (p_rdp3arg->dir)) == FALSE) 02339 { 02340 #ifdef _DEBUG_NFS_SHELL 02341 fprintf(stderr, "dir_handle error.\n"); 02342 #endif 02343 return FALSE; 02344 } 02345 02346 rc = ato64(argv[1], &tmp64); 02347 if(rc) 02348 { 02349 #ifdef _DEBUG_NFS_SHELL 02350 fprintf(stderr, "cookie error.\n"); 02351 #endif 02352 return FALSE; 02353 } 02354 p_rdp3arg->cookie = tmp64; 02355 02356 #ifdef _DEBUG_NFS_SHELL 02357 fprintf(stderr, "cookie = %llu.\n", tmp64); 02358 #endif 02359 02360 if(cmdnfs_verf3(CMDNFS_ENCODE, 1, argv + 2, 0, NULL, 02361 (caddr_t) & (p_rdp3arg->cookieverf), NULL) == FALSE) 02362 { 02363 #ifdef _DEBUG_NFS_SHELL 02364 fprintf(stderr, "cookieverf error.\n"); 02365 #endif 02366 return FALSE; 02367 } 02368 02369 rc = ato64(argv[3], &tmp64); 02370 if(rc) 02371 { 02372 #ifdef _DEBUG_NFS_SHELL 02373 fprintf(stderr, "dircount error (not a number).\n"); 02374 #endif 02375 return FALSE; 02376 } 02377 if(tmp64 > (unsigned long long)UINT_MAX) 02378 { 02379 #ifdef _DEBUG_NFS_SHELL 02380 fprintf(stderr, "dircount error (number too big).\n"); 02381 #endif 02382 return FALSE; 02383 } 02384 02385 p_rdp3arg->dircount = (unsigned int)tmp64; 02386 #ifdef _DEBUG_NFS_SHELL 02387 fprintf(stderr, "dircount = %u\n", p_rdp3arg->dircount); 02388 #endif 02389 02390 rc = ato64(argv[4], &tmp64); 02391 if(rc) 02392 { 02393 #ifdef _DEBUG_NFS_SHELL 02394 fprintf(stderr, "maxcount error (not a number).\n"); 02395 #endif 02396 return FALSE; 02397 } 02398 if(tmp64 > (unsigned long long)UINT_MAX) 02399 { 02400 #ifdef _DEBUG_NFS_SHELL 02401 fprintf(stderr, "maxcount error (number too big).\n"); 02402 #endif 02403 return FALSE; 02404 } 02405 02406 p_rdp3arg->maxcount = (unsigned int)tmp64; 02407 #ifdef _DEBUG_NFS_SHELL 02408 fprintf(stderr, "maxcount = %u\n", p_rdp3arg->maxcount); 02409 #endif 02410 02411 return TRUE; 02412 02413 case CMDNFS_FREE: 02414 02415 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_rdp3arg->dir)); 02416 02417 break; 02418 02419 case CMDNFS_DECODE: 02420 /* never decoded */ 02421 default: 02422 return FALSE; 02423 } 02424 return FALSE; 02425 } 02426 02427 static int cmdnfs_dirlistplus3(cmdnfs_encodetype_t encodeflag, 02428 int argc, char **argv, 02429 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02430 { 02431 dirlistplus3 *p_dirlistplus3 = (dirlistplus3 *) p_nfs_struct; 02432 02433 entryplus3 *p_entry = NULL; 02434 02435 /* sanity check */ 02436 if(p_dirlistplus3 == NULL) 02437 return FALSE; 02438 02439 switch (encodeflag) 02440 { 02441 case CMDNFS_DECODE: 02442 02443 /* print the list of entries */ 02444 p_entry = p_dirlistplus3->entries; 02445 02446 fprintf(out_stream, "%*sDirEntries:\n", indent, " "); 02447 while(p_entry) 02448 { 02449 fprintf(out_stream, "%*s{\n", indent + 2, " "); 02450 fprintf(out_stream, "%*sfileid = %#llx\n", indent + 4, " ", p_entry->fileid); 02451 fprintf(out_stream, "%*sname = %s\n", indent + 4, " ", p_entry->name); 02452 fprintf(out_stream, "%*scookie = %llu\n", indent + 4, " ", p_entry->cookie); 02453 02454 fprintf(out_stream, "%*sPost-op attributes:\n", indent + 4, " "); 02455 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 6, out_stream, 02456 (caddr_t) & (p_entry->name_attributes)) == FALSE) 02457 { 02458 return FALSE; 02459 } 02460 02461 fprintf(out_stream, "%*sPost-op handle:\n", indent + 4, " "); 02462 if(cmdnfs_postopfh3(CMDNFS_DECODE, 0, NULL, indent + 6, out_stream, 02463 (caddr_t) & (p_entry->name_handle)) == FALSE) 02464 { 02465 return FALSE; 02466 } 02467 02468 fprintf(out_stream, "%*s}\n", indent + 2, " "); 02469 02470 p_entry = p_entry->nextentry; 02471 } 02472 02473 /* prinf the eof boolean */ 02474 02475 if(p_dirlistplus3->eof) 02476 fprintf(out_stream, "%*seof = TRUE\n", indent, " "); 02477 else 02478 fprintf(out_stream, "%*seof = FALSE\n", indent, " "); 02479 02480 return TRUE; 02481 break; 02482 02483 case CMDNFS_ENCODE: 02484 /* never encoded */ 02485 case CMDNFS_FREE: 02486 /* it is never an input (never encoded, never allocated) */ 02487 default: 02488 return FALSE; 02489 } 02490 } 02491 02492 #define READDIRPLUS3_OK( _p_READDIRPLUS3res ) ( (_p_READDIRPLUS3res)->READDIRPLUS3res_u.resok ) 02493 #define READDIRPLUS3_FAIL( _p_READDIRPLUS3res ) ( (_p_READDIRPLUS3res)->READDIRPLUS3res_u.resfail ) 02494 02495 int cmdnfs_READDIRPLUS3res(cmdnfs_encodetype_t encodeflag, 02496 int argc, char **argv, 02497 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02498 { 02499 READDIRPLUS3res *p_rdp3res = (READDIRPLUS3res *) p_nfs_struct; 02500 02501 /* sanity check */ 02502 if(p_rdp3res == NULL) 02503 return FALSE; 02504 02505 switch (encodeflag) 02506 { 02507 case CMDNFS_DECODE: 02508 02509 fprintf(out_stream, "%*sREADDIRPLUS3res =\n", indent, " "); 02510 fprintf(out_stream, "%*s{\n", indent, " "); 02511 02512 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02513 (caddr_t) & p_rdp3res->status) == FALSE) 02514 { 02515 return FALSE; 02516 } 02517 02518 if(p_rdp3res->status == NFS3_OK) 02519 { 02520 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 02521 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02522 (caddr_t) & (READDIRPLUS3_OK(p_rdp3res).dir_attributes)) 02523 == FALSE) 02524 { 02525 return FALSE; 02526 } 02527 if(cmdnfs_verf3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02528 (caddr_t) & (READDIRPLUS3_OK(p_rdp3res).cookieverf), 02529 "cookieverf") == FALSE) 02530 { 02531 return FALSE; 02532 } 02533 02534 if(cmdnfs_dirlistplus3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02535 (caddr_t) & (READDIRPLUS3_OK(p_rdp3res).reply)) == FALSE) 02536 { 02537 return FALSE; 02538 } 02539 02540 } 02541 else 02542 { 02543 fprintf(out_stream, "%*sPost-op attributes (directory):\n", indent + 2, " "); 02544 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02545 (caddr_t) & (READDIRPLUS3_FAIL(p_rdp3res).dir_attributes)) 02546 == FALSE) 02547 { 02548 return FALSE; 02549 } 02550 } 02551 02552 fprintf(out_stream, "%*s}\n", indent, " "); 02553 02554 return TRUE; 02555 02556 break; 02557 02558 case CMDNFS_ENCODE: 02559 /* never encoded */ 02560 case CMDNFS_FREE: 02561 /* it is never an input (never encoded, never allocated) */ 02562 default: 02563 return FALSE; 02564 } 02565 } 02566 02567 #undef READDIRPLUS3_OK 02568 #undef READDIRPLUS3_FAIL 02569 02570 #define READLINK3_OK_ATTRS( _p_READLINK3res ) ( (_p_READLINK3res)->READLINK3res_u.resok.symlink_attributes ) 02571 #define READLINK3_OK_DATA( _p_READLINK3res ) ( (_p_READLINK3res)->READLINK3res_u.resok.data ) 02572 #define READLINK3_FAIL_ATTRS( _p_READLINK3res ) ( (_p_READLINK3res)->READLINK3res_u.resfail.symlink_attributes ) 02573 02574 int cmdnfs_READLINK3res(cmdnfs_encodetype_t encodeflag, 02575 int argc, char **argv, 02576 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02577 { 02578 READLINK3res *p_readlnk3res = (READLINK3res *) p_nfs_struct; 02579 02580 /* sanity check */ 02581 if(p_readlnk3res == NULL) 02582 return FALSE; 02583 02584 switch (encodeflag) 02585 { 02586 case CMDNFS_DECODE: 02587 02588 fprintf(out_stream, "%*sREADLINK3res =\n", indent, " "); 02589 fprintf(out_stream, "%*s{\n", indent, " "); 02590 02591 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02592 (caddr_t) & p_readlnk3res->status) == FALSE) 02593 { 02594 return FALSE; 02595 } 02596 02597 if(p_readlnk3res->status == NFS3_OK) 02598 { 02599 02600 fprintf(out_stream, "%*sPost-op attributes (symlink):\n", indent + 2, " "); 02601 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02602 (caddr_t) & READLINK3_OK_ATTRS(p_readlnk3res)) == FALSE) 02603 { 02604 return FALSE; 02605 } 02606 02607 fprintf(out_stream, "%*sdata = \"%s\"\n", indent + 2, " ", 02608 READLINK3_OK_DATA(p_readlnk3res)); 02609 } 02610 else 02611 { 02612 fprintf(out_stream, "%*sPost-op attributes (symlink):\n", indent + 2, " "); 02613 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02614 (caddr_t) & READLINK3_FAIL_ATTRS(p_readlnk3res)) == FALSE) 02615 { 02616 return FALSE; 02617 } 02618 } 02619 02620 fprintf(out_stream, "%*s}\n", indent, " "); 02621 02622 return TRUE; 02623 02624 break; 02625 02626 case CMDNFS_ENCODE: 02627 /* never encoded */ 02628 case CMDNFS_FREE: 02629 /* it is never an input (never encoded, never allocated) */ 02630 default: 02631 return FALSE; 02632 } 02633 } 02634 02635 #undef READLINK3_OK_ATTRS 02636 #undef READLINK3_OK_DATA 02637 #undef READLINK3_FAIL_ATTRS 02638 02639 #define FSSTAT3_OK( _p_FSSTAT3res ) ( (_p_FSSTAT3res)->FSSTAT3res_u.resok ) 02640 #define FSSTAT3_FAIL_ATTRS( _p_FSSTAT3res ) ( (_p_FSSTAT3res)->FSSTAT3res_u.resfail.obj_attributes ) 02641 02642 int cmdnfs_FSSTAT3res(cmdnfs_encodetype_t encodeflag, 02643 int argc, char **argv, 02644 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02645 { 02646 FSSTAT3res *p_fsstat3res = (FSSTAT3res *) p_nfs_struct; 02647 02648 /* sanity check */ 02649 if(p_fsstat3res == NULL) 02650 return FALSE; 02651 02652 switch (encodeflag) 02653 { 02654 case CMDNFS_DECODE: 02655 02656 fprintf(out_stream, "%*sFSSTAT3res =\n", indent, " "); 02657 fprintf(out_stream, "%*s{\n", indent, " "); 02658 02659 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02660 (caddr_t) & p_fsstat3res->status) == FALSE) 02661 { 02662 return FALSE; 02663 } 02664 02665 if(p_fsstat3res->status == NFS3_OK) 02666 { 02667 02668 fprintf(out_stream, "%*sPost-op attributes (symlink):\n", indent + 2, " "); 02669 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02670 (caddr_t) & (FSSTAT3_OK(p_fsstat3res).obj_attributes)) == 02671 FALSE) 02672 { 02673 return FALSE; 02674 } 02675 fprintf(out_stream, "%*stotal_bytes = %llu\n", indent + 2, " ", 02676 FSSTAT3_OK(p_fsstat3res).tbytes); 02677 fprintf(out_stream, "%*sfree_bytes = %llu\n", indent + 2, " ", 02678 FSSTAT3_OK(p_fsstat3res).fbytes); 02679 fprintf(out_stream, "%*savail_bytes = %llu\n", indent + 2, " ", 02680 FSSTAT3_OK(p_fsstat3res).abytes); 02681 fprintf(out_stream, "%*stotal_files = %llu\n", indent + 2, " ", 02682 FSSTAT3_OK(p_fsstat3res).tfiles); 02683 fprintf(out_stream, "%*sfree_files = %llu\n", indent + 2, " ", 02684 FSSTAT3_OK(p_fsstat3res).ffiles); 02685 fprintf(out_stream, "%*savail_files = %llu\n", indent + 2, " ", 02686 FSSTAT3_OK(p_fsstat3res).afiles); 02687 fprintf(out_stream, "%*sinvar_sec = %u\n", indent + 2, " ", 02688 FSSTAT3_OK(p_fsstat3res).invarsec); 02689 02690 } 02691 else 02692 { 02693 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 02694 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02695 (caddr_t) & FSSTAT3_FAIL_ATTRS(p_fsstat3res)) == FALSE) 02696 { 02697 return FALSE; 02698 } 02699 } 02700 02701 fprintf(out_stream, "%*s}\n", indent, " "); 02702 02703 return TRUE; 02704 02705 break; 02706 02707 case CMDNFS_ENCODE: 02708 /* never encoded */ 02709 case CMDNFS_FREE: 02710 /* it is never an input (never encoded, never allocated) */ 02711 default: 02712 return FALSE; 02713 } 02714 } 02715 02716 #undef FSSTAT3_OK 02717 #undef FSSTAT3_FAIL_ATTRS 02718 02719 int cmdnfs_ACCESS3args(cmdnfs_encodetype_t encodeflag, 02720 int argc, char **argv, 02721 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02722 { 02723 ACCESS3args *p_access3args = (ACCESS3args *) p_nfs_struct; 02724 02725 char *str_access; 02726 /* sanity check */ 02727 if(p_access3args == NULL) 02728 return FALSE; 02729 02730 switch (encodeflag) 02731 { 02732 case CMDNFS_ENCODE: 02733 02734 if(argc != 2) 02735 return FALSE; 02736 02737 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 02738 (caddr_t) & (p_access3args->object)) == FALSE) 02739 { 02740 return FALSE; 02741 } 02742 02743 /* access 2e arg: R(ead) L(ookup) M(odify) E(xtend) D(elete) (e)X(ecute) */ 02744 /* convert a "RLMEDX" string to an NFS access mask. */ 02745 02746 p_access3args->access = 0; 02747 02748 str_access = argv[1]; 02749 while(str_access[0] != '\0') 02750 { 02751 if((str_access[0] == 'r') || (str_access[0] == 'R')) 02752 p_access3args->access |= ACCESS3_READ; 02753 else if((str_access[0] == 'l') || (str_access[0] == 'L')) 02754 p_access3args->access |= ACCESS3_LOOKUP; 02755 else if((str_access[0] == 'm') || (str_access[0] == 'M')) 02756 p_access3args->access |= ACCESS3_MODIFY; 02757 else if((str_access[0] == 'e') || (str_access[0] == 'E')) 02758 p_access3args->access |= ACCESS3_EXTEND; 02759 else if((str_access[0] == 'd') || (str_access[0] == 'D')) 02760 p_access3args->access |= ACCESS3_DELETE; 02761 else if((str_access[0] == 'x') || (str_access[0] == 'X')) 02762 p_access3args->access |= ACCESS3_EXECUTE; 02763 else 02764 { 02765 #ifdef _DEBUG_NFS_SHELL 02766 fprintf(stderr, "access flag error: unknown flag \"%c\".\n", str_access[0]); 02767 #endif 02768 return FALSE; 02769 } 02770 02771 str_access++; 02772 } 02773 02774 return TRUE; 02775 02776 case CMDNFS_FREE: 02777 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_access3args->object)); 02778 return TRUE; 02779 break; 02780 02781 case CMDNFS_DECODE: 02782 /* never decoded */ 02783 default: 02784 return FALSE; 02785 } 02786 } 02787 02788 #define ACCESS3_OK_ATTRS( _p_ACCESS3res ) ( (_p_ACCESS3res)->ACCESS3res_u.resok.obj_attributes ) 02789 #define ACCESS3_OK_ACCESS( _p_ACCESS3res ) ( (_p_ACCESS3res)->ACCESS3res_u.resok.access ) 02790 #define ACCESS3_FAIL_ATTRS( _p_ACCESS3res ) ( (_p_ACCESS3res)->ACCESS3res_u.resfail.obj_attributes ) 02791 02792 int cmdnfs_ACCESS3res(cmdnfs_encodetype_t encodeflag, 02793 int argc, char **argv, 02794 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02795 { 02796 ACCESS3res *p_access3res = (ACCESS3res *) p_nfs_struct; 02797 02798 /* sanity check */ 02799 if(p_access3res == NULL) 02800 return FALSE; 02801 02802 switch (encodeflag) 02803 { 02804 case CMDNFS_DECODE: 02805 02806 fprintf(out_stream, "%*sACCESS3res =\n", indent, " "); 02807 fprintf(out_stream, "%*s{\n", indent, " "); 02808 02809 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 02810 (caddr_t) & p_access3res->status) == FALSE) 02811 { 02812 return FALSE; 02813 } 02814 02815 if(p_access3res->status == NFS3_OK) 02816 { 02817 02818 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 02819 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02820 (caddr_t) & ACCESS3_OK_ATTRS(p_access3res)) == FALSE) 02821 { 02822 return FALSE; 02823 } 02824 02825 /* print acces rights */ 02826 fprintf(out_stream, "%*saccess =", indent + 2, " "); 02827 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_READ) 02828 fprintf(out_stream, " READ"); 02829 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_LOOKUP) 02830 fprintf(out_stream, " LOOKUP"); 02831 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_MODIFY) 02832 fprintf(out_stream, " MODIFY"); 02833 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_EXTEND) 02834 fprintf(out_stream, " EXTEND"); 02835 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_DELETE) 02836 fprintf(out_stream, " DELETE"); 02837 if(ACCESS3_OK_ACCESS(p_access3res) & ACCESS3_EXECUTE) 02838 fprintf(out_stream, " EXECUTE"); 02839 fprintf(out_stream, " (%#.4x)\n", ACCESS3_OK_ACCESS(p_access3res)); 02840 02841 } 02842 else 02843 { 02844 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 02845 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 02846 (caddr_t) & ACCESS3_FAIL_ATTRS(p_access3res)) == FALSE) 02847 { 02848 return FALSE; 02849 } 02850 } 02851 02852 fprintf(out_stream, "%*s}\n", indent, " "); 02853 02854 return TRUE; 02855 02856 break; 02857 02858 case CMDNFS_ENCODE: 02859 /* never encoded */ 02860 case CMDNFS_FREE: 02861 /* it is never an input (never encoded, never allocated) */ 02862 default: 02863 return FALSE; 02864 } 02865 } 02866 02867 #undef ACCESS3_OK_ATTRS 02868 #undef ACCESS3_OK_ACCESS 02869 #undef ACCESS3_FAIL_ATTRS 02870 02871 int cmdnfs_CREATE3args(cmdnfs_encodetype_t encodeflag, 02872 int argc, char **argv, 02873 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02874 { 02875 CREATE3args *p_CREATE3args = (CREATE3args *) p_nfs_struct; 02876 char *str_mode; 02877 02878 /* sanity check */ 02879 if(p_CREATE3args == NULL) 02880 return FALSE; 02881 02882 switch (encodeflag) 02883 { 02884 case CMDNFS_ENCODE: 02885 02886 if((argc != 3) && (argc != 4)) 02887 return FALSE; 02888 02889 /* The first two args */ 02890 if(cmdnfs_diropargs3(CMDNFS_ENCODE, 2, argv, 0, NULL, 02891 (caddr_t) & (p_CREATE3args->where)) == FALSE) 02892 { 02893 return FALSE; 02894 } 02895 02896 /* CREATE 3e arg: UNCHECKED, GUARDED or EXCLUSIVE */ 02897 02898 str_mode = argv[2]; 02899 if(!strcasecmp(str_mode, "UNCHECKED")) 02900 p_CREATE3args->how.mode = UNCHECKED; 02901 else if(!strcasecmp(str_mode, "GUARDED")) 02902 p_CREATE3args->how.mode = GUARDED; 02903 else if(!strcasecmp(str_mode, "EXCLUSIVE")) 02904 p_CREATE3args->how.mode = EXCLUSIVE; 02905 else 02906 return FALSE; 02907 02908 /* CREATE 4th arg: sattr3 list or a create verifier */ 02909 02910 switch (p_CREATE3args->how.mode) 02911 { 02912 case UNCHECKED: 02913 case GUARDED: 02914 02915 /* The optional 4th arg is a sattr3 list */ 02916 if(cmdnfs_sattr3(CMDNFS_ENCODE, argc - 3, argv + 3, 0, NULL, 02917 (caddr_t) & (p_CREATE3args->how.createhow3_u.obj_attributes)) 02918 == FALSE) 02919 { 02920 return FALSE; 02921 } 02922 02923 break; 02924 case EXCLUSIVE: 02925 02926 /* The mandatory 4rd arg is a create verifier */ 02927 if(cmdnfs_verf3(CMDNFS_ENCODE, argc - 3, argv + 3, 0, NULL, 02928 (caddr_t) & (p_CREATE3args->how.createhow3_u.verf), 02929 NULL) == FALSE) 02930 { 02931 return FALSE; 02932 } 02933 02934 break; 02935 } 02936 02937 return TRUE; 02938 02939 case CMDNFS_FREE: 02940 02941 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, 02942 (caddr_t) & (p_CREATE3args->where)); 02943 02944 switch (p_CREATE3args->how.mode) 02945 { 02946 case UNCHECKED: 02947 case GUARDED: 02948 cmdnfs_sattr3(CMDNFS_FREE, 0, NULL, 0, NULL, 02949 (caddr_t) & (p_CREATE3args->how.createhow3_u.obj_attributes)); 02950 break; 02951 02952 case EXCLUSIVE: 02953 cmdnfs_verf3(CMDNFS_FREE, 0, NULL, 0, NULL, 02954 (caddr_t) & (p_CREATE3args->how.createhow3_u.verf), NULL); 02955 break; 02956 } 02957 02958 return TRUE; 02959 break; 02960 02961 case CMDNFS_DECODE: 02962 /* never decoded */ 02963 default: 02964 return FALSE; 02965 } 02966 } 02967 02968 int cmdnfs_preopattr(cmdnfs_encodetype_t encodeflag, 02969 int argc, char **argv, 02970 int indent, FILE * out_stream, caddr_t p_nfs_struct) 02971 { 02972 pre_op_attr *p_opattr = (pre_op_attr *) p_nfs_struct; 02973 wcc_attr *p_wccattr; 02974 char tmp_buff[256]; 02975 struct tm paramtm; 02976 /* sanity check */ 02977 if(p_opattr == NULL) 02978 return FALSE; 02979 02980 switch (encodeflag) 02981 { 02982 case CMDNFS_DECODE: 02983 02984 if(p_opattr->attributes_follow) 02985 { 02986 p_wccattr = &(p_opattr->pre_op_attr_u.attributes); 02987 02988 fprintf(out_stream, "%*s{\n", indent, " "); 02989 02990 fprintf(out_stream, "%*ssize = %llu\n", indent + 2, " ", p_wccattr->size); 02991 02992 strftime(tmp_buff, 256, "%Y-%m-%d %T", 02993 Localtime_r((time_t *) & p_wccattr->mtime.seconds, ¶mtm)); 02994 fprintf(out_stream, "%*smtime = %u.%.9u (%s)\n", indent + 2, " ", 02995 p_wccattr->mtime.seconds, p_wccattr->mtime.nseconds, tmp_buff); 02996 02997 strftime(tmp_buff, 256, "%Y-%m-%d %T", 02998 Localtime_r((time_t *) & p_wccattr->ctime.seconds, ¶mtm)); 02999 fprintf(out_stream, "%*sctime = %u.%.9u (%s)\n", indent + 2, " ", 03000 p_wccattr->ctime.seconds, p_wccattr->ctime.nseconds, tmp_buff); 03001 03002 fprintf(out_stream, "%*s}\n", indent, " "); 03003 } 03004 else 03005 { 03006 fprintf(out_stream, "%*sN/A\n", indent, " "); 03007 return TRUE; 03008 } 03009 03010 break; 03011 03012 case CMDNFS_ENCODE: 03013 /* never encoded */ 03014 case CMDNFS_FREE: 03015 /* it is never an input (never encoded, never allocated) */ 03016 default: 03017 return FALSE; 03018 } 03019 return FALSE; 03020 } 03021 03022 int cmdnfs_wccdata(cmdnfs_encodetype_t encodeflag, 03023 int argc, char **argv, 03024 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03025 { 03026 wcc_data *p_wccdata = (wcc_data *) p_nfs_struct; 03027 /* sanity check */ 03028 03029 if(p_wccdata == NULL) 03030 return FALSE; 03031 03032 switch (encodeflag) 03033 { 03034 case CMDNFS_DECODE: 03035 03036 fprintf(out_stream, "%*swcc_before:\n", indent, " "); 03037 if(cmdnfs_preopattr(CMDNFS_DECODE, 0, NULL, indent, out_stream, 03038 (caddr_t) & (p_wccdata->before)) == FALSE) 03039 return FALSE; 03040 03041 fprintf(out_stream, "%*swcc_after:\n", indent, " "); 03042 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent, out_stream, 03043 (caddr_t) & (p_wccdata->after)) == FALSE) 03044 return FALSE; 03045 03046 return TRUE; 03047 break; 03048 03049 case CMDNFS_ENCODE: 03050 /* never encoded */ 03051 case CMDNFS_FREE: 03052 /* it is never an input (never encoded, never allocated) */ 03053 default: 03054 return FALSE; 03055 } 03056 } 03057 03058 #define CREATE3_OK_FH( _p_CREATE3res ) ( (_p_CREATE3res)->CREATE3res_u.resok.obj ) 03059 #define CREATE3_OK_ATTRS( _p_CREATE3res ) ( (_p_CREATE3res)->CREATE3res_u.resok.obj_attributes ) 03060 #define CREATE3_OK_WCC( _p_CREATE3res ) ( (_p_CREATE3res)->CREATE3res_u.resok.dir_wcc ) 03061 #define CREATE3_FAIL_WCC( _p_CREATE3res ) ( (_p_CREATE3res)->CREATE3res_u.resfail.dir_wcc ) 03062 03063 int cmdnfs_CREATE3res(cmdnfs_encodetype_t encodeflag, 03064 int argc, char **argv, 03065 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03066 { 03067 03068 CREATE3res *p_CREATE3res = (CREATE3res *) p_nfs_struct; 03069 03070 /* sanity check */ 03071 if(p_CREATE3res == NULL) 03072 return FALSE; 03073 03074 switch (encodeflag) 03075 { 03076 case CMDNFS_DECODE: 03077 03078 fprintf(out_stream, "%*sCREATE3res =\n", indent, " "); 03079 fprintf(out_stream, "%*s{\n", indent, " "); 03080 03081 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03082 (caddr_t) & p_CREATE3res->status) == FALSE) 03083 { 03084 return FALSE; 03085 } 03086 03087 if(p_CREATE3res->status == NFS3_OK) 03088 { 03089 03090 if(cmdnfs_postopfh3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03091 (caddr_t) & CREATE3_OK_FH(p_CREATE3res)) == FALSE) 03092 { 03093 return FALSE; 03094 } 03095 03096 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 03097 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03098 (caddr_t) & CREATE3_OK_ATTRS(p_CREATE3res)) == FALSE) 03099 { 03100 return FALSE; 03101 } 03102 03103 fprintf(out_stream, "%*sWcc_data (directory):\n", indent + 2, " "); 03104 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03105 (caddr_t) & CREATE3_OK_WCC(p_CREATE3res)) == FALSE) 03106 { 03107 return FALSE; 03108 } 03109 03110 } 03111 else 03112 { 03113 fprintf(out_stream, "%*sWcc_data (directory):\n", indent + 2, " "); 03114 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03115 (caddr_t) & CREATE3_FAIL_WCC(p_CREATE3res)) == FALSE) 03116 { 03117 return FALSE; 03118 } 03119 } 03120 03121 fprintf(out_stream, "%*s}\n", indent, " "); 03122 03123 return TRUE; 03124 03125 break; 03126 03127 case CMDNFS_ENCODE: 03128 /* never encoded */ 03129 case CMDNFS_FREE: 03130 /* it is never an input (never encoded, never allocated) */ 03131 default: 03132 return FALSE; 03133 } 03134 03135 } 03136 03137 #undef CREATE3_OK_FH 03138 #undef CREATE3_OK_ATTRS 03139 #undef CREATE3_OK_WCC 03140 #undef CREATE3_FAIL_WCC 03141 03142 int cmdnfs_MKDIR3args(cmdnfs_encodetype_t encodeflag, 03143 int argc, char **argv, 03144 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03145 { 03146 MKDIR3args *p_MKDIR3args = (MKDIR3args *) p_nfs_struct; 03147 03148 /* sanity check */ 03149 if(p_MKDIR3args == NULL) 03150 return FALSE; 03151 03152 switch (encodeflag) 03153 { 03154 case CMDNFS_ENCODE: 03155 03156 if((argc != 2) && (argc != 3)) 03157 return FALSE; 03158 03159 /* The first two args */ 03160 if(cmdnfs_diropargs3(CMDNFS_ENCODE, 2, argv, 0, NULL, 03161 (caddr_t) & (p_MKDIR3args->where)) == FALSE) 03162 { 03163 return FALSE; 03164 } 03165 03166 /* MKDIR 3th arg: sattr3 list or a MKDIR verifier */ 03167 03168 if(argc == 3) 03169 { 03170 /* The 3th arg is a sattr3 list */ 03171 if(cmdnfs_sattr3(CMDNFS_ENCODE, 1, argv + 2, 0, NULL, 03172 (caddr_t) & (p_MKDIR3args->attributes)) == FALSE) 03173 { 03174 return FALSE; 03175 } 03176 } 03177 else 03178 { 03179 /* the sattr3 strucure is empty */ 03180 if(cmdnfs_sattr3(CMDNFS_ENCODE, 0, NULL, 0, NULL, 03181 (caddr_t) & (p_MKDIR3args->attributes)) == FALSE) 03182 { 03183 return FALSE; 03184 } 03185 } 03186 03187 return TRUE; 03188 03189 case CMDNFS_FREE: 03190 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_MKDIR3args->where)); 03191 cmdnfs_sattr3(CMDNFS_FREE, 0, NULL, 0, NULL, 03192 (caddr_t) & (p_MKDIR3args->attributes)); 03193 return TRUE; 03194 break; 03195 03196 case CMDNFS_DECODE: 03197 /* never decoded */ 03198 default: 03199 return FALSE; 03200 } 03201 } 03202 03203 #define MKDIR3_OK_FH( _p_MKDIR3res ) ( (_p_MKDIR3res)->MKDIR3res_u.resok.obj ) 03204 #define MKDIR3_OK_ATTRS( _p_MKDIR3res ) ( (_p_MKDIR3res)->MKDIR3res_u.resok.obj_attributes ) 03205 #define MKDIR3_OK_WCC( _p_MKDIR3res ) ( (_p_MKDIR3res)->MKDIR3res_u.resok.dir_wcc ) 03206 #define MKDIR3_FAIL_WCC( _p_MKDIR3res ) ( (_p_MKDIR3res)->MKDIR3res_u.resfail.dir_wcc ) 03207 03208 int cmdnfs_MKDIR3res(cmdnfs_encodetype_t encodeflag, 03209 int argc, char **argv, 03210 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03211 { 03212 03213 MKDIR3res *p_MKDIR3res = (MKDIR3res *) p_nfs_struct; 03214 03215 /* sanity check */ 03216 if(p_MKDIR3res == NULL) 03217 return FALSE; 03218 03219 switch (encodeflag) 03220 { 03221 case CMDNFS_DECODE: 03222 03223 fprintf(out_stream, "%*sMKDIR3res =\n", indent, " "); 03224 fprintf(out_stream, "%*s{\n", indent, " "); 03225 03226 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03227 (caddr_t) & p_MKDIR3res->status) == FALSE) 03228 { 03229 return FALSE; 03230 } 03231 03232 if(p_MKDIR3res->status == NFS3_OK) 03233 { 03234 03235 if(cmdnfs_postopfh3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03236 (caddr_t) & MKDIR3_OK_FH(p_MKDIR3res)) == FALSE) 03237 { 03238 return FALSE; 03239 } 03240 03241 fprintf(out_stream, "%*sPost-op attributes (new dir):\n", indent + 2, " "); 03242 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03243 (caddr_t) & MKDIR3_OK_ATTRS(p_MKDIR3res)) == FALSE) 03244 { 03245 return FALSE; 03246 } 03247 03248 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03249 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03250 (caddr_t) & MKDIR3_OK_WCC(p_MKDIR3res)) == FALSE) 03251 { 03252 return FALSE; 03253 } 03254 03255 } 03256 else 03257 { 03258 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03259 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03260 (caddr_t) & MKDIR3_FAIL_WCC(p_MKDIR3res)) == FALSE) 03261 { 03262 return FALSE; 03263 } 03264 } 03265 03266 fprintf(out_stream, "%*s}\n", indent, " "); 03267 03268 return TRUE; 03269 03270 break; 03271 03272 case CMDNFS_ENCODE: 03273 /* never encoded */ 03274 case CMDNFS_FREE: 03275 /* it is never an input (never encoded, never allocated) */ 03276 default: 03277 return FALSE; 03278 } 03279 03280 } 03281 03282 #undef MKDIR3_OK_FH 03283 #undef MKDIR3_OK_ATTRS 03284 #undef MKDIR3_OK_WCC 03285 #undef MKDIR3_FAIL_WCC 03286 03287 #define REMOVE3_OK_WCC( _p_REMOVE3res ) ( (_p_REMOVE3res)->REMOVE3res_u.resok.dir_wcc ) 03288 #define REMOVE3_FAIL_WCC( _p_REMOVE3res ) ( (_p_REMOVE3res)->REMOVE3res_u.resfail.dir_wcc ) 03289 03290 int cmdnfs_REMOVE3res(cmdnfs_encodetype_t encodeflag, 03291 int argc, char **argv, 03292 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03293 { 03294 03295 REMOVE3res *p_REMOVE3res = (REMOVE3res *) p_nfs_struct; 03296 03297 /* sanity check */ 03298 if(p_REMOVE3res == NULL) 03299 return FALSE; 03300 03301 switch (encodeflag) 03302 { 03303 case CMDNFS_DECODE: 03304 03305 fprintf(out_stream, "%*sREMOVE3res =\n", indent, " "); 03306 fprintf(out_stream, "%*s{\n", indent, " "); 03307 03308 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03309 (caddr_t) & p_REMOVE3res->status) == FALSE) 03310 { 03311 return FALSE; 03312 } 03313 03314 if(p_REMOVE3res->status == NFS3_OK) 03315 { 03316 03317 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03318 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03319 (caddr_t) & REMOVE3_OK_WCC(p_REMOVE3res)) == FALSE) 03320 { 03321 return FALSE; 03322 } 03323 03324 } 03325 else 03326 { 03327 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03328 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03329 (caddr_t) & REMOVE3_FAIL_WCC(p_REMOVE3res)) == FALSE) 03330 { 03331 return FALSE; 03332 } 03333 } 03334 03335 fprintf(out_stream, "%*s}\n", indent, " "); 03336 03337 return TRUE; 03338 03339 break; 03340 03341 case CMDNFS_ENCODE: 03342 /* never encoded */ 03343 case CMDNFS_FREE: 03344 /* it is never an input (never encoded, never allocated) */ 03345 default: 03346 return FALSE; 03347 } 03348 03349 } 03350 03351 #undef REMOVE3_OK_WCC 03352 #undef REMOVE3_FAIL_WCC 03353 03354 #define RMDIR3_OK_WCC( _p_RMDIR3res ) ( (_p_RMDIR3res)->RMDIR3res_u.resok.dir_wcc ) 03355 #define RMDIR3_FAIL_WCC( _p_RMDIR3res ) ( (_p_RMDIR3res)->RMDIR3res_u.resfail.dir_wcc ) 03356 03357 int cmdnfs_RMDIR3res(cmdnfs_encodetype_t encodeflag, 03358 int argc, char **argv, 03359 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03360 { 03361 03362 RMDIR3res *p_RMDIR3res = (RMDIR3res *) p_nfs_struct; 03363 03364 /* sanity check */ 03365 if(p_RMDIR3res == NULL) 03366 return FALSE; 03367 03368 switch (encodeflag) 03369 { 03370 case CMDNFS_DECODE: 03371 03372 fprintf(out_stream, "%*sRMDIR3res =\n", indent, " "); 03373 fprintf(out_stream, "%*s{\n", indent, " "); 03374 03375 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03376 (caddr_t) & p_RMDIR3res->status) == FALSE) 03377 { 03378 return FALSE; 03379 } 03380 03381 if(p_RMDIR3res->status == NFS3_OK) 03382 { 03383 03384 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03385 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03386 (caddr_t) & RMDIR3_OK_WCC(p_RMDIR3res)) == FALSE) 03387 { 03388 return FALSE; 03389 } 03390 03391 } 03392 else 03393 { 03394 fprintf(out_stream, "%*sWcc_data (parent dir):\n", indent + 2, " "); 03395 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03396 (caddr_t) & RMDIR3_FAIL_WCC(p_RMDIR3res)) == FALSE) 03397 { 03398 return FALSE; 03399 } 03400 } 03401 03402 fprintf(out_stream, "%*s}\n", indent, " "); 03403 03404 return TRUE; 03405 03406 break; 03407 03408 case CMDNFS_ENCODE: 03409 /* never encoded */ 03410 case CMDNFS_FREE: 03411 /* it is never an input (never encoded, never allocated) */ 03412 default: 03413 return FALSE; 03414 } 03415 03416 } 03417 03418 #undef RMDIR3_OK_WCC 03419 #undef RMDIR3_FAIL_WCC 03420 03421 int cmdnfs_sattrguard3(cmdnfs_encodetype_t encodeflag, 03422 int argc, char **argv, 03423 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03424 { 03425 sattrguard3 *p_sattr = (sattrguard3 *) p_nfs_struct; 03426 03427 time_t c_sec; 03428 int c_nsec; 03429 char *nsec_str = NULL; 03430 char *time_str; 03431 03432 /* sanity check */ 03433 if(p_sattr == NULL) 03434 return FALSE; 03435 03436 switch (encodeflag) 03437 { 03438 case CMDNFS_ENCODE: 03439 03440 /* inits structure */ 03441 memset((caddr_t) p_sattr, 0, sizeof(sattrguard3)); 03442 03443 if(argc == 0) 03444 { 03445 /* empty structure */ 03446 p_sattr->check = FALSE; 03447 return TRUE; 03448 } 03449 03450 /* at this point it must not be more than one string */ 03451 if(argc != 1) 03452 return FALSE; 03453 03454 time_str = strtok_r(argv[0], ".", &nsec_str); 03455 03456 c_sec = atotime(time_str); 03457 if(c_sec == ((time_t) - 1)) 03458 return FALSE; 03459 03460 if(nsec_str == NULL) 03461 { 03462 c_nsec = 0; 03463 } 03464 else 03465 { 03466 c_nsec = my_atoi(nsec_str); 03467 if((c_nsec < 0) || (c_nsec > 999999999)) 03468 return FALSE; 03469 } 03470 03471 p_sattr->check = TRUE; 03472 p_sattr->sattrguard3_u.obj_ctime.seconds = c_sec; 03473 p_sattr->sattrguard3_u.obj_ctime.nseconds = c_nsec; 03474 03475 #ifdef _DEBUG_NFS_SHELL 03476 printf("ctime check = %u.%.9u\n", p_sattr->sattrguard3_u.obj_ctime.seconds, 03477 p_sattr->sattrguard3_u.obj_ctime.nseconds); 03478 #endif 03479 03480 return TRUE; 03481 break; 03482 case CMDNFS_FREE: 03483 /* nothing to do */ 03484 return TRUE; 03485 break; 03486 03487 case CMDNFS_DECODE: 03488 /* never decoded */ 03489 default: 03490 return FALSE; 03491 } 03492 03493 } /* cmdnfs_sattrguard3 */ 03494 03495 int cmdnfs_SETATTR3args(cmdnfs_encodetype_t encodeflag, 03496 int argc, char **argv, 03497 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03498 { 03499 SETATTR3args *p_SETATTR3args = (SETATTR3args *) p_nfs_struct; 03500 03501 /* sanity check */ 03502 if(p_SETATTR3args == NULL) 03503 return FALSE; 03504 03505 switch (encodeflag) 03506 { 03507 case CMDNFS_ENCODE: 03508 03509 if((argc != 2) && (argc != 3)) 03510 return FALSE; 03511 03512 /* The first arg */ 03513 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 03514 (caddr_t) & (p_SETATTR3args->object)) == FALSE) 03515 { 03516 return FALSE; 03517 } 03518 03519 /* SETATTR 2th arg: sattr3 list */ 03520 03521 if(cmdnfs_sattr3(CMDNFS_ENCODE, 1, argv + 1, 0, NULL, 03522 (caddr_t) & (p_SETATTR3args->new_attributes)) == FALSE) 03523 { 03524 return FALSE; 03525 } 03526 03527 /* SETATTR optionnal 3th arg: sattrguard3 */ 03528 03529 if(cmdnfs_sattrguard3(CMDNFS_ENCODE, argc - 2, argv + 2, 0, NULL, 03530 (caddr_t) & (p_SETATTR3args->guard)) == FALSE) 03531 { 03532 return FALSE; 03533 } 03534 03535 return TRUE; 03536 03537 case CMDNFS_FREE: 03538 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, 03539 (caddr_t) & (p_SETATTR3args->object)); 03540 cmdnfs_sattr3(CMDNFS_FREE, 0, NULL, 0, NULL, 03541 (caddr_t) & (p_SETATTR3args->new_attributes)); 03542 return TRUE; 03543 break; 03544 03545 case CMDNFS_DECODE: 03546 /* never decoded */ 03547 default: 03548 return FALSE; 03549 } 03550 } 03551 03552 #define SETATTR3_OK_WCC( _p_SETATTR3res ) ( (_p_SETATTR3res)->SETATTR3res_u.resok.obj_wcc ) 03553 #define SETATTR3_FAIL_WCC( _p_SETATTR3res ) ( (_p_SETATTR3res)->SETATTR3res_u.resfail.obj_wcc ) 03554 03555 int cmdnfs_SETATTR3res(cmdnfs_encodetype_t encodeflag, 03556 int argc, char **argv, 03557 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03558 { 03559 03560 SETATTR3res *p_SETATTR3res = (SETATTR3res *) p_nfs_struct; 03561 03562 /* sanity check */ 03563 if(p_SETATTR3res == NULL) 03564 return FALSE; 03565 03566 switch (encodeflag) 03567 { 03568 case CMDNFS_DECODE: 03569 03570 fprintf(out_stream, "%*sSETATTR3res =\n", indent, " "); 03571 fprintf(out_stream, "%*s{\n", indent, " "); 03572 03573 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03574 (caddr_t) & p_SETATTR3res->status) == FALSE) 03575 { 03576 return FALSE; 03577 } 03578 03579 if(p_SETATTR3res->status == NFS3_OK) 03580 { 03581 03582 fprintf(out_stream, "%*sWcc_data (object):\n", indent + 2, " "); 03583 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03584 (caddr_t) & SETATTR3_OK_WCC(p_SETATTR3res)) == FALSE) 03585 { 03586 return FALSE; 03587 } 03588 03589 } 03590 else 03591 { 03592 fprintf(out_stream, "%*sWcc_data (object):\n", indent + 2, " "); 03593 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03594 (caddr_t) & SETATTR3_FAIL_WCC(p_SETATTR3res)) == FALSE) 03595 { 03596 return FALSE; 03597 } 03598 } 03599 03600 fprintf(out_stream, "%*s}\n", indent, " "); 03601 03602 return TRUE; 03603 03604 break; 03605 03606 case CMDNFS_ENCODE: 03607 /* never encoded */ 03608 case CMDNFS_FREE: 03609 /* it is never an input (never encoded, never allocated) */ 03610 default: 03611 return FALSE; 03612 } 03613 03614 } 03615 03616 #undef SETATTR3_OK_WCC 03617 #undef SETATTR3_FAIL_WCC 03618 03619 int cmdnfs_RENAME3args(cmdnfs_encodetype_t encodeflag, 03620 int argc, char **argv, 03621 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03622 { 03623 RENAME3args *p_RENAME3args = (RENAME3args *) p_nfs_struct; 03624 03625 /* sanity check */ 03626 if(p_RENAME3args == NULL) 03627 return FALSE; 03628 03629 switch (encodeflag) 03630 { 03631 case CMDNFS_ENCODE: 03632 03633 if(argc != 4) 03634 return FALSE; 03635 03636 /* The first 2 args */ 03637 if(cmdnfs_diropargs3(CMDNFS_ENCODE, 2, argv, 0, NULL, 03638 (caddr_t) & (p_RENAME3args->from)) == FALSE) 03639 { 03640 return FALSE; 03641 } 03642 03643 /* The last 2 args */ 03644 if(cmdnfs_diropargs3(CMDNFS_ENCODE, argc - 2, argv + 2, 0, NULL, 03645 (caddr_t) & (p_RENAME3args->to)) == FALSE) 03646 { 03647 return FALSE; 03648 } 03649 03650 return TRUE; 03651 03652 case CMDNFS_FREE: 03653 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_RENAME3args->from)); 03654 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_RENAME3args->to)); 03655 return TRUE; 03656 break; 03657 03658 case CMDNFS_DECODE: 03659 /* never decoded */ 03660 default: 03661 return FALSE; 03662 } 03663 } 03664 03665 #define RENAME3_OK_FROMWCC( _p_RENAME3res ) ( (_p_RENAME3res)->RENAME3res_u.resok.fromdir_wcc ) 03666 #define RENAME3_OK_TOWCC( _p_RENAME3res ) ( (_p_RENAME3res)->RENAME3res_u.resok.todir_wcc ) 03667 #define RENAME3_FAIL_FROMWCC( _p_RENAME3res ) ( (_p_RENAME3res)->RENAME3res_u.resfail.fromdir_wcc ) 03668 #define RENAME3_FAIL_TOWCC( _p_RENAME3res ) ( (_p_RENAME3res)->RENAME3res_u.resfail.todir_wcc ) 03669 03670 int cmdnfs_RENAME3res(cmdnfs_encodetype_t encodeflag, 03671 int argc, char **argv, 03672 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03673 { 03674 03675 RENAME3res *p_RENAME3res = (RENAME3res *) p_nfs_struct; 03676 03677 /* sanity check */ 03678 if(p_RENAME3res == NULL) 03679 return FALSE; 03680 03681 switch (encodeflag) 03682 { 03683 case CMDNFS_DECODE: 03684 03685 fprintf(out_stream, "%*sRENAME3res =\n", indent, " "); 03686 fprintf(out_stream, "%*s{\n", indent, " "); 03687 03688 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03689 (caddr_t) & p_RENAME3res->status) == FALSE) 03690 { 03691 return FALSE; 03692 } 03693 03694 if(p_RENAME3res->status == NFS3_OK) 03695 { 03696 03697 fprintf(out_stream, "%*sWcc_data (source directory):\n", indent + 2, " "); 03698 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03699 (caddr_t) & RENAME3_OK_FROMWCC(p_RENAME3res)) == FALSE) 03700 { 03701 return FALSE; 03702 } 03703 fprintf(out_stream, "%*sWcc_data (target directory):\n", indent + 2, " "); 03704 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03705 (caddr_t) & RENAME3_OK_TOWCC(p_RENAME3res)) == FALSE) 03706 { 03707 return FALSE; 03708 } 03709 03710 } 03711 else 03712 { 03713 fprintf(out_stream, "%*sWcc_data (source directory):\n", indent + 2, " "); 03714 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03715 (caddr_t) & RENAME3_FAIL_FROMWCC(p_RENAME3res)) == FALSE) 03716 { 03717 return FALSE; 03718 } 03719 fprintf(out_stream, "%*sWcc_data (target directory):\n", indent + 2, " "); 03720 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03721 (caddr_t) & RENAME3_FAIL_TOWCC(p_RENAME3res)) == FALSE) 03722 { 03723 return FALSE; 03724 } 03725 } 03726 03727 fprintf(out_stream, "%*s}\n", indent, " "); 03728 03729 return TRUE; 03730 03731 break; 03732 03733 case CMDNFS_ENCODE: 03734 /* never encoded */ 03735 case CMDNFS_FREE: 03736 /* it is never an input (never encoded, never allocated) */ 03737 default: 03738 return FALSE; 03739 } 03740 03741 } 03742 03743 #undef RENAME3_OK_FROMWCC 03744 #undef RENAME3_OK_TOWCC 03745 #undef RENAME3_FAIL_FROMWCC 03746 #undef RENAME3_FAIL_TOWCC 03747 03748 int cmdnfs_LINK3args(cmdnfs_encodetype_t encodeflag, 03749 int argc, char **argv, 03750 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03751 { 03752 LINK3args *p_LINK3args = (LINK3args *) p_nfs_struct; 03753 03754 /* sanity check */ 03755 if(p_LINK3args == NULL) 03756 return FALSE; 03757 03758 switch (encodeflag) 03759 { 03760 case CMDNFS_ENCODE: 03761 03762 if(argc != 3) 03763 return FALSE; 03764 03765 /* The first arg */ 03766 if(cmdnfs_fhandle3(CMDNFS_ENCODE, 1, argv, 0, NULL, 03767 (caddr_t) & (p_LINK3args->file)) == FALSE) 03768 { 03769 return FALSE; 03770 } 03771 03772 /* The last 2 args */ 03773 if(cmdnfs_diropargs3(CMDNFS_ENCODE, argc - 1, argv + 1, 0, NULL, 03774 (caddr_t) & (p_LINK3args->link)) == FALSE) 03775 { 03776 return FALSE; 03777 } 03778 03779 return TRUE; 03780 03781 case CMDNFS_FREE: 03782 cmdnfs_fhandle3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_LINK3args->file)); 03783 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, (caddr_t) & (p_LINK3args->link)); 03784 return TRUE; 03785 break; 03786 03787 case CMDNFS_DECODE: 03788 /* never decoded */ 03789 default: 03790 return FALSE; 03791 } 03792 } 03793 03794 #define LINK3_OK_ATTRS( _p_LINK3res ) ( (_p_LINK3res)->LINK3res_u.resok.file_attributes ) 03795 #define LINK3_OK_WCC( _p_LINK3res ) ( (_p_LINK3res)->LINK3res_u.resok.linkdir_wcc ) 03796 #define LINK3_FAIL_ATTRS( _p_LINK3res ) ( (_p_LINK3res)->LINK3res_u.resfail.file_attributes ) 03797 #define LINK3_FAIL_WCC( _p_LINK3res ) ( (_p_LINK3res)->LINK3res_u.resfail.linkdir_wcc ) 03798 03799 int cmdnfs_LINK3res(cmdnfs_encodetype_t encodeflag, 03800 int argc, char **argv, 03801 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03802 { 03803 03804 LINK3res *p_LINK3res = (LINK3res *) p_nfs_struct; 03805 03806 /* sanity check */ 03807 if(p_LINK3res == NULL) 03808 return FALSE; 03809 03810 switch (encodeflag) 03811 { 03812 case CMDNFS_DECODE: 03813 03814 fprintf(out_stream, "%*sLINK3res =\n", indent, " "); 03815 fprintf(out_stream, "%*s{\n", indent, " "); 03816 03817 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03818 (caddr_t) & p_LINK3res->status) == FALSE) 03819 { 03820 return FALSE; 03821 } 03822 03823 if(p_LINK3res->status == NFS3_OK) 03824 { 03825 03826 fprintf(out_stream, "%*sPost-op attributes (file):\n", indent + 2, " "); 03827 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03828 (caddr_t) & LINK3_OK_ATTRS(p_LINK3res)) == FALSE) 03829 { 03830 return FALSE; 03831 } 03832 03833 fprintf(out_stream, "%*sWcc_data (link directory):\n", indent + 2, " "); 03834 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03835 (caddr_t) & LINK3_OK_WCC(p_LINK3res)) == FALSE) 03836 { 03837 return FALSE; 03838 } 03839 03840 } 03841 else 03842 { 03843 fprintf(out_stream, "%*sPost-op attributes (file):\n", indent + 2, " "); 03844 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03845 (caddr_t) & LINK3_FAIL_ATTRS(p_LINK3res)) == FALSE) 03846 { 03847 return FALSE; 03848 } 03849 03850 fprintf(out_stream, "%*sWcc_data (link directory):\n", indent + 2, " "); 03851 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03852 (caddr_t) & LINK3_FAIL_WCC(p_LINK3res)) == FALSE) 03853 { 03854 return FALSE; 03855 } 03856 } 03857 03858 fprintf(out_stream, "%*s}\n", indent, " "); 03859 03860 return TRUE; 03861 03862 break; 03863 03864 case CMDNFS_ENCODE: 03865 /* never encoded */ 03866 case CMDNFS_FREE: 03867 /* it is never an input (never encoded, never allocated) */ 03868 default: 03869 return FALSE; 03870 } 03871 03872 } 03873 03874 #undef LINK3_OK_ATTRS 03875 #undef LINK3_OK_WCC 03876 #undef LINK3_FAIL_ATTRS 03877 #undef LINK3_FAIL_WCC 03878 03879 int cmdnfs_SYMLINK3args(cmdnfs_encodetype_t encodeflag, 03880 int argc, char **argv, 03881 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03882 { 03883 SYMLINK3args *p_SYMLINK3args = (SYMLINK3args *) p_nfs_struct; 03884 03885 /* sanity check */ 03886 if(p_SYMLINK3args == NULL) 03887 return FALSE; 03888 03889 switch (encodeflag) 03890 { 03891 case CMDNFS_ENCODE: 03892 03893 if((argc != 3) && (argc != 4)) 03894 return FALSE; 03895 03896 /* The first 2 args */ 03897 if(cmdnfs_diropargs3(CMDNFS_ENCODE, 2, argv, 0, NULL, 03898 (caddr_t) & (p_SYMLINK3args->where)) == FALSE) 03899 { 03900 return FALSE; 03901 } 03902 03903 /* optional 3rd arg */ 03904 if(argc == 4) 03905 { 03906 if(cmdnfs_sattr3(CMDNFS_ENCODE, 1, argv + 2, 0, NULL, 03907 (caddr_t) & (p_SYMLINK3args->symlink.symlink_attributes)) == 03908 FALSE) 03909 { 03910 return FALSE; 03911 } 03912 /* 4th arg */ 03913 if(cmdnfs_dirpath(CMDNFS_ENCODE, argc - 3, argv + 3, 0, NULL, 03914 (caddr_t) & (p_SYMLINK3args->symlink.symlink_data)) == FALSE) 03915 { 03916 return FALSE; 03917 } 03918 03919 } 03920 else 03921 { 03922 /* empty attr set */ 03923 if(cmdnfs_sattr3(CMDNFS_ENCODE, 0, NULL, 0, NULL, 03924 (caddr_t) & (p_SYMLINK3args->symlink.symlink_attributes)) == 03925 FALSE) 03926 { 03927 return FALSE; 03928 } 03929 if(cmdnfs_dirpath(CMDNFS_ENCODE, argc - 2, argv + 2, 0, NULL, 03930 (caddr_t) & (p_SYMLINK3args->symlink.symlink_data)) == FALSE) 03931 { 03932 return FALSE; 03933 } 03934 } 03935 03936 return TRUE; 03937 03938 case CMDNFS_FREE: 03939 cmdnfs_diropargs3(CMDNFS_FREE, 0, NULL, 0, NULL, 03940 (caddr_t) & (p_SYMLINK3args->where)); 03941 cmdnfs_sattr3(CMDNFS_FREE, 0, NULL, 0, NULL, 03942 (caddr_t) & (p_SYMLINK3args->symlink.symlink_attributes)); 03943 cmdnfs_dirpath(CMDNFS_FREE, 0, NULL, 0, NULL, 03944 (caddr_t) & (p_SYMLINK3args->symlink.symlink_data)); 03945 return TRUE; 03946 break; 03947 03948 case CMDNFS_DECODE: 03949 /* never decoded */ 03950 default: 03951 return FALSE; 03952 } 03953 } /* cmdnfs_SYMLINK3args */ 03954 03955 #define SYMLINK3_OK_FH( _p_SYMLINK3res ) ( (_p_SYMLINK3res)->SYMLINK3res_u.resok.obj ) 03956 #define SYMLINK3_OK_ATTRS( _p_SYMLINK3res ) ( (_p_SYMLINK3res)->SYMLINK3res_u.resok.obj_attributes ) 03957 #define SYMLINK3_OK_WCC( _p_SYMLINK3res ) ( (_p_SYMLINK3res)->SYMLINK3res_u.resok.dir_wcc ) 03958 #define SYMLINK3_FAIL_WCC( _p_SYMLINK3res ) ( (_p_SYMLINK3res)->SYMLINK3res_u.resfail.dir_wcc ) 03959 03960 int cmdnfs_SYMLINK3res(cmdnfs_encodetype_t encodeflag, 03961 int argc, char **argv, 03962 int indent, FILE * out_stream, caddr_t p_nfs_struct) 03963 { 03964 03965 SYMLINK3res *p_SYMLINK3res = (SYMLINK3res *) p_nfs_struct; 03966 03967 /* sanity check */ 03968 if(p_SYMLINK3res == NULL) 03969 return FALSE; 03970 03971 switch (encodeflag) 03972 { 03973 case CMDNFS_DECODE: 03974 03975 fprintf(out_stream, "%*sSYMLINK3res =\n", indent, " "); 03976 fprintf(out_stream, "%*s{\n", indent, " "); 03977 03978 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03979 (caddr_t) & p_SYMLINK3res->status) == FALSE) 03980 { 03981 return FALSE; 03982 } 03983 03984 if(p_SYMLINK3res->status == NFS3_OK) 03985 { 03986 03987 if(cmdnfs_postopfh3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 03988 (caddr_t) & SYMLINK3_OK_FH(p_SYMLINK3res)) == FALSE) 03989 { 03990 return FALSE; 03991 } 03992 03993 fprintf(out_stream, "%*sPost-op attributes (symlink):\n", indent + 2, " "); 03994 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 03995 (caddr_t) & SYMLINK3_OK_ATTRS(p_SYMLINK3res)) == FALSE) 03996 { 03997 return FALSE; 03998 } 03999 04000 fprintf(out_stream, "%*sWcc_data (directory):\n", indent + 2, " "); 04001 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04002 (caddr_t) & SYMLINK3_OK_WCC(p_SYMLINK3res)) == FALSE) 04003 { 04004 return FALSE; 04005 } 04006 04007 } 04008 else 04009 { 04010 fprintf(out_stream, "%*sWcc_data (directory):\n", indent + 2, " "); 04011 if(cmdnfs_wccdata(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04012 (caddr_t) & SYMLINK3_FAIL_WCC(p_SYMLINK3res)) == FALSE) 04013 { 04014 return FALSE; 04015 } 04016 } 04017 04018 fprintf(out_stream, "%*s}\n", indent, " "); 04019 04020 return TRUE; 04021 04022 break; 04023 04024 case CMDNFS_ENCODE: 04025 /* never encoded */ 04026 case CMDNFS_FREE: 04027 /* it is never an input (never encoded, never allocated) */ 04028 default: 04029 return FALSE; 04030 } 04031 04032 } 04033 04034 #undef SYMLINK3_OK_FH 04035 #undef SYMLINK3_OK_ATTRS 04036 #undef SYMLINK3_OK_WCC 04037 #undef SYMLINK3_FAIL_WCC 04038 04039 #define FSINFO3_OK_ATTRS( _p_FSINFO3res ) ( (_p_FSINFO3res)->FSINFO3res_u.resok.obj_attributes ) 04040 #define FSINFO3_OK_INFO( _p_FSINFO3res ) ( (_p_FSINFO3res)->FSINFO3res_u.resok ) 04041 #define FSINFO3_FAIL_ATTRS( _p_FSINFO3res ) ( (_p_FSINFO3res)->FSINFO3res_u.resfail.obj_attributes ) 04042 04043 int cmdnfs_FSINFO3res(cmdnfs_encodetype_t encodeflag, 04044 int argc, char **argv, 04045 int indent, FILE * out_stream, caddr_t p_nfs_struct) 04046 { 04047 04048 FSINFO3res *p_FSINFO3res = (FSINFO3res *) p_nfs_struct; 04049 04050 /* sanity check */ 04051 if(p_FSINFO3res == NULL) 04052 return FALSE; 04053 04054 switch (encodeflag) 04055 { 04056 case CMDNFS_DECODE: 04057 04058 fprintf(out_stream, "%*sFSINFO3res =\n", indent, " "); 04059 fprintf(out_stream, "%*s{\n", indent, " "); 04060 04061 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 04062 (caddr_t) & p_FSINFO3res->status) == FALSE) 04063 { 04064 return FALSE; 04065 } 04066 04067 if(p_FSINFO3res->status == NFS3_OK) 04068 { 04069 04070 fprintf(out_stream, "%*sPost-op attributes (root):\n", indent + 2, " "); 04071 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04072 (caddr_t) & FSINFO3_OK_ATTRS(p_FSINFO3res)) == FALSE) 04073 { 04074 return FALSE; 04075 } 04076 04077 fprintf(out_stream, "%*srtmax = %u\n", indent + 2, " ", 04078 FSINFO3_OK_INFO(p_FSINFO3res).rtmax); 04079 fprintf(out_stream, "%*srtpref = %u\n", indent + 2, " ", 04080 FSINFO3_OK_INFO(p_FSINFO3res).rtpref); 04081 fprintf(out_stream, "%*srtmult = %u\n", indent + 2, " ", 04082 FSINFO3_OK_INFO(p_FSINFO3res).rtmult); 04083 fprintf(out_stream, "%*swtmax = %u\n", indent + 2, " ", 04084 FSINFO3_OK_INFO(p_FSINFO3res).wtmax); 04085 fprintf(out_stream, "%*swtpref = %u\n", indent + 2, " ", 04086 FSINFO3_OK_INFO(p_FSINFO3res).wtpref); 04087 fprintf(out_stream, "%*swtmult = %u\n", indent + 2, " ", 04088 FSINFO3_OK_INFO(p_FSINFO3res).wtmult); 04089 fprintf(out_stream, "%*sdtpref = %u\n", indent + 2, " ", 04090 FSINFO3_OK_INFO(p_FSINFO3res).dtpref); 04091 fprintf(out_stream, "%*smaxfilesize = %llu (%#llx)\n", indent + 2, " ", 04092 FSINFO3_OK_INFO(p_FSINFO3res).maxfilesize, 04093 FSINFO3_OK_INFO(p_FSINFO3res).maxfilesize); 04094 fprintf(out_stream, "%*stime_delta = %u.%.9u\n", indent + 2, " ", 04095 FSINFO3_OK_INFO(p_FSINFO3res).time_delta.seconds, 04096 FSINFO3_OK_INFO(p_FSINFO3res).time_delta.nseconds); 04097 fprintf(out_stream, "%*sproperties = %#x : ", indent + 2, " ", 04098 FSINFO3_OK_INFO(p_FSINFO3res).properties); 04099 04100 if(FSINFO3_OK_INFO(p_FSINFO3res).properties & FSF3_LINK) 04101 fprintf(out_stream, "FSF3_LINK "); 04102 if(FSINFO3_OK_INFO(p_FSINFO3res).properties & FSF3_SYMLINK) 04103 fprintf(out_stream, "FSF3_SYMLINK "); 04104 if(FSINFO3_OK_INFO(p_FSINFO3res).properties & FSF3_HOMOGENEOUS) 04105 fprintf(out_stream, "FSF3_HOMOGENEOUS "); 04106 if(FSINFO3_OK_INFO(p_FSINFO3res).properties & FSF3_CANSETTIME) 04107 fprintf(out_stream, "FSF3_CANSETTIME "); 04108 04109 fprintf(out_stream, "\n"); 04110 04111 } 04112 else 04113 { 04114 fprintf(out_stream, "%*sPost-op attributes (root):\n", indent + 2, " "); 04115 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04116 (caddr_t) & FSINFO3_FAIL_ATTRS(p_FSINFO3res)) == FALSE) 04117 { 04118 return FALSE; 04119 } 04120 } 04121 04122 fprintf(out_stream, "%*s}\n", indent, " "); 04123 04124 return TRUE; 04125 04126 break; 04127 04128 case CMDNFS_ENCODE: 04129 /* never encoded */ 04130 case CMDNFS_FREE: 04131 /* it is never an input (never encoded, never allocated) */ 04132 default: 04133 return FALSE; 04134 } 04135 04136 } /* cmdnfs_FSINFO3res */ 04137 04138 #undef FSINFO3_OK_ATTRS 04139 #undef FSINFO3_OK_INFO 04140 #undef FSINFO3_FAIL_ATTRS 04141 04142 #define PATHCONF3_OK_ATTRS( _p_PATHCONF3res ) ( (_p_PATHCONF3res)->PATHCONF3res_u.resok.obj_attributes ) 04143 #define PATHCONF3_OK_INFO( _p_PATHCONF3res ) ( (_p_PATHCONF3res)->PATHCONF3res_u.resok ) 04144 #define PATHCONF3_FAIL_ATTRS( _p_PATHCONF3res ) ( (_p_PATHCONF3res)->PATHCONF3res_u.resfail.obj_attributes ) 04145 04146 int cmdnfs_PATHCONF3res(cmdnfs_encodetype_t encodeflag, 04147 int argc, char **argv, 04148 int indent, FILE * out_stream, caddr_t p_nfs_struct) 04149 { 04150 04151 PATHCONF3res *p_PATHCONF3res = (PATHCONF3res *) p_nfs_struct; 04152 04153 /* sanity check */ 04154 if(p_PATHCONF3res == NULL) 04155 return FALSE; 04156 04157 switch (encodeflag) 04158 { 04159 case CMDNFS_DECODE: 04160 04161 fprintf(out_stream, "%*sPATHCONF3res =\n", indent, " "); 04162 fprintf(out_stream, "%*s{\n", indent, " "); 04163 04164 if(cmdnfs_nfsstat3(CMDNFS_DECODE, 0, NULL, indent + 2, out_stream, 04165 (caddr_t) & p_PATHCONF3res->status) == FALSE) 04166 { 04167 return FALSE; 04168 } 04169 04170 if(p_PATHCONF3res->status == NFS3_OK) 04171 { 04172 04173 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 04174 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04175 (caddr_t) & PATHCONF3_OK_ATTRS(p_PATHCONF3res)) == FALSE) 04176 { 04177 return FALSE; 04178 } 04179 04180 fprintf(out_stream, "%*slinkmax = %u\n", indent + 2, " ", 04181 PATHCONF3_OK_INFO(p_PATHCONF3res).linkmax); 04182 fprintf(out_stream, "%*sname_max = %u\n", indent + 2, " ", 04183 PATHCONF3_OK_INFO(p_PATHCONF3res).name_max); 04184 fprintf(out_stream, "%*sno_trunc = %u\n", indent + 2, " ", 04185 PATHCONF3_OK_INFO(p_PATHCONF3res).no_trunc); 04186 fprintf(out_stream, "%*schown_restricted = %u\n", indent + 2, " ", 04187 PATHCONF3_OK_INFO(p_PATHCONF3res).chown_restricted); 04188 fprintf(out_stream, "%*scase_insensitive = %u\n", indent + 2, " ", 04189 PATHCONF3_OK_INFO(p_PATHCONF3res).case_insensitive); 04190 fprintf(out_stream, "%*scase_preserving = %u\n", indent + 2, " ", 04191 PATHCONF3_OK_INFO(p_PATHCONF3res).case_preserving); 04192 04193 } 04194 else 04195 { 04196 fprintf(out_stream, "%*sPost-op attributes (object):\n", indent + 2, " "); 04197 if(cmdnfs_postopattr(CMDNFS_DECODE, 0, NULL, indent + 4, out_stream, 04198 (caddr_t) & PATHCONF3_FAIL_ATTRS(p_PATHCONF3res)) == FALSE) 04199 { 04200 return FALSE; 04201 } 04202 } 04203 04204 fprintf(out_stream, "%*s}\n", indent, " "); 04205 04206 return TRUE; 04207 04208 break; 04209 04210 case CMDNFS_ENCODE: 04211 /* never encoded */ 04212 case CMDNFS_FREE: 04213 /* it is never an input (never encoded, never allocated) */ 04214 default: 04215 return FALSE; 04216 } 04217 04218 } /* cmdnfs_PATHCONF3res */ 04219 04220 #undef PATHCONF3_OK_ATTRS 04221 #undef PATHCONF3_OK_INFO 04222 #undef PATHCONF3_FAIL_ATTRS 04223 04224 /*-----------------------------------------------------------------------*/ 04225 04237 #define print_mask(_out,_mode,_mask,_lettre) do { \ 04238 if (_mode & _mask) fprintf(_out,_lettre); \ 04239 else fprintf(_out,"-"); \ 04240 } while(0) 04241 04242 void print_nfsitem_line(FILE * out, fattr3 * attrib, char *name, char *target) 04243 { 04244 04245 char buff[256]; 04246 04247 /* print inode */ 04248 fprintf(out, "%10llx ", attrib->fileid); 04249 04250 /* printing type */ 04251 switch (attrib->type) 04252 { 04253 case NF3FIFO: 04254 fprintf(out, "p"); 04255 break; 04256 case NF3CHR: 04257 fprintf(out, "c"); 04258 break; 04259 case NF3DIR: 04260 fprintf(out, "d"); 04261 break; 04262 case NF3BLK: 04263 fprintf(out, "b"); 04264 break; 04265 case NF3REG: 04266 fprintf(out, "-"); 04267 break; 04268 case NF3LNK: 04269 fprintf(out, "l"); 04270 break; 04271 case NF3SOCK: 04272 fprintf(out, "s"); 04273 break; 04274 default: 04275 fprintf(out, "?"); 04276 } 04277 04278 /* printing rights */ 04279 print_mask(out, attrib->mode, S_IRUSR, "r"); 04280 print_mask(out, attrib->mode, S_IWUSR, "w"); 04281 04282 if(attrib->mode & S_ISUID) 04283 { 04284 if(attrib->mode & S_IXUSR) 04285 fprintf(out, "s"); 04286 else 04287 fprintf(out, "S"); 04288 } 04289 else 04290 { 04291 if(attrib->mode & S_IXUSR) 04292 fprintf(out, "x"); 04293 else 04294 fprintf(out, "-"); 04295 } 04296 04297 print_mask(out, attrib->mode, S_IRGRP, "r"); 04298 print_mask(out, attrib->mode, S_IWGRP, "w"); 04299 04300 if(attrib->mode & S_ISGID) 04301 { 04302 if(attrib->mode & S_IXGRP) 04303 fprintf(out, "s"); 04304 else 04305 fprintf(out, "l"); 04306 } 04307 else 04308 { 04309 if(attrib->mode & S_IXGRP) 04310 fprintf(out, "x"); 04311 else 04312 fprintf(out, "-"); 04313 } 04314 print_mask(out, attrib->mode, S_IROTH, "r"); 04315 print_mask(out, attrib->mode, S_IWOTH, "w"); 04316 print_mask(out, attrib->mode, S_IXOTH, "x"); 04317 04318 fprintf(out, " %3u", attrib->nlink); 04319 fprintf(out, " %8d", attrib->uid); 04320 fprintf(out, " %8d", attrib->gid); 04321 fprintf(out, " %15llu", attrib->size); 04322 04323 /* print mtime */ 04324 fprintf(out, " %15s", time2str(attrib->mtime.seconds, buff)); 04325 04326 /* print name */ 04327 fprintf(out, " %s", name); 04328 04329 if(attrib->type == NF3LNK) 04330 fprintf(out, " -> %s", target); 04331 04332 fprintf(out, "\n"); 04333 return; 04334 04335 } /* print_nfsitem_line */ 04336 04345 void print_nfs_attributes(fattr3 * attrs, FILE * output) 04346 { 04347 04348 fprintf(output, "\tType : %s\n", nfstype3_to_str(attrs->type)); 04349 fprintf(output, "\tSize : %llu\n", attrs->size); 04350 fprintf(output, "\tfsId : %u.%u\n", (unsigned int)(attrs->fsid >> 32), 04351 (unsigned int)attrs->fsid); 04352 fprintf(output, "\tFileId : %#llx\n", attrs->fileid); 04353 fprintf(output, "\tMode : %#o\n", attrs->mode); 04354 fprintf(output, "\tNumlinks : %u\n", attrs->nlink); 04355 fprintf(output, "\tuid : %d\n", attrs->uid); 04356 fprintf(output, "\tgid : %d\n", attrs->gid); 04357 fprintf(output, "\tRawdev : %u.%u\n", attrs->rdev.specdata1, attrs->rdev.specdata2); 04358 fprintf(output, "\tatime : %s", ctime((time_t *) & attrs->atime.seconds)); 04359 fprintf(output, "\tctime : %s", ctime((time_t *) & attrs->ctime.seconds)); 04360 fprintf(output, "\tmtime : %s", ctime((time_t *) & attrs->mtime.seconds)); 04361 fprintf(output, "\tspaceused : %llu\n", attrs->used); 04362 04363 }