10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*8913SJohn.Beck@Sun.COM * Common Development and Distribution License (the "License").
6*8913SJohn.Beck@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
20*8913SJohn.Beck@Sun.COM */
21*8913SJohn.Beck@Sun.COM
22*8913SJohn.Beck@Sun.COM /*
23*8913SJohn.Beck@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <stdio.h>
280Sstevel@tonic-gate #include <stdlib.h>
290Sstevel@tonic-gate #include <auth_attr.h>
300Sstevel@tonic-gate #include <secdb.h>
310Sstevel@tonic-gate #include <pwd.h>
320Sstevel@tonic-gate #include <unistd.h>
330Sstevel@tonic-gate #include <sysexits.h>
340Sstevel@tonic-gate #include <errno.h>
350Sstevel@tonic-gate #include <auth_list.h>
360Sstevel@tonic-gate
370Sstevel@tonic-gate #define _PATH_SENDMAIL_BIN "/usr/lib/sendmail"
380Sstevel@tonic-gate
390Sstevel@tonic-gate int
main(int argc,char * argv[],char * envp[])400Sstevel@tonic-gate main(int argc, char *argv[], char *envp[])
410Sstevel@tonic-gate {
420Sstevel@tonic-gate struct passwd *pw = getpwuid(getuid());
430Sstevel@tonic-gate char **newargv;
440Sstevel@tonic-gate int j;
450Sstevel@tonic-gate
460Sstevel@tonic-gate if (pw && chkauthattr(MAILQ_AUTH, pw->pw_name)) {
47*8913SJohn.Beck@Sun.COM /* The extra 2 is 1 for the "-bp" + 1 for the terminator. */
48*8913SJohn.Beck@Sun.COM newargv = (char **)malloc((argc + 2) * sizeof (char *));
490Sstevel@tonic-gate if (newargv == NULL)
500Sstevel@tonic-gate exit(EX_UNAVAILABLE);
510Sstevel@tonic-gate newargv[0] = _PATH_SENDMAIL_BIN;
520Sstevel@tonic-gate newargv[1] = "-bp";
530Sstevel@tonic-gate for (j = 1; j <= argc; j++)
540Sstevel@tonic-gate newargv[j + 1] = argv[j];
550Sstevel@tonic-gate (void) execve(_PATH_SENDMAIL_BIN, newargv, envp);
560Sstevel@tonic-gate perror("Cannot exec " _PATH_SENDMAIL_BIN);
570Sstevel@tonic-gate exit(EX_OSERR);
580Sstevel@tonic-gate }
590Sstevel@tonic-gate (void) fputs("No authorization to run mailq; "
600Sstevel@tonic-gate "see mailq(1) for details.\n", stderr);
610Sstevel@tonic-gate return (EX_NOPERM);
620Sstevel@tonic-gate }
63