xref: /titanic_51/usr/src/cmd/sendmail/aux/mailq.c (revision 287247a826fa2ab8d01f6c8f276d405eb08420f8)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
525ccf314SJohn Beck  * Common Development and Distribution License (the "License").
625ccf314SJohn Beck  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate 
2225ccf314SJohn Beck /*
2325ccf314SJohn Beck  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2425ccf314SJohn Beck  * Use is subject to license terms.
2525ccf314SJohn Beck  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <stdlib.h>
297c478bd9Sstevel@tonic-gate #include <auth_attr.h>
307c478bd9Sstevel@tonic-gate #include <secdb.h>
317c478bd9Sstevel@tonic-gate #include <pwd.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <sysexits.h>
347c478bd9Sstevel@tonic-gate #include <errno.h>
357c478bd9Sstevel@tonic-gate #include <auth_list.h>
367c478bd9Sstevel@tonic-gate 
37*287247a8SAlexander Pyhalov #define	_PATH_SENDMAIL_BIN	"/usr/lib/smtp/sendmail/sendmail"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate int
407c478bd9Sstevel@tonic-gate main(int argc, char *argv[], char *envp[])
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate 	struct passwd *pw = getpwuid(getuid());
437c478bd9Sstevel@tonic-gate 	char **newargv;
447c478bd9Sstevel@tonic-gate 	int j;
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate 	if (pw && chkauthattr(MAILQ_AUTH, pw->pw_name)) {
4725ccf314SJohn Beck 		/* The extra 2 is 1 for the "-bp" + 1 for the terminator. */
4825ccf314SJohn Beck 		newargv = (char **)malloc((argc + 2) * sizeof (char *));
497c478bd9Sstevel@tonic-gate 		if (newargv == NULL)
507c478bd9Sstevel@tonic-gate 			exit(EX_UNAVAILABLE);
517c478bd9Sstevel@tonic-gate 		newargv[0] = _PATH_SENDMAIL_BIN;
527c478bd9Sstevel@tonic-gate 		newargv[1] = "-bp";
537c478bd9Sstevel@tonic-gate 		for (j = 1; j <= argc; j++)
547c478bd9Sstevel@tonic-gate 			newargv[j + 1] = argv[j];
557c478bd9Sstevel@tonic-gate 		(void) execve(_PATH_SENDMAIL_BIN, newargv, envp);
567c478bd9Sstevel@tonic-gate 		perror("Cannot exec " _PATH_SENDMAIL_BIN);
577c478bd9Sstevel@tonic-gate 		exit(EX_OSERR);
587c478bd9Sstevel@tonic-gate 	}
597c478bd9Sstevel@tonic-gate 	(void) fputs("No authorization to run mailq; "
607c478bd9Sstevel@tonic-gate 	    "see mailq(1) for details.\n", stderr);
617c478bd9Sstevel@tonic-gate 	return (EX_NOPERM);
627c478bd9Sstevel@tonic-gate }
63