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>
↓ open down ↓ 608 lines elided ↑ open up ↑
 647  647  }
 648  648  
 649  649  /*
 650  650   * Given the input arguments, return the passwd structure that matches best.
 651  651   * Also, since we use getpwnam() and friends, subsequent calls to this
 652  652   * function will re-use the memory previously returned.
 653  653   */
 654  654  static struct passwd *
 655  655  match_user(uid_t uid, char *projname, int is_my_uid)
 656  656  {
 657      -        char prbuf[PROJECT_BUFSZ], username[LOGNAME_MAX+1];
      657 +        char prbuf[PROJECT_BUFSZ], username[LOGNAME_MAX_ILLUMOS+1];
 658  658          struct project prj;
 659  659          char *tmp_name;
 660  660          struct passwd *pw = NULL;
 661  661  
 662  662          /*
 663  663           * In order to allow users with the same UID but distinguishable
 664  664           * user names to be in different projects we play a guessing
 665  665           * game of which username is most appropriate. If we're checking
 666  666           * for the uid of the calling process, the login name is a
 667  667           * good starting point.
↓ open down ↓ 21 lines elided ↑ open up ↑
 689  689           * If projname wasn't supplied, we've done our best, so just return
 690  690           * what we've got now. Alternatively, if newtask's invoker has
 691  691           * superuser privileges, return the pw structure we've got now, with
 692  692           * no further checking from inproj(). Superuser should be able to
 693  693           * join any project, and the subsequent call to setproject() will
 694  694           * allow this.
 695  695           */
 696  696          if (projname == NULL || getuid() == (uid_t)0)
 697  697                  return (pw);
 698  698  
 699      -        (void) strcpy(username, pw->pw_name);
      699 +        (void) strncpy(username, pw->pw_name, sizeof (username) - 1);
      700 +        username[sizeof (username) - 1] = '\0';
 700  701  
 701  702          if (inproj(username, projname, prbuf, PROJECT_BUFSZ) == 0) {
 702  703                  char **u;
 703  704                  tmp_name = NULL;
 704  705  
 705  706                  /*
 706  707                   * If the previous guesses didn't work, walk through all
 707  708                   * project members and test for UID-equivalence.
 708  709                   */
 709  710  
↓ open down ↓ 94 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX