/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2014 Gary Mills
*/
/*
* New implementation of pfexec(1) and all of the profile shells.
*
* The algorithm is as follows:
* first try to derive the shell's path from getexecname();
* note that this requires a *hard* link to the program, so
* if we find that we are actually executing pfexec, we start
* looking at argv[0].
* argv[0] is also our fallback in case getexecname doesn't find it.
*/
#include <alloca.h>
#include <errno.h>
#include <locale.h>
#include <priv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef TEXT_DOMAIN
#endif
#define RES_OK 0
/*
* Return the shellname
*/
int
{
else
cmd++;
return (RES_FAILURE);
return (RES_PFEXEC);
return (RES_FAILURE);
} else {
}
return (RES_OK);
}
static void
usage(void)
{
}
int
{
char *cmd;
int c;
int oflag;
gettext("pfexec: unable to set PFEXEC flag: %s\n"),
exit(1);
}
if (*argv[0] == '-')
else
/* Strip "pf" from argv[0], it confuses some shells. */
argv[0] += 2;
/* argv[0] will need to start with '-' again. */
*argv[0] = '-';
}
/* If this fails, we just continue with plan B */
case RES_OK:
gettext("pfexec: unable to execute %s: %s\n"),
return (1);
case RES_PFEXEC:
case RES_FAILURE:
switch (c) {
case 'P':
break;
}
/* FALLTHROUGH */
default:
usage();
}
}
if (argc < 1)
usage();
NULL) {
gettext("pfexec: error parsing "
}
gettext("pfexec: error setting "
}
}
gettext("pfexec: unable to execute %s: %s\n"),
return (1);
}
return (1);
}