setpmac.c revision 330449
137535Sdes/*- 237535Sdes * SPDX-License-Identifier: BSD-3-Clause 337535Sdes * 437535Sdes * Copyright (c) 2002 Networks Associates Technology, Inc. 537535Sdes * All rights reserved. 637535Sdes * 737535Sdes * This software was developed for the FreeBSD Project by Network 837535Sdes * Associates Laboratories, the Security Research Division of Network 937535Sdes * Associates, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 1037535Sdes * ("CBOSS"), as part of the DARPA CHATS research program. 1137535Sdes * 1237535Sdes * Redistribution and use in source and binary forms, with or without 1337535Sdes * modification, are permitted provided that the following conditions 1437535Sdes * are met: 1537535Sdes * 1. Redistributions of source code must retain the above copyright 1637535Sdes * notice, this list of conditions and the following disclaimer. 1737535Sdes * 2. Redistributions in binary form must reproduce the above copyright 1837535Sdes * notice, this list of conditions and the following disclaimer in the 1937535Sdes * documentation and/or other materials provided with the distribution. 2037535Sdes * 3. The names of the authors may not be used to endorse or promote 2137535Sdes * products derived from this software without specific prior written 2237535Sdes * permission. 2337535Sdes * 2437535Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2537535Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2637535Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2737535Sdes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2850476Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2937535Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3037535Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3137535Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3237571Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3337535Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3437535Sdes * SUCH DAMAGE. 3537535Sdes * 3637535Sdes * $FreeBSD: stable/11/usr.sbin/setpmac/setpmac.c 330449 2018-03-05 07:26:05Z eadler $ 3737535Sdes */ 3837535Sdes#include <sys/types.h> 3937535Sdes#include <sys/mac.h> 4037535Sdes 4137535Sdes#include <err.h> 4237535Sdes#include <paths.h> 4337535Sdes#include <stdio.h> 4437535Sdes#include <stdlib.h> 4537535Sdes#include <string.h> 4637535Sdes#include <sysexits.h> 4737535Sdes#include <unistd.h> 4837535Sdes 4937535Sdes#define MAXELEMENTS 32 5037535Sdes 5137535Sdesstatic void 5237535Sdesusage(void) 5337535Sdes{ 5437535Sdes 5537535Sdes fprintf(stderr, "setpmac [label] [command] [args ...]\n"); 5637535Sdes exit (EX_USAGE); 5737535Sdes} 5841862Sdes 5937535Sdesint 6037535Sdesmain(int argc, char *argv[]) 6137535Sdes{ 6237535Sdes const char *shell; 6355557Sdes mac_t label; 6460188Sdes int error; 6537573Sdes 6637535Sdes 6737571Sdes if (argc < 3) 6837535Sdes usage(); 6941869Sdes 7037571Sdes error = mac_from_text(&label, argv[1]); 7137535Sdes if (error != 0) { 7237535Sdes perror("mac_from_text"); 7340939Sdes return (-1); 7441862Sdes } 7537535Sdes 7637535Sdes error = mac_set_proc(label); 7737535Sdes if (error != 0) { 7837573Sdes perror(argv[1]); 7937535Sdes return (-1); 8037573Sdes } 8137573Sdes 8241869Sdes mac_free(label); 8341863Sdes 8437573Sdes if (argc >= 3) { 8560737Sume execvp(argv[2], argv + 2); 8660737Sume err(1, "%s", argv[2]); 8737573Sdes } else { 8837573Sdes if (!(shell = getenv("SHELL"))) 8937573Sdes shell = _PATH_BSHELL; 9037573Sdes execlp(shell, shell, "-i", (char *)NULL); 9160188Sdes err(1, "%s", shell); 9255557Sdes } 9363336Sdes /* NOTREACHED */ 9437573Sdes} 9540975Sdes