xref: /minix3/usr.bin/su/suutil.c (revision 4de51eedad5c2244aac7f2cacbeeef2a2a8c0591)
1*4de51eedSBen Gras /*	$NetBSD: suutil.c,v 1.1 2007/10/17 21:05:39 christos Exp $	*/
2*4de51eedSBen Gras 
3*4de51eedSBen Gras /*
4*4de51eedSBen Gras  * Copyright (c) 1988 The Regents of the University of California.
5*4de51eedSBen Gras  * All rights reserved.
6*4de51eedSBen Gras  *
7*4de51eedSBen Gras  * Redistribution and use in source and binary forms, with or without
8*4de51eedSBen Gras  * modification, are permitted provided that the following conditions
9*4de51eedSBen Gras  * are met:
10*4de51eedSBen Gras  * 1. Redistributions of source code must retain the above copyright
11*4de51eedSBen Gras  *    notice, this list of conditions and the following disclaimer.
12*4de51eedSBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
13*4de51eedSBen Gras  *    notice, this list of conditions and the following disclaimer in the
14*4de51eedSBen Gras  *    documentation and/or other materials provided with the distribution.
15*4de51eedSBen Gras  * 3. Neither the name of the University nor the names of its contributors
16*4de51eedSBen Gras  *    may be used to endorse or promote products derived from this software
17*4de51eedSBen Gras  *    without specific prior written permission.
18*4de51eedSBen Gras  *
19*4de51eedSBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*4de51eedSBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*4de51eedSBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*4de51eedSBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*4de51eedSBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*4de51eedSBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*4de51eedSBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*4de51eedSBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*4de51eedSBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*4de51eedSBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*4de51eedSBen Gras  * SUCH DAMAGE.
30*4de51eedSBen Gras  */
31*4de51eedSBen Gras #include <sys/cdefs.h>
32*4de51eedSBen Gras __RCSID("$NetBSD: suutil.c,v 1.1 2007/10/17 21:05:39 christos Exp $");
33*4de51eedSBen Gras 
34*4de51eedSBen Gras #include <sys/param.h>
35*4de51eedSBen Gras #include <stdio.h>
36*4de51eedSBen Gras #include <unistd.h>
37*4de51eedSBen Gras #include <string.h>
38*4de51eedSBen Gras #include "suutil.h"
39*4de51eedSBen Gras 
40*4de51eedSBen Gras int
chshell(const char * sh)41*4de51eedSBen Gras chshell(const char *sh)
42*4de51eedSBen Gras {
43*4de51eedSBen Gras 	const char *cp;
44*4de51eedSBen Gras 
45*4de51eedSBen Gras 	setusershell();
46*4de51eedSBen Gras 	while ((cp = getusershell()) != NULL)
47*4de51eedSBen Gras 		if (strcmp(cp, sh) == 0)
48*4de51eedSBen Gras 			return 1;
49*4de51eedSBen Gras 	return 0;
50*4de51eedSBen Gras }
51*4de51eedSBen Gras 
52*4de51eedSBen Gras char *
ontty(void)53*4de51eedSBen Gras ontty(void)
54*4de51eedSBen Gras {
55*4de51eedSBen Gras 	char *p;
56*4de51eedSBen Gras 	static char buf[MAXPATHLEN + 4];
57*4de51eedSBen Gras 
58*4de51eedSBen Gras 	buf[0] = 0;
59*4de51eedSBen Gras 	if ((p = ttyname(STDERR_FILENO)) != NULL)
60*4de51eedSBen Gras 		(void)snprintf(buf, sizeof buf, " on %s", p);
61*4de51eedSBen Gras 	return buf;
62*4de51eedSBen Gras }
63*4de51eedSBen Gras 
64