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/oamuser/lib/vlogin.c
+++ new/usr/src/cmd/oamuser/lib/vlogin.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
↓ 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 (c) 1997, by Sun Microsystems, Inc.
24 26 * All rights reserved.
25 27 */
26 28
27 29 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 30 /* All Rights Reserved */
29 31
30 -
31 -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
32 -
33 32 /*LINTLIBRARY*/
34 33
35 34 #include <sys/types.h>
36 35 #include <stdio.h>
37 36 #include <ctype.h>
38 37 #include <userdefs.h>
39 38 #include <users.h>
39 +#include <deflt.h>
40 40 #include <limits.h>
41 41
42 +/* Defaults file */
43 +#define DEFAULT_USERADD "/etc/default/useradd"
44 +
45 +/* Traditional length limit */
46 +#define TRAD_LEN_MAX 8
47 +
42 48 /*
43 49 * validate string given as login name.
44 50 */
45 51 int
46 52 valid_login(char *login, struct passwd **pptr, int *warning)
47 53 {
48 54 struct passwd *t_pptr;
49 55 char *ptr = login;
50 56 int bad1char, badc, clower, len;
51 57 char c;
58 + char action;
52 59
53 60 len = 0; clower = 0; badc = 0; bad1char = 0;
54 61 *warning = 0;
55 62 if (!login || !*login)
56 63 return (INVALID);
57 64
58 65 c = *ptr;
59 66 if (!isalpha(c))
60 67 bad1char++;
61 68 for (; c != NULL; ptr++, c = *ptr) {
62 69 len++;
63 70 if (!isprint(c) || (c == ':') || (c == '\n'))
64 71 return (INVALID);
65 72 if (!isalnum(c) && c != '_' && c != '-' && c != '.')
66 73 badc++;
67 74 if (islower(c))
68 75 clower++;
69 76 }
70 77
71 - /*
72 - * XXX length checking causes some operational/compatibility problem.
73 - * This has to be revisited in the future as ARC/standards issue.
74 - */
78 + action = 'w';
79 + if (defopen(DEFAULT_USERADD) == 0) {
80 + char *defptr;
81 +
82 + if ((defptr = defread("EXCEED_TRAD=")) != NULL) {
83 + char let = tolower(*defptr);
84 +
85 + switch (let) {
86 + case 'w': /* warning */
87 + case 'e': /* error */
88 + case 's': /* silent */
89 + action = let;
90 + break;
91 + }
92 + }
93 + (void) defopen((char *)NULL);
94 + }
95 +
75 96 if (len > LOGNAME_MAX)
76 - *warning = *warning | WARN_NAME_TOO_LONG;
97 + return (LONGNAME);
98 +
99 + if (len > TRAD_LEN_MAX) {
100 + if (action == 'w')
101 + *warning = *warning | WARN_NAME_TOO_LONG;
102 + else if (action == 'e')
103 + return (LONGNAME);
104 + }
105 +
77 106 if (clower == 0)
78 107 *warning = *warning | WARN_NO_LOWERCHAR;
79 108 if (badc != 0)
80 109 *warning = *warning | WARN_BAD_LOGNAME_CHAR;
81 110 if (bad1char != 0)
82 111 *warning = *warning | WARN_BAD_LOGNAME_FIRST;
83 112
84 113 if ((t_pptr = getpwnam(login)) != NULL) {
85 114 if (pptr) *pptr = t_pptr;
86 115 return (NOTUNIQUE);
87 116 }
88 117 return (UNIQUE);
89 118 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX