xref: /titanic_41/usr/src/cmd/sendmail/aux/mailq.c (revision a6d42e7d71324c5193c3b94d57d96ba2925d52e1)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  *
22  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <auth_attr.h>
31 #include <secdb.h>
32 #include <pwd.h>
33 #include <unistd.h>
34 #include <sysexits.h>
35 #include <errno.h>
36 #include <auth_list.h>
37 
38 #define	_PATH_SENDMAIL_BIN	"/usr/lib/sendmail"
39 
40 int
41 main(int argc, char *argv[], char *envp[])
42 {
43 	struct passwd *pw = getpwuid(getuid());
44 	char **newargv;
45 	int j;
46 
47 	if (pw && chkauthattr(MAILQ_AUTH, pw->pw_name)) {
48 		newargv = (char **)malloc((argc + 1) * sizeof (char *));
49 		if (newargv == NULL)
50 			exit(EX_UNAVAILABLE);
51 		newargv[0] = _PATH_SENDMAIL_BIN;
52 		newargv[1] = "-bp";
53 		for (j = 1; j <= argc; j++)
54 			newargv[j + 1] = argv[j];
55 		(void) execve(_PATH_SENDMAIL_BIN, newargv, envp);
56 		perror("Cannot exec " _PATH_SENDMAIL_BIN);
57 		exit(EX_OSERR);
58 	}
59 	(void) fputs("No authorization to run mailq; "
60 	    "see mailq(1) for details.\n", stderr);
61 	return (EX_NOPERM);
62 }
63