Print this page
Add libuserdefs and use in cmd/{oamuser,passwd}


  81 
  82 static ua_key_t keys[] = {
  83         /* First entry is always set correctly in main() */
  84         { USERATTR_TYPE_KW,     check_type,     type },
  85         { USERATTR_AUTHS_KW,    check_auth,     auth },
  86         { USERATTR_PROFILES_KW, check_prof,     prof },
  87         { USERATTR_ROLES_KW,    check_role,     role },
  88         { USERATTR_DEFAULTPROJ_KW,      check_proj,     proj },
  89         { USERATTR_LIMPRIV_KW,  check_privset,  priv },
  90         { USERATTR_DFLTPRIV_KW, check_privset,  priv },
  91         { USERATTR_LOCK_AFTER_RETRIES_KW, check_lock_after_retries,  lock },
  92         { USERATTR_CLEARANCE,   check_label,    label },
  93         { USERATTR_MINLABEL,    check_label,    label },
  94         { USERATTR_IDLECMD_KW,  check_idlecmd,  idlecmd },
  95         { USERATTR_IDLETIME_KW, check_idletime, idletime },
  96         { USERATTR_AUDIT_FLAGS_KW, check_auditflags, auditflags },
  97 };
  98 
  99 #define NKEYS   (sizeof (keys)/sizeof (ua_key_t))
 100 



























 101 /*
 102  * Change a key, there are three different call sequences:
 103  *
 104  *              key, value      - key with option letter, value.
 105  *              NULL, value     - -K key=value option.
 106  */
 107 
 108 void
 109 change_key(const char *key, char *value)
 110 {
 111         int i;
 112         const char *res;
 113 
 114         if (key == NULL) {
 115                 key = value;
 116                 value = strchr(value, '=');
 117                 /* Bad value */
 118                 if (value == NULL) {
 119                         errmsg(M_INVALID_VALUE);
 120                         exit(EX_BADARG);




  81 
  82 static ua_key_t keys[] = {
  83         /* First entry is always set correctly in main() */
  84         { USERATTR_TYPE_KW,     check_type,     type },
  85         { USERATTR_AUTHS_KW,    check_auth,     auth },
  86         { USERATTR_PROFILES_KW, check_prof,     prof },
  87         { USERATTR_ROLES_KW,    check_role,     role },
  88         { USERATTR_DEFAULTPROJ_KW,      check_proj,     proj },
  89         { USERATTR_LIMPRIV_KW,  check_privset,  priv },
  90         { USERATTR_DFLTPRIV_KW, check_privset,  priv },
  91         { USERATTR_LOCK_AFTER_RETRIES_KW, check_lock_after_retries,  lock },
  92         { USERATTR_CLEARANCE,   check_label,    label },
  93         { USERATTR_MINLABEL,    check_label,    label },
  94         { USERATTR_IDLECMD_KW,  check_idlecmd,  idlecmd },
  95         { USERATTR_IDLETIME_KW, check_idletime, idletime },
  96         { USERATTR_AUDIT_FLAGS_KW, check_auditflags, auditflags },
  97 };
  98 
  99 #define NKEYS   (sizeof (keys)/sizeof (ua_key_t))
 100 
 101 /* Import default keys for ordinary useradd */
 102 void
 103 import_def(struct userdefs *ud)
 104 {
 105         int i;
 106 
 107         /* Don't import the user type (skip i = 0) */
 108         for (i = 1; i < NKEYS; i++) {
 109                 if (keys[i].newvalue == NULL)
 110                         keys[i].newvalue =
 111                             userdef_get_by_uakey(ud, keys[i].key);
 112         }
 113 }
 114 
 115 /* Export command line keys to defaults for useradd -D */
 116 void
 117 update_def(struct userdefs *ud)
 118 {
 119         int i;
 120 
 121         for (i = 0; i < NKEYS; i++) {
 122                 if (keys[i].newvalue != NULL)
 123                         userdef_set_by_uakey(ud, keys[i].key,
 124                             keys[i].newvalue);
 125         }
 126 }
 127 
 128 /*
 129  * Change a key, there are three different call sequences:
 130  *
 131  *              key, value      - key with option letter, value.
 132  *              NULL, value     - -K key=value option.
 133  */
 134 
 135 void
 136 change_key(const char *key, char *value)
 137 {
 138         int i;
 139         const char *res;
 140 
 141         if (key == NULL) {
 142                 key = value;
 143                 value = strchr(value, '=');
 144                 /* Bad value */
 145                 if (value == NULL) {
 146                         errmsg(M_INVALID_VALUE);
 147                         exit(EX_BADARG);