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 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  27 /*        All Rights Reserved   */
  28 
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 #include <sys/types.h>
  33 #include <sys/param.h>
  34 #include <sys/signal.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/stat.h>
  37 #include <stdio.h>
  38 #include <stdlib.h>
  39 #include <string.h>
  40 #include <ctype.h>
  41 #include <locale.h>
  42 #include <errno.h>
  43 #include <unistd.h>

  44 






  45 #define ERROR1  "Too many/few fields"
  46 #define ERROR2  "Bad character(s) in logname"
  47 #define ERROR2a "First char in logname not alphabetic"
  48 #define ERROR2b "Logname field NULL"
  49 #define ERROR2c "Logname contains no lower-case letters"
  50 #define ERROR3  "Logname too long/short"
  51 #define ERROR4  "Invalid UID"
  52 #define ERROR5  "Invalid GID"
  53 #define ERROR6  "Login directory not found"
  54 #define ERROR6a "Login directory null"
  55 #define ERROR7  "Optional shell file not found"
  56 
  57 static int eflag, code = 0;
  58 static int badc;
  59 static int lc;
  60 static char buf[512];
  61 static void error(char *);
  62 
  63 int
  64 main(int argc, char **argv)


 146                         error(ERROR2b);
 147                 else if (!isalpha(buf[0]))
 148                         error(ERROR2a);
 149 
 150                 for (i = 0; buf[i] != ':'; i++) {
 151                         if (!isalnum(buf[i]) &&
 152                                 buf[i] != '_' &&
 153                                 buf[i] != '-' &&
 154                                 buf[i] != '.')
 155                                 badc++;
 156                         else if (islower(buf[i]))
 157                                 lc++;
 158                 }
 159                 if (lc == 0)
 160                         error(ERROR2c);
 161                 if (badc > 0)
 162                         error(ERROR2);
 163 
 164                 /* Check for valid number of characters in logname */
 165 
 166                 if (i <= 0 || i > 8)
 167                         error(ERROR3);
 168 
 169                 /* Check that UID is numeric and <= MAXUID */
 170 
 171                 errno = 0;
 172                 str = &buf[delim[1] + 1];
 173                 uid = strtol(str, &lastc, 10);
 174                 if (lastc != str + (delim[2] - delim[1]) - 1 ||
 175                     uid > MAXUID || errno == ERANGE)
 176                         error(ERROR4);
 177 
 178                 /* Check that GID is numeric and <= MAXUID */
 179 
 180                 errno = 0;
 181                 str = &buf[delim[2] + 1];
 182                 gid = strtol(str, &lastc, 10);
 183                 if (lastc != str + (delim[3] - delim[2]) - 1 ||
 184                     gid > MAXUID || errno == ERANGE)
 185                         error(ERROR5);
 186 




   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 2007 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  */
  27 
  28 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T     */
  29 /*        All Rights Reserved   */
  30 
  31 


  32 #include <sys/types.h>
  33 #include <sys/param.h>
  34 #include <sys/signal.h>
  35 #include <sys/sysmacros.h>
  36 #include <sys/stat.h>
  37 #include <stdio.h>
  38 #include <stdlib.h>
  39 #include <string.h>
  40 #include <ctype.h>
  41 #include <locale.h>
  42 #include <errno.h>
  43 #include <unistd.h>
  44 #include <limits.h>
  45 
  46 #ifdef  LOGNAME_MAX_ILLUMOS
  47 #define _LOGNAME_MAX    LOGNAME_MAX_ILLUMOS
  48 #else /* LOGNAME_MAX_ILLUMOS */
  49 #define _LOGNAME_MAX    LOGNAME_MAX
  50 #endif /* LOGNAME_MAX_ILLUMOS */
  51 
  52 #define ERROR1  "Too many/few fields"
  53 #define ERROR2  "Bad character(s) in logname"
  54 #define ERROR2a "First char in logname not alphabetic"
  55 #define ERROR2b "Logname field NULL"
  56 #define ERROR2c "Logname contains no lower-case letters"
  57 #define ERROR3  "Logname too long/short"
  58 #define ERROR4  "Invalid UID"
  59 #define ERROR5  "Invalid GID"
  60 #define ERROR6  "Login directory not found"
  61 #define ERROR6a "Login directory null"
  62 #define ERROR7  "Optional shell file not found"
  63 
  64 static int eflag, code = 0;
  65 static int badc;
  66 static int lc;
  67 static char buf[512];
  68 static void error(char *);
  69 
  70 int
  71 main(int argc, char **argv)


 153                         error(ERROR2b);
 154                 else if (!isalpha(buf[0]))
 155                         error(ERROR2a);
 156 
 157                 for (i = 0; buf[i] != ':'; i++) {
 158                         if (!isalnum(buf[i]) &&
 159                                 buf[i] != '_' &&
 160                                 buf[i] != '-' &&
 161                                 buf[i] != '.')
 162                                 badc++;
 163                         else if (islower(buf[i]))
 164                                 lc++;
 165                 }
 166                 if (lc == 0)
 167                         error(ERROR2c);
 168                 if (badc > 0)
 169                         error(ERROR2);
 170 
 171                 /* Check for valid number of characters in logname */
 172 
 173                 if (i <= 0 || i > _LOGNAME_MAX)
 174                         error(ERROR3);
 175 
 176                 /* Check that UID is numeric and <= MAXUID */
 177 
 178                 errno = 0;
 179                 str = &buf[delim[1] + 1];
 180                 uid = strtol(str, &lastc, 10);
 181                 if (lastc != str + (delim[2] - delim[1]) - 1 ||
 182                     uid > MAXUID || errno == ERANGE)
 183                         error(ERROR4);
 184 
 185                 /* Check that GID is numeric and <= MAXUID */
 186 
 187                 errno = 0;
 188                 str = &buf[delim[2] + 1];
 189                 gid = strtol(str, &lastc, 10);
 190                 if (lastc != str + (delim[3] - delim[2]) - 1 ||
 191                     gid > MAXUID || errno == ERANGE)
 192                         error(ERROR5);
 193