mailq.c revision 3649
3649N/A/*
3649N/A * CDDL HEADER START
3649N/A *
3649N/A * The contents of this file are subject to the terms of the
3649N/A * Common Development and Distribution License (the "License").
3649N/A * You may not use this file except in compliance with the License.
3649N/A *
3649N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3649N/A * or http://www.opensolaris.org/os/licensing.
3649N/A * See the License for the specific language governing permissions
3649N/A * and limitations under the License.
3649N/A *
3649N/A * When distributing Covered Code, include this CDDL HEADER in each
3649N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3649N/A * If applicable, add the following below this CDDL HEADER, with the
3649N/A * fields enclosed by brackets "[]" replaced with your own identifying
3649N/A * information: Portions Copyright [yyyy] [name of copyright owner]
3649N/A *
3649N/A * CDDL HEADER END
3649N/A */
3649N/A
3649N/A/*
3649N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
3649N/A * Use is subject to license terms.
3649N/A */
3649N/A
3649N/A#include <stdio.h>
3649N/A#include <stdlib.h>
3649N/A#include <auth_attr.h>
3649N/A#include <secdb.h>
3649N/A#include <pwd.h>
3649N/A#include <unistd.h>
3649N/A#include <sysexits.h>
3649N/A#include <errno.h>
3649N/A#include <auth_list.h>
3649N/A
3649N/A#define _PATH_SENDMAIL_BIN "/usr/lib/sendmail"
3649N/A
3649N/Aint
3649N/Amain(int argc, char *argv[], char *envp[])
3649N/A{
3649N/A struct passwd *pw = getpwuid(getuid());
3649N/A char **newargv;
3649N/A int j;
3649N/A
3649N/A if (pw && chkauthattr(MAILQ_AUTH, pw->pw_name)) {
3649N/A /* The extra 2 is 1 for the "-bp" + 1 for the terminator. */
3649N/A newargv = (char **)malloc((argc + 2) * sizeof (char *));
3649N/A if (newargv == NULL)
3649N/A exit(EX_UNAVAILABLE);
3649N/A newargv[0] = _PATH_SENDMAIL_BIN;
3649N/A newargv[1] = "-bp";
3649N/A for (j = 1; j <= argc; j++)
3649N/A newargv[j + 1] = argv[j];
3649N/A (void) execve(_PATH_SENDMAIL_BIN, newargv, envp);
3649N/A perror("Cannot exec " _PATH_SENDMAIL_BIN);
3649N/A exit(EX_OSERR);
3649N/A }
3649N/A (void) fputs("No authorization to run mailq; "
3649N/A "see mailq(1) for details.\n", stderr);
3649N/A return (EX_NOPERM);
3649N/A}