Print this page
10105 libproject needs smatch fixes


   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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  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 (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012, Joyent, Inc. All rights reserved.
  24  */
  25 
  26 
  27 #include <sys/task.h>
  28 #include <sys/types.h>
  29 #include <unistd.h>
  30 
  31 #include <ctype.h>
  32 #include <project.h>
  33 #include <rctl.h>
  34 #include <secdb.h>
  35 #include <signal.h>
  36 #include <stdlib.h>
  37 #include <string.h>
  38 #include <strings.h>
  39 #include <nss_dbdefs.h>
  40 #include <pwd.h>
  41 #include <pool.h>
  42 #include <libproc.h>
  43 #include <priv.h>


 484         if (pool_name != NULL && pool_get_pool(conf, pool_name) != NULL) {
 485                 /*
 486                  * There was a project.pool entry, and the pool it refers to
 487                  * is a valid (active) pool.
 488                  */
 489                 (void) pool_conf_close(conf);
 490                 pool_conf_free(conf);
 491                 if (pool_set_binding(pool_name, P_PID, pid) != PO_SUCCESS) {
 492                         if (pool_error() != POE_SYSTEM)
 493                                 errno = EINVAL;
 494                         return (-1);
 495                 }
 496                 return (0);
 497         }
 498 
 499         /*
 500          * Bind to the pool with 'pool.default' = 'true' if
 501          * 'system.bind-default' = 'true'.
 502          */
 503         if ((pvals[0] = pool_value_alloc()) == NULL) {
 504                 pool_conf_close(conf);
 505                 pool_conf_free(conf);
 506                 return (-1);
 507         }
 508         if (!force && pool_get_property(conf, pool_conf_to_elem(conf),
 509             "system.bind-default", pvals[0]) != POC_BOOL ||
 510             pool_value_get_bool(pvals[0], &bval) != PO_SUCCESS ||
 511             bval == PO_FALSE) {
 512                 pool_value_free(pvals[0]);
 513                 pool_conf_close(conf);
 514                 pool_conf_free(conf);
 515                 errno = pool_name == NULL ? EACCES : ESRCH;
 516                 return (-1);
 517         }
 518         (void) pool_value_set_name(pvals[0], "pool.default");
 519         pool_value_set_bool(pvals[0], PO_TRUE);
 520         if ((pools = pool_query_pools(conf, &nelem, pvals)) == NULL) {
 521                 /*
 522                  * No default pools exist.
 523                  */
 524                 pool_value_free(pvals[0]);
 525                 pool_conf_close(conf);
 526                 pool_conf_free(conf);
 527                 errno = pool_name == NULL ? EACCES : ESRCH;
 528                 return (-1);
 529         }
 530         if (nelem != 1 ||
 531             pool_get_property(conf, pool_to_elem(conf, pools[0]), "pool.name",
 532             pvals[0]) != POC_STRING) {
 533                 /*
 534                  * Configuration is invalid.
 535                  */
 536                 free(pools);
 537                 pool_value_free(pvals[0]);
 538                 (void) pool_conf_close(conf);
 539                 pool_conf_free(conf);
 540                 return (0);
 541         }
 542         free(pools);
 543         (void) pool_conf_close(conf);
 544         pool_conf_free(conf);
 545         (void) pool_value_get_string(pvals[0], &nm);




   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
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  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 (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2018, Joyent, Inc.
  24  */
  25 
  26 
  27 #include <sys/task.h>
  28 #include <sys/types.h>
  29 #include <unistd.h>
  30 
  31 #include <ctype.h>
  32 #include <project.h>
  33 #include <rctl.h>
  34 #include <secdb.h>
  35 #include <signal.h>
  36 #include <stdlib.h>
  37 #include <string.h>
  38 #include <strings.h>
  39 #include <nss_dbdefs.h>
  40 #include <pwd.h>
  41 #include <pool.h>
  42 #include <libproc.h>
  43 #include <priv.h>


 484         if (pool_name != NULL && pool_get_pool(conf, pool_name) != NULL) {
 485                 /*
 486                  * There was a project.pool entry, and the pool it refers to
 487                  * is a valid (active) pool.
 488                  */
 489                 (void) pool_conf_close(conf);
 490                 pool_conf_free(conf);
 491                 if (pool_set_binding(pool_name, P_PID, pid) != PO_SUCCESS) {
 492                         if (pool_error() != POE_SYSTEM)
 493                                 errno = EINVAL;
 494                         return (-1);
 495                 }
 496                 return (0);
 497         }
 498 
 499         /*
 500          * Bind to the pool with 'pool.default' = 'true' if
 501          * 'system.bind-default' = 'true'.
 502          */
 503         if ((pvals[0] = pool_value_alloc()) == NULL) {
 504                 (void) pool_conf_close(conf);
 505                 pool_conf_free(conf);
 506                 return (-1);
 507         }
 508         if (!force && pool_get_property(conf, pool_conf_to_elem(conf),
 509             "system.bind-default", pvals[0]) != POC_BOOL ||
 510             pool_value_get_bool(pvals[0], &bval) != PO_SUCCESS ||
 511             bval == PO_FALSE) {
 512                 pool_value_free(pvals[0]);
 513                 (void) pool_conf_close(conf);
 514                 pool_conf_free(conf);
 515                 errno = pool_name == NULL ? EACCES : ESRCH;
 516                 return (-1);
 517         }
 518         (void) pool_value_set_name(pvals[0], "pool.default");
 519         pool_value_set_bool(pvals[0], PO_TRUE);
 520         if ((pools = pool_query_pools(conf, &nelem, pvals)) == NULL) {
 521                 /*
 522                  * No default pools exist.
 523                  */
 524                 pool_value_free(pvals[0]);
 525                 (void) pool_conf_close(conf);
 526                 pool_conf_free(conf);
 527                 errno = pool_name == NULL ? EACCES : ESRCH;
 528                 return (-1);
 529         }
 530         if (nelem != 1 ||
 531             pool_get_property(conf, pool_to_elem(conf, pools[0]), "pool.name",
 532             pvals[0]) != POC_STRING) {
 533                 /*
 534                  * Configuration is invalid.
 535                  */
 536                 free(pools);
 537                 pool_value_free(pvals[0]);
 538                 (void) pool_conf_close(conf);
 539                 pool_conf_free(conf);
 540                 return (0);
 541         }
 542         free(pools);
 543         (void) pool_conf_close(conf);
 544         pool_conf_free(conf);
 545         (void) pool_value_get_string(pvals[0], &nm);