newgrp.c revision 16cac7864bfb2afb3e274fea3fbaf50e8f154079
/*
* 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"
/*
* newgrp [-l | -] [group]
*
* rules
* if no arg, group id in password file is used
* else if group id == id in password file
* else if login name is in member list
* else if password is present and user knows it
* else too bad
*/
#include <stdio.h>
#include <pwd.h>
#include <grp.h>
#include <crypt.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>
#include <syslog.h>
#include <unistd.h>
#include <bsm/adt_event.h>
#define ELIM 128
char PW[] = "newgrp: Password: ";
char NG[] = "newgrp: Sorry";
char PD[] = "newgrp: Permission denied";
char UG[] = "newgrp: Unknown group";
char NS[] = "newgrp: You have no shell";
char *homedir;
char *logname;
extern char **environ;
void error(char *s) __NORETURN;
void warn(char *s);
void usage(void);
int
{
struct passwd *p;
int eflag = 0;
int flag;
#ifdef DEBUG
chroot(".");
#endif
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
endpwent();
switch (flag) {
case 'l':
eflag++;
break;
default:
usage();
break;
}
}
if (eflag)
usage();
eflag++;
argv++;
--argc;
}
if (argc > 0)
error("newgrp: Memory request failed");
error("newgrp: Memory request failed");
if (!*p->pw_shell) {
} else {
}
}
if (eflag) {
char *simple;
error("newgrp: Memory request failed");
error("newgrp: Memory request failed");
if (uid == 0)
else
error("newgrp: Memory request failed");
if (simple) {
}
}
else
return (1);
}
void
warn(char *s)
{
}
void
error(char *s)
{
warn(s);
exit(1);
}
void
{
"adt_start_session(ADT_newgrp_login): %m");
}
"adt_alloc_event(ADT_newgrp_login): %m");
} else {
}
"adt_put_event(ADT_newgrp, %d): %m", sorf);
}
(void) adt_end_session(ah);
}
char *gname;
struct passwd *p;
{
char **t;
struct group *g;
endgrent();
if (g == NULL) {
return (getgid());
}
return (g->gr_gid);
}
for (t = g->gr_mem; *t; ++t) {
return (g->gr_gid);
}
}
if (*g->gr_passwd) {
}
return (g->gr_gid);
}
}
return (getgid());
}
void
usage(void)
{
"usage: newgrp [-l | -] [group]\n"));
exit(2);
}