Print this page
2989 Eliminate use of LOGNAME_MAX in ON
1166 useradd have warning with name more 8 chars


   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
   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 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Portions Copyright 2009 Chad Mynhier
  26  */
  27 
  28 #include <procfs.h>
  29 #include <unistd.h>
  30 #include <stdlib.h>
  31 #include <pwd.h>
  32 #include <ctype.h>
  33 #include <string.h>
  34 #include <libintl.h>
  35 #include <errno.h>
  36 #include <zone.h>
  37 #include <libzonecfg.h>

  38 
  39 #include "prstat.h"
  40 #include "prutil.h"
  41 #include "prtable.h"
  42 
  43 static plwp_t   *plwp_tbl[PLWP_TBL_SZ];
  44 
  45 void
  46 lwpid_init()
  47 {
  48         (void) memset(&plwp_tbl, 0, sizeof (plwp_t *) * PLWP_TBL_SZ);
  49 }
  50 
  51 static uid_t
  52 pwd_getid(char *name)
  53 {
  54         struct passwd *pwd;
  55 
  56         if ((pwd = getpwnam(name)) == NULL)
  57                 Die(gettext("invalid user name: %s\n"), name);
  58         return (pwd->pw_uid);
  59 }
  60 
  61 void
  62 pwd_getname(uid_t uid, char *name, int length, int noresolve)

  63 {
  64         struct passwd *pwd;

  65 
  66         if (noresolve || (pwd = getpwuid(uid)) == NULL) {





  67                 (void) snprintf(name, length, "%u", uid);
  68         } else {







  69                 (void) snprintf(name, length, "%s", pwd->pw_name);
  70         }
  71 }
  72 
  73 void
  74 add_uid(uidtbl_t *tbl, char *name)
  75 {
  76         uid_t *uid;
  77 
  78         if (tbl->n_size == tbl->n_nent) { /* reallocation */
  79                 if ((tbl->n_size *= 2) == 0)
  80                         tbl->n_size = 4;     /* first time */
  81                 tbl->n_list = Realloc(tbl->n_list, tbl->n_size*sizeof (uid_t));
  82         }
  83 
  84         uid = &tbl->n_list[tbl->n_nent++];
  85 
  86         if (isdigit(name[0])) {
  87                 *uid = Atoi(name);
  88         } else {




   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
   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) 2013 Gary Mills
  23  *
  24  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  *
  27  * Portions Copyright 2009 Chad Mynhier
  28  */
  29 
  30 #include <procfs.h>
  31 #include <unistd.h>
  32 #include <stdlib.h>
  33 #include <pwd.h>
  34 #include <ctype.h>
  35 #include <string.h>
  36 #include <libintl.h>
  37 #include <errno.h>
  38 #include <zone.h>
  39 #include <libzonecfg.h>
  40 #include <wchar.h>
  41 
  42 #include "prstat.h"
  43 #include "prutil.h"
  44 #include "prtable.h"
  45 
  46 static plwp_t   *plwp_tbl[PLWP_TBL_SZ];
  47 
  48 void
  49 lwpid_init()
  50 {
  51         (void) memset(&plwp_tbl, 0, sizeof (plwp_t *) * PLWP_TBL_SZ);
  52 }
  53 
  54 static uid_t
  55 pwd_getid(char *name)
  56 {
  57         struct passwd *pwd;
  58 
  59         if ((pwd = getpwnam(name)) == NULL)
  60                 Die(gettext("invalid user name: %s\n"), name);
  61         return (pwd->pw_uid);
  62 }
  63 
  64 void
  65 pwd_getname(uid_t uid, char *name, size_t length, int noresolve,
  66     int trunc, size_t width)
  67 {
  68         struct passwd *pwd;
  69         size_t n;
  70 
  71         if (noresolve || (pwd = getpwuid(uid)) == NULL) {
  72                 n = snprintf(NULL, 0, "%u", uid);
  73                 if (trunc && n > width)
  74                         (void) snprintf(name, length, "%.*u%c",
  75                             width - 1, uid, '*');
  76                 else
  77                         (void) snprintf(name, length, "%u", uid);
  78         } else {
  79                 n = mbstowcs(NULL, pwd->pw_name, 0);
  80                 if (n == (size_t)-1)
  81                         (void) snprintf(name, length, "%s", "ERROR");
  82                 else if (trunc && n > width)
  83                         (void) snprintf(name, length, "%.*s%c",
  84                             width - 1, pwd->pw_name, '*');
  85                 else
  86                         (void) snprintf(name, length, "%s", pwd->pw_name);
  87         }
  88 }
  89 
  90 void
  91 add_uid(uidtbl_t *tbl, char *name)
  92 {
  93         uid_t *uid;
  94 
  95         if (tbl->n_size == tbl->n_nent) { /* reallocation */
  96                 if ((tbl->n_size *= 2) == 0)
  97                         tbl->n_size = 4;     /* first time */
  98                 tbl->n_list = Realloc(tbl->n_list, tbl->n_size*sizeof (uid_t));
  99         }
 100 
 101         uid = &tbl->n_list[tbl->n_nent++];
 102 
 103         if (isdigit(name[0])) {
 104                 *uid = Atoi(name);
 105         } else {