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/newtask/newtask.c
          +++ new/usr/src/cmd/newtask/newtask.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright (c) 2013 Gary Mills
       24 + *
  23   25   * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24   26   * Use is subject to license terms.
  25   27   */
  26   28  
  27      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  28      -
  29   29  #include <sys/types.h>
  30   30  #include <sys/task.h>
  31   31  
  32   32  #include <alloca.h>
  33   33  #include <libproc.h>
  34   34  #include <libintl.h>
  35   35  #include <libgen.h>
  36   36  #include <limits.h>
  37   37  #include <project.h>
  38   38  #include <pwd.h>
  39   39  #include <secdb.h>
  40   40  #include <stdio.h>
  41   41  #include <stdlib.h>
  42   42  #include <string.h>
  43   43  #include <sys/varargs.h>
  44   44  #include <unistd.h>
  45   45  #include <errno.h>
  46   46  #include <signal.h>
  47   47  #include <priv_utils.h>
  48   48  
       49 +#ifdef  LOGNAME_MAX_ILLUMOS
       50 +#define _LOGNAME_MAX    LOGNAME_MAX_ILLUMOS
       51 +#else /* LOGNAME_MAX_ILLUMOS */
       52 +#define _LOGNAME_MAX    LOGNAME_MAX
       53 +#endif /* LOGNAME_MAX_ILLUMOS */
       54 +
  49   55  #include "utils.h"
  50   56  
  51   57  #define OPTIONS_STRING  "Fc:lp:v"
  52   58  #define NENV            8
  53   59  #define ENVSIZE         255
  54   60  #define PATH            "PATH=/usr/bin"
  55   61  #define SUPATH          "PATH=/usr/sbin:/usr/bin"
  56   62  #define SHELL           "/usr/bin/sh"
  57   63  #define SHELL2          "/sbin/sh"
  58   64  #define TIMEZONEFILE    "/etc/default/init"
↓ open down ↓ 588 lines elided ↑ open up ↑
 647  653  }
 648  654  
 649  655  /*
 650  656   * Given the input arguments, return the passwd structure that matches best.
 651  657   * Also, since we use getpwnam() and friends, subsequent calls to this
 652  658   * function will re-use the memory previously returned.
 653  659   */
 654  660  static struct passwd *
 655  661  match_user(uid_t uid, char *projname, int is_my_uid)
 656  662  {
 657      -        char prbuf[PROJECT_BUFSZ], username[LOGNAME_MAX+1];
      663 +        char prbuf[PROJECT_BUFSZ], username[_LOGNAME_MAX+1];
 658  664          struct project prj;
 659  665          char *tmp_name;
 660  666          struct passwd *pw = NULL;
 661  667  
 662  668          /*
 663  669           * In order to allow users with the same UID but distinguishable
 664  670           * user names to be in different projects we play a guessing
 665  671           * game of which username is most appropriate. If we're checking
 666  672           * for the uid of the calling process, the login name is a
 667  673           * good starting point.
↓ open down ↓ 21 lines elided ↑ open up ↑
 689  695           * If projname wasn't supplied, we've done our best, so just return
 690  696           * what we've got now. Alternatively, if newtask's invoker has
 691  697           * superuser privileges, return the pw structure we've got now, with
 692  698           * no further checking from inproj(). Superuser should be able to
 693  699           * join any project, and the subsequent call to setproject() will
 694  700           * allow this.
 695  701           */
 696  702          if (projname == NULL || getuid() == (uid_t)0)
 697  703                  return (pw);
 698  704  
 699      -        (void) strcpy(username, pw->pw_name);
      705 +        (void) strncpy(username, pw->pw_name, sizeof (username) - 1);
      706 +        username[sizeof (username) - 1] = '\0';
 700  707  
 701  708          if (inproj(username, projname, prbuf, PROJECT_BUFSZ) == 0) {
 702  709                  char **u;
 703  710                  tmp_name = NULL;
 704  711  
 705  712                  /*
 706  713                   * If the previous guesses didn't work, walk through all
 707  714                   * project members and test for UID-equivalence.
 708  715                   */
 709  716  
↓ open down ↓ 94 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX