vlogin.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry/*
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * CDDL HEADER START
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry *
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * The contents of this file are subject to the terms of the
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * Common Development and Distribution License, Version 1.0 only
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * (the "License"). You may not use this file except in compliance
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * with the License.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb *
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * or http://www.opensolaris.org/os/licensing.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * See the License for the specific language governing permissions
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * and limitations under the License.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb *
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * When distributing Covered Code, include this CDDL HEADER in each
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * If applicable, add the following below this CDDL HEADER, with the
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * fields enclosed by brackets "[]" replaced with your own identifying
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * information: Portions Copyright [yyyy] [name of copyright owner]
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb *
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * CDDL HEADER END
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb/*
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * Copyright (c) 1997, by Sun Microsystems, Inc.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * All rights reserved.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb/* All Rights Reserved */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb/*LINTLIBRARY*/
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#include <sys/types.h>
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#include <stdio.h>
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#include <ctype.h>
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#include <userdefs.h>
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry#include <users.h>
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb#include <limits.h>
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb/*
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb * validate string given as login name.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb */
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtbint
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtbvalid_login(char *login, struct passwd **pptr, int *warning)
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb{
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb struct passwd *t_pptr;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb char *ptr = login;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb int bad1char, badc, clower, len;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb char c;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb len = 0; clower = 0; badc = 0; bad1char = 0;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb *warning = 0;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (!login || !*login)
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb return (INVALID);
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb c = *ptr;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (!isalpha(c))
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry bad1char++;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb for (; c != NULL; ptr++, c = *ptr) {
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb len++;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (!isprint(c) || (c == ':') || (c == '\n'))
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb return (INVALID);
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (!isalnum(c) && c != '_' && c != '-' && c != '.')
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb badc++;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (islower(c))
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb clower++;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb }
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry /*
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * XXX length checking causes some operational/compatibility problem.
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry * This has to be revisited in the future as ARC/standards issue.
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb */
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry if (len > LOGNAME_MAX)
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry *warning = *warning | WARN_NAME_TOO_LONG;
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry if (clower == 0)
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry *warning = *warning | WARN_NO_LOWERCHAR;
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry if (badc != 0)
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry *warning = *warning | WARN_BAD_LOGNAME_CHAR;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if (bad1char != 0)
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb *warning = *warning | WARN_BAD_LOGNAME_FIRST;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb if ((t_pptr = getpwnam(login)) != NULL) {
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry if (pptr) *pptr = t_pptr;
ab9b2e153c3a9a2b1141fefa87925b1a9beb1236gtb return (NOTUNIQUE);
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry }
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry return (UNIQUE);
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry}
ba7b222e36bac28710a7f43739283302b617e7f5Glenn Barry