Print this page
4078 groupadd execs getent unnecessarily
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Milan Jurik <milan.jurik@xylab.cz>
Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com>


   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) 1999, 2010, Oracle and/or its affiliates. All rights reserved.

  23  */
  24 
  25 #include <stdio.h>
  26 #include <stdlib.h>
  27 #include <strings.h>
  28 #include <auth_attr.h>
  29 #include <prof_attr.h>
  30 #include <user_attr.h>
  31 #include <project.h>
  32 #include <secdb.h>
  33 #include <pwd.h>
  34 #include <unistd.h>
  35 #include <priv.h>
  36 #include <errno.h>
  37 #include <ctype.h>
  38 #include <nss.h>
  39 #include <bsm/libbsm.h>
  40 #include <tsol/label.h>
  41 #include "funcs.h"
  42 #include "messages.h"


 163                 len = strlen(key) + strlen(val) + 2;
 164                 arg = malloc(len);
 165 
 166                 (void) snprintf(arg, len, "%s=%s", key, val);
 167                 argv[(*index)++] = "-K";
 168                 argv[(*index)++] = arg;
 169         }
 170 }
 171 
 172 /*
 173  * Propose a default value for a key and get the actual value back.
 174  * If the proposed default value is NULL, return the actual value set.
 175  * The key argument is the user_attr key.
 176  */
 177 char *
 178 getsetdefval(const char *key, char *dflt)
 179 {
 180         int i;
 181 
 182         for (i = 0; i < NKEYS; i++)
 183                 if (strcmp(keys[i].key, key) == 0)
 184                         if (keys[i].newvalue != NULL)
 185                                 return (keys[i].newvalue);
 186                         else
 187                                 return (keys[i].newvalue = dflt);

 188         return (NULL);
 189 }
 190 
 191 char *
 192 getusertype(char *cmdname)
 193 {
 194         static char usertype[MAX_TYPE_LENGTH];
 195         char *cmd;
 196 
 197         if (cmd = strrchr(cmdname, '/'))
 198                 ++cmd;
 199         else
 200                 cmd = cmdname;
 201 
 202         /* get user type based on the program name */
 203         if (strncmp(cmd, CMD_PREFIX_USER,
 204             strlen(CMD_PREFIX_USER)) == 0)
 205                 strcpy(usertype, USERATTR_TYPE_NORMAL_KW);
 206         else
 207                 strcpy(usertype, USERATTR_TYPE_NONADMIN_KW);
 208 
 209         return (usertype);
 210 }
 211 
 212 int
 213 is_role(char *usertype)
 214 {
 215         if (strcmp(usertype, USERATTR_TYPE_NONADMIN_KW) == 0)
 216                 return (1);
 217         /* not a role */




   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) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2013 RackTop Systems.
  24  */
  25 
  26 #include <stdio.h>
  27 #include <stdlib.h>
  28 #include <strings.h>
  29 #include <auth_attr.h>
  30 #include <prof_attr.h>
  31 #include <user_attr.h>
  32 #include <project.h>
  33 #include <secdb.h>
  34 #include <pwd.h>
  35 #include <unistd.h>
  36 #include <priv.h>
  37 #include <errno.h>
  38 #include <ctype.h>
  39 #include <nss.h>
  40 #include <bsm/libbsm.h>
  41 #include <tsol/label.h>
  42 #include "funcs.h"
  43 #include "messages.h"


 164                 len = strlen(key) + strlen(val) + 2;
 165                 arg = malloc(len);
 166 
 167                 (void) snprintf(arg, len, "%s=%s", key, val);
 168                 argv[(*index)++] = "-K";
 169                 argv[(*index)++] = arg;
 170         }
 171 }
 172 
 173 /*
 174  * Propose a default value for a key and get the actual value back.
 175  * If the proposed default value is NULL, return the actual value set.
 176  * The key argument is the user_attr key.
 177  */
 178 char *
 179 getsetdefval(const char *key, char *dflt)
 180 {
 181         int i;
 182 
 183         for (i = 0; i < NKEYS; i++)
 184                 if (strcmp(keys[i].key, key) == 0) {
 185                         if (keys[i].newvalue != NULL)
 186                                 return (keys[i].newvalue);
 187                         else
 188                                 return (keys[i].newvalue = dflt);
 189                 }
 190         return (NULL);
 191 }
 192 
 193 char *
 194 getusertype(char *cmdname)
 195 {
 196         static char usertype[MAX_TYPE_LENGTH];
 197         char *cmd;
 198 
 199         if ((cmd = strrchr(cmdname, '/')))
 200                 ++cmd;
 201         else
 202                 cmd = cmdname;
 203 
 204         /* get user type based on the program name */
 205         if (strncmp(cmd, CMD_PREFIX_USER,
 206             strlen(CMD_PREFIX_USER)) == 0)
 207                 strcpy(usertype, USERATTR_TYPE_NORMAL_KW);
 208         else
 209                 strcpy(usertype, USERATTR_TYPE_NONADMIN_KW);
 210 
 211         return (usertype);
 212 }
 213 
 214 int
 215 is_role(char *usertype)
 216 {
 217         if (strcmp(usertype, USERATTR_TYPE_NONADMIN_KW) == 0)
 218                 return (1);
 219         /* not a role */