1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 30 #include <sys/param.h> 31 #include <sys/types.h> 32 #include <sys/systm.h> 33 #include <sys/user.h> 34 #include <sys/vnode.h> 35 #include <sys/file.h> 36 #include <sys/dirent.h> 37 #include <sys/vfs.h> 38 #include <sys/stream.h> 39 #include <sys/strsubr.h> 40 #include <sys/debug.h> 41 #include <sys/t_lock.h> 42 #include <sys/acl.h> 43 44 #include <rpc/types.h> 45 #include <rpc/xdr.h> 46 47 #include <nfs/nfs.h> 48 #include <nfs/nfs_clnt.h> 49 #include <nfs/nfs_acl.h> 50 51 /* 52 * These are the XDR routines used to serialize and deserialize 53 * the various structures passed as parameters accross the network 54 * between ACL clients and servers. 55 */ 56 57 bool_t 58 xdr_uid(XDR *xdrs, uid32_t *objp) 59 { 60 if (!xdr_int(xdrs, objp)) 61 return (FALSE); 62 return (TRUE); 63 } 64 65 bool_t 66 xdr_o_mode(XDR *xdrs, o_mode *objp) 67 { 68 69 if (!xdr_u_short(xdrs, (ushort_t *)objp)) 70 return (FALSE); 71 return (TRUE); 72 } 73 74 bool_t 75 xdr_aclent(XDR *xdrs, aclent_t *objp) 76 { 77 78 if (!xdr_int(xdrs, &objp->a_type)) 79 return (FALSE); 80 if (!xdr_uid(xdrs, &objp->a_id)) 81 return (FALSE); 82 if (!xdr_o_mode(xdrs, &objp->a_perm)) 83 return (FALSE); 84 return (TRUE); 85 } 86 87 bool_t 88 xdr_secattr(XDR *xdrs, vsecattr_t *objp) 89 { 90 uint_t count; 91 92 if (!xdr_u_int(xdrs, &objp->vsa_mask)) 93 return (FALSE); 94 if (!xdr_int(xdrs, &objp->vsa_aclcnt)) 95 return (FALSE); 96 if (objp->vsa_aclentp != NULL) 97 count = (uint_t)objp->vsa_aclcnt; 98 else 99 count = 0; 100 if (!xdr_array(xdrs, (char **)&objp->vsa_aclentp, &count, 101 NFS_ACL_MAX_ENTRIES, sizeof (aclent_t), (xdrproc_t)xdr_aclent)) 102 return (FALSE); 103 if (count != 0 && count != (uint_t)objp->vsa_aclcnt) 104 return (FALSE); 105 if (!xdr_int(xdrs, &objp->vsa_dfaclcnt)) 106 return (FALSE); 107 if (objp->vsa_dfaclentp != NULL) 108 count = (uint_t)objp->vsa_dfaclcnt; 109 else 110 count = 0; 111 if (!xdr_array(xdrs, (char **)&objp->vsa_dfaclentp, &count, 112 NFS_ACL_MAX_ENTRIES, sizeof (aclent_t), (xdrproc_t)xdr_aclent)) 113 return (FALSE); 114 if (count != 0 && count != (uint_t)objp->vsa_dfaclcnt) 115 return (FALSE); 116 return (TRUE); 117 } 118 119 bool_t 120 xdr_GETACL2args(XDR *xdrs, GETACL2args *objp) 121 { 122 123 if (!xdr_fhandle(xdrs, &objp->fh)) 124 return (FALSE); 125 if (!xdr_u_int(xdrs, &objp->mask)) 126 return (FALSE); 127 return (TRUE); 128 } 129 bool_t 130 xdr_fastGETACL2args(XDR *xdrs, GETACL2args **objpp) 131 { 132 int32_t *ptr; 133 #ifdef _LITTLE_ENDIAN 134 GETACL2args *objp; 135 #endif 136 137 if (xdrs->x_op != XDR_DECODE) 138 return (FALSE); 139 140 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (GETACL2args))); 141 if (ptr != NULL) { 142 *objpp = (GETACL2args *)ptr; 143 #ifdef _LITTLE_ENDIAN 144 objp = (GETACL2args *)ptr; 145 objp->mask = ntohl(objp->mask); 146 #endif 147 return (TRUE); 148 } 149 150 return (FALSE); 151 } 152 153 bool_t 154 xdr_GETACL2resok(XDR *xdrs, GETACL2resok *objp) 155 { 156 157 if (!xdr_fattr(xdrs, &objp->attr)) 158 return (FALSE); 159 if (!xdr_secattr(xdrs, &objp->acl)) 160 return (FALSE); 161 return (TRUE); 162 } 163 164 bool_t 165 xdr_GETACL2res(XDR *xdrs, GETACL2res *objp) 166 { 167 168 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 169 return (FALSE); 170 switch (objp->status) { 171 case NFS_OK: 172 if (!xdr_GETACL2resok(xdrs, &objp->resok)) 173 return (FALSE); 174 break; 175 } 176 return (TRUE); 177 } 178 179 bool_t 180 xdr_SETACL2args(XDR *xdrs, SETACL2args *objp) 181 { 182 183 if (!xdr_fhandle(xdrs, &objp->fh)) 184 return (FALSE); 185 if (!xdr_secattr(xdrs, &objp->acl)) 186 return (FALSE); 187 return (TRUE); 188 } 189 190 bool_t 191 xdr_SETACL2resok(XDR *xdrs, SETACL2resok *objp) 192 { 193 194 if (!xdr_fattr(xdrs, &objp->attr)) 195 return (FALSE); 196 return (TRUE); 197 } 198 #ifdef _LITTLE_ENDIAN 199 bool_t 200 xdr_fastSETACL2resok(XDR *xdrs, SETACL2resok *objp) 201 { 202 203 if (!xdr_fastfattr(xdrs, &objp->attr)) 204 return (FALSE); 205 return (TRUE); 206 } 207 #endif 208 209 bool_t 210 xdr_SETACL2res(XDR *xdrs, SETACL2res *objp) 211 { 212 213 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 214 return (FALSE); 215 switch (objp->status) { 216 case NFS_OK: 217 if (!xdr_SETACL2resok(xdrs, &objp->resok)) 218 return (FALSE); 219 break; 220 } 221 return (TRUE); 222 } 223 #ifdef _LITTLE_ENDIAN 224 bool_t 225 xdr_fastSETACL2res(XDR *xdrs, SETACL2res *objp) 226 { 227 228 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status)) 229 return (FALSE); 230 switch (objp->status) { 231 case NFS_OK: 232 if (!xdr_fastSETACL2resok(xdrs, &objp->resok)) 233 return (FALSE); 234 break; 235 } 236 return (TRUE); 237 } 238 #endif 239 240 bool_t 241 xdr_GETATTR2args(XDR *xdrs, GETATTR2args *objp) 242 { 243 244 if (!xdr_fhandle(xdrs, &objp->fh)) 245 return (FALSE); 246 return (TRUE); 247 } 248 bool_t 249 xdr_fastGETATTR2args(XDR *xdrs, GETATTR2args **objpp) 250 { 251 int32_t *ptr; 252 253 if (xdrs->x_op != XDR_DECODE) 254 return (FALSE); 255 256 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (GETATTR2args))); 257 if (ptr != NULL) { 258 *objpp = (GETATTR2args *)ptr; 259 return (TRUE); 260 } 261 262 return (FALSE); 263 } 264 265 bool_t 266 xdr_GETATTR2resok(XDR *xdrs, GETATTR2resok *objp) 267 { 268 269 if (!xdr_fattr(xdrs, &objp->attr)) 270 return (FALSE); 271 return (TRUE); 272 } 273 #ifdef _LITTLE_ENDIAN 274 bool_t 275 xdr_fastGETATTR2resok(XDR *xdrs, GETATTR2resok *objp) 276 { 277 278 if (!xdr_fastfattr(xdrs, &objp->attr)) 279 return (FALSE); 280 return (TRUE); 281 } 282 #endif 283 284 bool_t 285 xdr_GETATTR2res(XDR *xdrs, GETATTR2res *objp) 286 { 287 288 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 289 return (FALSE); 290 switch (objp->status) { 291 case NFS_OK: 292 if (!xdr_GETATTR2resok(xdrs, &objp->resok)) 293 return (FALSE); 294 break; 295 } 296 return (TRUE); 297 } 298 #ifdef _LITTLE_ENDIAN 299 bool_t 300 xdr_fastGETATTR2res(XDR *xdrs, GETATTR2res *objp) 301 { 302 303 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status)) 304 return (FALSE); 305 switch (objp->status) { 306 case NFS_OK: 307 if (!xdr_fastGETATTR2resok(xdrs, &objp->resok)) 308 return (FALSE); 309 break; 310 } 311 return (TRUE); 312 } 313 #endif 314 315 bool_t 316 xdr_ACCESS2args(XDR *xdrs, ACCESS2args *objp) 317 { 318 319 if (!xdr_fhandle(xdrs, &objp->fh)) 320 return (FALSE); 321 if (!xdr_uint32(xdrs, &objp->access)) 322 return (FALSE); 323 return (TRUE); 324 } 325 bool_t 326 xdr_fastACCESS2args(XDR *xdrs, ACCESS2args **objpp) 327 { 328 int32_t *ptr; 329 #ifdef _LITTLE_ENDIAN 330 ACCESS2args *objp; 331 #endif 332 333 if (xdrs->x_op != XDR_DECODE) 334 return (FALSE); 335 336 ptr = XDR_INLINE(xdrs, RNDUP(sizeof (ACCESS2args))); 337 if (ptr != NULL) { 338 *objpp = (ACCESS2args *)ptr; 339 #ifdef _LITTLE_ENDIAN 340 objp = (ACCESS2args *)ptr; 341 objp->access = ntohl(objp->access); 342 #endif 343 return (TRUE); 344 } 345 346 return (FALSE); 347 } 348 349 bool_t 350 xdr_ACCESS2resok(XDR *xdrs, ACCESS2resok *objp) 351 { 352 353 if (!xdr_fattr(xdrs, &objp->attr)) 354 return (FALSE); 355 if (!xdr_uint32(xdrs, &objp->access)) 356 return (FALSE); 357 return (TRUE); 358 } 359 #ifdef _LITTLE_ENDIAN 360 bool_t 361 xdr_fastACCESS2resok(XDR *xdrs, ACCESS2resok *objp) 362 { 363 364 if (!xdr_fastfattr(xdrs, &objp->attr)) 365 return (FALSE); 366 objp->access = ntohl(objp->access); 367 return (TRUE); 368 } 369 #endif 370 371 bool_t 372 xdr_ACCESS2res(XDR *xdrs, ACCESS2res *objp) 373 { 374 375 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 376 return (FALSE); 377 switch (objp->status) { 378 case NFS_OK: 379 if (!xdr_ACCESS2resok(xdrs, &objp->resok)) 380 return (FALSE); 381 break; 382 } 383 return (TRUE); 384 } 385 #ifdef _LITTLE_ENDIAN 386 bool_t 387 xdr_fastACCESS2res(XDR *xdrs, ACCESS2res *objp) 388 { 389 390 if (!xdr_fastenum(xdrs, (enum_t *)&objp->status)) 391 return (FALSE); 392 switch (objp->status) { 393 case NFS_OK: 394 if (!xdr_fastACCESS2resok(xdrs, &objp->resok)) 395 return (FALSE); 396 break; 397 } 398 return (TRUE); 399 } 400 #endif 401 402 bool_t 403 xdr_GETXATTRDIR2args(XDR *xdrs, GETXATTRDIR2args *objp) 404 { 405 if (!xdr_fhandle(xdrs, &objp->fh)) 406 return (FALSE); 407 if (!xdr_bool(xdrs, &objp->create)) 408 return (FALSE); 409 return (TRUE); 410 } 411 412 bool_t 413 xdr_GETXATTRDIR2resok(XDR *xdrs, GETXATTRDIR2resok *objp) 414 { 415 if (!xdr_fhandle(xdrs, &objp->fh)) 416 return (FALSE); 417 if (!xdr_fattr(xdrs, &objp->attr)) 418 return (FALSE); 419 return (TRUE); 420 } 421 422 bool_t 423 xdr_GETXATTRDIR2res(XDR *xdrs, GETXATTRDIR2res *objp) 424 { 425 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 426 return (FALSE); 427 switch (objp->status) { 428 case NFS_OK: 429 if (!xdr_GETXATTRDIR2resok(xdrs, &objp->resok)) 430 return (FALSE); 431 break; 432 } 433 return (TRUE); 434 } 435 436 bool_t 437 xdr_GETACL3args(XDR *xdrs, GETACL3args *objp) 438 { 439 440 if (!xdr_nfs_fh3(xdrs, &objp->fh)) 441 return (FALSE); 442 if (!xdr_u_int(xdrs, &objp->mask)) 443 return (FALSE); 444 return (TRUE); 445 } 446 447 bool_t 448 xdr_GETACL3resok(XDR *xdrs, GETACL3resok *objp) 449 { 450 451 if (!xdr_post_op_attr(xdrs, &objp->attr)) 452 return (FALSE); 453 if (!xdr_secattr(xdrs, &objp->acl)) 454 return (FALSE); 455 return (TRUE); 456 } 457 458 bool_t 459 xdr_GETACL3resfail(XDR *xdrs, GETACL3resfail *objp) 460 { 461 462 if (!xdr_post_op_attr(xdrs, &objp->attr)) 463 return (FALSE); 464 return (TRUE); 465 } 466 467 bool_t 468 xdr_GETACL3res(XDR *xdrs, GETACL3res *objp) 469 { 470 471 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 472 return (FALSE); 473 switch (objp->status) { 474 case NFS3_OK: 475 if (!xdr_GETACL3resok(xdrs, &objp->resok)) 476 return (FALSE); 477 break; 478 default: 479 if (!xdr_GETACL3resfail(xdrs, &objp->resfail)) 480 return (FALSE); 481 break; 482 } 483 return (TRUE); 484 } 485 486 bool_t 487 xdr_SETACL3args(XDR *xdrs, SETACL3args *objp) 488 { 489 490 if (!xdr_nfs_fh3(xdrs, &objp->fh)) 491 return (FALSE); 492 if (!xdr_secattr(xdrs, &objp->acl)) 493 return (FALSE); 494 return (TRUE); 495 } 496 497 bool_t 498 xdr_SETACL3resok(XDR *xdrs, SETACL3resok *objp) 499 { 500 501 if (!xdr_post_op_attr(xdrs, &objp->attr)) 502 return (FALSE); 503 return (TRUE); 504 } 505 506 bool_t 507 xdr_SETACL3resfail(XDR *xdrs, SETACL3resfail *objp) 508 { 509 510 if (!xdr_post_op_attr(xdrs, &objp->attr)) 511 return (FALSE); 512 return (TRUE); 513 } 514 515 bool_t 516 xdr_SETACL3res(XDR *xdrs, SETACL3res *objp) 517 { 518 519 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 520 return (FALSE); 521 switch (objp->status) { 522 case NFS3_OK: 523 if (!xdr_SETACL3resok(xdrs, &objp->resok)) 524 return (FALSE); 525 break; 526 default: 527 if (!xdr_SETACL3resfail(xdrs, &objp->resfail)) 528 return (FALSE); 529 break; 530 } 531 return (TRUE); 532 } 533 534 bool_t 535 xdr_GETXATTRDIR3args(XDR *xdrs, GETXATTRDIR3args *objp) 536 { 537 if (!xdr_nfs_fh3(xdrs, &objp->fh)) 538 return (FALSE); 539 if (!xdr_bool(xdrs, &objp->create)) 540 return (FALSE); 541 return (TRUE); 542 } 543 544 bool_t 545 xdr_GETXATTRDIR3resok(XDR *xdrs, GETXATTRDIR3resok *objp) 546 { 547 if (!xdr_nfs_fh3(xdrs, &objp->fh)) 548 return (FALSE); 549 if (!xdr_post_op_attr(xdrs, &objp->attr)) 550 return (FALSE); 551 return (TRUE); 552 } 553 554 bool_t 555 xdr_GETXATTRDIR3res(XDR *xdrs, GETXATTRDIR3res *objp) 556 { 557 if (!xdr_enum(xdrs, (enum_t *)&objp->status)) 558 return (FALSE); 559 switch (objp->status) { 560 case NFS_OK: 561 if (!xdr_GETXATTRDIR3resok(xdrs, &objp->resok)) 562 return (FALSE); 563 break; 564 } 565 return (TRUE); 566 } 567