proto_set.c (0f1702c5) proto_set.c (bd670b35)
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 5 unchanged lines hidden (view full) ---

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
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 (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 5 unchanged lines hidden (view full) ---

14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#include <sys/types.h>
27#include <inet/common.h>
28#include <sys/stream.h>
29#include <sys/stropts.h>
30#include <sys/strsun.h>

--- 312 unchanged lines hidden (view full) ---

343 return (optd);
344 }
345 return (NULL);
346}
347
348/*
349 * Do a lookup of the options in the array and do permission and length checking
350 * Returns zero if there is no error (note: for non-tpi-providers not being able
23 * Use is subject to license terms.
24 */
25
26#include <sys/types.h>
27#include <inet/common.h>
28#include <sys/stream.h>
29#include <sys/stropts.h>
30#include <sys/strsun.h>

--- 312 unchanged lines hidden (view full) ---

343 return (optd);
344 }
345 return (NULL);
346}
347
348/*
349 * Do a lookup of the options in the array and do permission and length checking
350 * Returns zero if there is no error (note: for non-tpi-providers not being able
351 * to find the option is not an error). TPI errors are returned as -ve.
351 * to find the option is not an error). TPI errors are returned as negative
352 * numbers and errnos as positive numbers.
353 * If max_len is set we update it based on the max length of the option.
352 */
353int
354proto_opt_check(int level, int name, int len, t_uscalar_t *max_len,
354 */
355int
356proto_opt_check(int level, int name, int len, t_uscalar_t *max_len,
355 opdes_t *opt_arr, uint_t opt_arr_cnt, boolean_t topmost_tpiprovider,
356 boolean_t negotiate, boolean_t check, cred_t *cr)
357 opdes_t *opt_arr, uint_t opt_arr_cnt, boolean_t negotiate, boolean_t check,
358 cred_t *cr)
357{
358 opdes_t *optd;
359
360 /* Find the option in the opt_arr. */
359{
360 opdes_t *optd;
361
362 /* Find the option in the opt_arr. */
361 if ((optd = proto_opt_lookup(level, name, opt_arr, opt_arr_cnt)) ==
362 NULL) {
363 /*
364 * Not found, that is a bad thing if
365 * the caller is a tpi provider
366 */
367 if (topmost_tpiprovider)
368 return (-TBADOPT);
369 else
370 return (0); /* skip unmodified */
371 }
363 optd = proto_opt_lookup(level, name, opt_arr, opt_arr_cnt);
364 if (optd == NULL)
365 return (-TBADOPT);
372
373 /* Additional checks dependent on operation. */
374 if (negotiate) {
375 /* Cannot be true at the same time */
376 ASSERT(check == B_FALSE);
377
378 if (!OA_WRITE_OR_EXECUTE(optd, cr)) {
379 /* can't negotiate option */

--- 24 unchanged lines hidden (view full) ---

404 }
405 } else {
406 if (check) {
407 if (!OA_RWX_ANYPRIV(optd))
408 /* any of "rwx" permission but not none */
409 return (-TBADOPT);
410 }
411 /*
366
367 /* Additional checks dependent on operation. */
368 if (negotiate) {
369 /* Cannot be true at the same time */
370 ASSERT(check == B_FALSE);
371
372 if (!OA_WRITE_OR_EXECUTE(optd, cr)) {
373 /* can't negotiate option */

--- 24 unchanged lines hidden (view full) ---

398 }
399 } else {
400 if (check) {
401 if (!OA_RWX_ANYPRIV(optd))
402 /* any of "rwx" permission but not none */
403 return (-TBADOPT);
404 }
405 /*
412 * XXX Change the comments.
413 *
414 * XXX Since T_CURRENT was not there in TLI and the
415 * official TLI inspired TPI standard, getsockopt()
416 * API uses T_CHECK (for T_CURRENT semantics)
406 * XXX Since T_CURRENT was not there in TLI and the
407 * official TLI inspired TPI standard, getsockopt()
408 * API uses T_CHECK (for T_CURRENT semantics)
417 * The following fallthru makes sense because of its
418 * historical use as semantic equivalent to T_CURRENT.
409 * Thus T_CHECK includes the T_CURRENT semantics due to that
410 * historical use.
419 */
411 */
420 /* FALLTHRU */
421 if (!OA_READ_PERMISSION(optd, cr)) {
422 /* can't read option value */
423 if (!(OA_MATCHED_PRIV(optd, cr)) &&
424 OA_R_ANYPRIV(optd)) {
425 /*
426 * not privileged but privilege
427 * will help in reading option value.
428 */

--- 12 unchanged lines hidden ---
412 if (!OA_READ_PERMISSION(optd, cr)) {
413 /* can't read option value */
414 if (!(OA_MATCHED_PRIV(optd, cr)) &&
415 OA_R_ANYPRIV(optd)) {
416 /*
417 * not privileged but privilege
418 * will help in reading option value.
419 */

--- 12 unchanged lines hidden ---