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

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/grpck/grpck.c
          +++ new/usr/src/cmd/grpck/grpck.c
↓ open down ↓ 11 lines elided ↑ open up ↑
  12   12   *
  13   13   * When distributing Covered Code, include this CDDL HEADER in each
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
       22 + * Copyright (c) 2013 Gary Mills
       23 + *
  22   24   * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23   25   * Use is subject to license terms.
  24   26   */
  25   27  
  26   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  27   29  /*        All Rights Reserved   */
  28   30  
  29   31  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   32  #include <sys/param.h>
  33   33  #include <sys/types.h>
  34   34  #include <unistd.h>
  35   35  #include <stdlib.h>
  36   36  #include <stdio.h>
  37   37  #include <string.h>
  38   38  #include <ctype.h>
  39   39  #include <pwd.h>
  40   40  #include <errno.h>
  41   41  #include <locale.h>
↓ open down ↓ 6 lines elided ↑ open up ↑
  48   48  #define BADGID  "Invalid GID"
  49   49  #define NULLNAME "Null login name"
  50   50  #define NOTFOUND "Logname not found in password file"
  51   51  #define DUPNAME "Duplicate logname entry"
  52   52  #define DUPNAME2 "Duplicate logname entry (gid first occurs in passwd entry)"
  53   53  #define NOMEM   "Out of memory"
  54   54  #define NGROUPS "Maximum groups exceeded for logname "
  55   55  #define BLANKLINE "Blank line detected. Please remove line"
  56   56  #define LONGNAME  "Group name too long"
  57   57  
       58 +#ifdef  LOGNAME_MAX_ILLUMOS
       59 +#define _LOGNAME_MAX    LOGNAME_MAX_ILLUMOS
       60 +#else /* LOGNAME_MAX_ILLUMOS */
       61 +#define _LOGNAME_MAX    LOGNAME_MAX
       62 +#endif /* LOGNAME_MAX_ILLUMOS */
       63 +
  58   64  int eflag, badchar, baddigit, badlognam, colons, len;
  59   65  static int longnam = 0;
  60   66  int code;
  61   67  
  62   68  #define MYBUFSIZE (LINE_MAX)    /* max line length including newline and null */
  63   69  #define NUM_COLONS      3
  64   70  
  65   71  char *buf;
  66   72  char *nptr;
  67   73  char *cptr;
↓ open down ↓ 53 lines elided ↑ open up ↑
 121  127  
 122  128          if (argc == 1)
 123  129                  argv[1] = "/etc/group";
 124  130          else if (argc != 2) {
 125  131                  fprintf(stderr, gettext("usage: %s filename\n"), *argv);
 126  132                  exit(1);
 127  133          }
 128  134  
 129  135          if ((fptr = fopen(argv[1], "r")) == NULL) {
 130  136                  fprintf(stderr, gettext("cannot open file %s: %s\n"), argv[1],
 131      -                        strerror(errno));
      137 +                    strerror(errno));
 132  138                  exit(1);
 133  139          }
 134  140  
 135  141  #ifdef ORIG_SVR4
 136  142          while ((pwp = getpwent()) != NULL) {
 137  143                  t = (struct node *)emalloc(sizeof (*t) + strlen(pwp->pw_name));
 138  144                  t->next = root;
 139  145                  root = t;
 140  146                  strcpy(t->user, pwp->pw_name);
 141  147                  t->ngroups = 1;
 142  148                  if (!ngroups_max)
 143  149                          t->groups = NULL;
 144  150                  else {
 145  151                          t->groups = (struct group *)
 146      -                                emalloc(sizeof (struct group));
      152 +                            emalloc(sizeof (struct group));
 147  153                          t->groups->grp = pwp->pw_gid;
 148  154                          t->groups->cnt = 1;
 149  155                          t->groups->nxt = NULL;
 150  156                  }
 151  157          }
 152  158  #endif
 153  159  
 154  160          bufsize = MYBUFSIZE;
 155  161          if ((buf = malloc(bufsize)) == NULL) {
 156  162                  (void) fprintf(stderr, gettext(NOMEM));
↓ open down ↓ 21 lines elided ↑ open up ↑
 178  184                  /* Report error to be consistent with libc */
 179  185                  if ((buf_len + 1) > LINE_MAX)
 180  186                          error(TOOLONG);
 181  187  
 182  188                  lineno++;
 183  189                  if (buf[0] == '\n')    /* blank lines are ignored */
 184  190                  {
 185  191                          code = 1;               /* exit with error code = 1 */
 186  192                          eflag = 0;      /* force print of "blank" line */
 187  193                          fprintf(stderr, "\n%s %d\n", gettext(BLANKLINE),
 188      -                                lineno);
      194 +                            lineno);
 189  195                          continue;
 190  196                  }
 191  197  
 192  198                  if (buf[buf_len - 1] == '\n') {
 193  199                          if ((tmpbuf = strdup(buf)) == NULL) {
 194  200                                  (void) fprintf(stderr, gettext(NOMEM));
 195  201                                  exit(1);
 196  202                          }
 197  203                          tmpbuf[buf_len - 1] = ',';
 198  204                  } else {
↓ open down ↓ 41 lines elided ↑ open up ↑
 240  246                          continue;
 241  247                  }
 242  248  
 243  249                  /* check to see that group name is at least 1 character */
 244  250                  /* and that all characters are lowrcase or digits.      */
 245  251  
 246  252                  if (buf[0] == ':')
 247  253                          error(NONAME);
 248  254                  else {
 249  255                          for (i = 0; buf[i] != ':'; i++) {
 250      -                                if (i >= LOGNAME_MAX)
      256 +                                if (i >= _LOGNAME_MAX)
 251  257                                          longnam++;
 252  258                                  if (!(islower(buf[i]) || isdigit(buf[i])))
 253  259                                          badchar++;
 254  260                          }
 255  261                          if (longnam > 0)
 256  262                                  error(LONGNAME);
 257  263                          if (badchar > 0)
 258  264                                  error(BADNAME);
 259  265                  }
 260  266  
↓ open down ↓ 48 lines elided ↑ open up ↑
 309  315                                  if ((pwp = getpwnam(nptr)) == NULL) {
 310  316  #endif
 311  317                                          badlognam++;
 312  318                                          error(NOTFOUND);
 313  319                                          goto getnext;
 314  320  #ifndef ORIG_SVR4
 315  321                                  }
 316  322  
 317  323                                  /* Usrname found, so add entry to user-list */
 318  324                                  t = (struct node *)
 319      -                                        emalloc(sizeof (*t) + strlen(nptr));
      325 +                                    emalloc(sizeof (*t) + strlen(nptr));
 320  326                                  t->next = root;
 321  327                                  root = t;
 322  328                                  strcpy(t->user, nptr);
 323  329                                  t->ngroups = 1;
 324  330                                  if (!ngroups_max)
 325  331                                          t->groups = NULL;
 326  332                                  else {
 327  333                                          t->groups = (struct group *)
 328      -                                                emalloc(sizeof (struct group));
      334 +                                            emalloc(sizeof (struct group));
 329  335                                          t->groups->grp = pwp->pw_gid;
 330  336                                          t->groups->cnt = 1;
 331  337                                          t->groups->nxt = NULL;
 332  338                                  }
 333  339                          }
 334  340  #endif
 335  341                          if (!ngroups_max)
 336  342                                  goto getnext;
 337  343  
 338  344                          t->ngroups++;
↓ open down ↓ 28 lines elided ↑ open up ↑
 367  373  
 368  374          if (ngroups == 0) {
 369  375                  fprintf(stderr, gettext("Group file '%s' is empty\n"), argv[1]);
 370  376                  code = 1;
 371  377          }
 372  378  
 373  379          if (ngroups_max) {
 374  380                  for (t = root; t != NULL; t = t->next) {
 375  381                          if (t->ngroups > ngroups_max) {
 376  382                                  fprintf(stderr, "\n\n%s%s (%d)\n",
 377      -                                NGROUPS, t->user, t->ngroups);
      383 +                                    NGROUPS, t->user, t->ngroups);
 378  384                                  code = 1;
 379  385                          }
 380  386                  }
 381  387          }
 382  388          return (code);
 383  389  }
 384  390  
 385  391  /*      Error printing routine  */
 386  392  
 387  393  void
↓ open down ↓ 29 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX