grpck.c revision f48205be61a214698b763ff550ab9e657525104c
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <pwd.h>
#include <errno.h>
#include <locale.h>
#include <limits.h>
#define TOOLONG "Line too long"
#define NONAME "No group name"
#define BADNAME "Bad character(s) in group name"
#define BADGID "Invalid GID"
#define NULLNAME "Null login name"
#define NOTFOUND "Logname not found in password file"
#define DUPNAME "Duplicate logname entry"
#define DUPNAME2 "Duplicate logname entry (gid first occurs in passwd entry)"
#define NOMEM "Out of memory"
#define NGROUPS "Maximum groups exceeded for logname "
#define BLANKLINE "Blank line detected. Please remove line"
#define LONGNAME "Group name too long"
static int longnam = 0;
int code;
#define NUM_COLONS 3
char *buf;
char *nptr;
char *cptr;
struct group {
int cnt;
};
struct node {
int ngroups;
char user[1];
};
void *
{
void *vp;
exit(1);
}
return (vp);
}
int
{
struct node *t;
int ngroups_max;
int ngroups = 0;
int listlen;
int i;
int lineno = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#define TEXT_DOMAIN "SYS_TEST"
#endif
(void) textdomain(TEXT_DOMAIN);
code = 0;
if (argc == 1)
else if (argc != 2) {
exit(1);
}
exit(1);
}
#ifdef ORIG_SVR4
root = t;
t->ngroups = 1;
if (!ngroups_max)
else {
}
}
#endif
exit(1);
}
buf_len = 0;
break;
exit(1);
}
}
if (buf_len == 0)
continue;
/* Report error to be consistent with libc */
lineno++;
{
eflag = 0; /* force print of "blank" line */
lineno);
continue;
}
exit(1);
}
} else {
exit(1);
}
}
colons = 0;
eflag = 0;
badchar = 0;
baddigit = 0;
badlognam = 0;
gid = 0;
ngroups++; /* Increment number of groups found */
/* Check that entry is not a nameservice redirection */
/*
* Should set flag here to allow special case checking
* in the rest of the code,
* but for now, we'll just ignore this entry.
*/
continue;
}
/* Check number of fields */
if (buf[i] == ':') {
if (++colons > NUM_COLONS)
break;
}
}
if (colons != NUM_COLONS) {
continue;
}
/* check to see that group name is at least 1 character */
/* and that all characters are lowrcase or digits. */
if (buf[0] == ':')
else {
for (i = 0; buf[i] != ':'; i++) {
if (i >= LOGNAME_MAX)
longnam++;
badchar++;
}
if (longnam > 0)
if (badchar > 0)
}
/* check that GID is numeric and <= 31 bits */
else {
baddigit++;
else if (baddigit == 0)
/* converts ascii GID to decimal */
}
if (baddigit > 0)
}
/* check that logname appears in the passwd file */
nptr++;
if (listlen)
nptr++;
continue;
}
break;
}
if (t == NULL) {
#ifndef ORIG_SVR4
/*
* User entry not found, so check if in
* password file
*/
#endif
badlognam++;
goto getnext;
#ifndef ORIG_SVR4
}
/* Usrname found, so add entry to user-list */
t = (struct node *)
root = t;
t->ngroups = 1;
if (!ngroups_max)
else {
}
}
#endif
if (!ngroups_max)
goto getnext;
t->ngroups++;
/*
* check for duplicate logname in group
*/
badlognam++;
else
}
goto getnext;
}
}
}
}
if (ngroups == 0) {
code = 1;
}
if (ngroups_max) {
if (t->ngroups > ngroups_max) {
code = 1;
}
}
}
return (code);
}
/* Error printing routine */
void
{
code = 1;
if (eflag == 0) {
eflag = 1;
}
if (longnam != 0) {
longnam = 0;
return;
}
if (badchar != 0) {
badchar = 0;
return;
} else if (baddigit != 0) {
baddigit = 0;
return;
} else if (badlognam != 0) {
badlognam = 0;
return;
} else {
return;
}
}