/*
* Copyright (c) 2005-2007 Nicolas Bernard
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* This is a wrapper to authorize the use of a port (eg: parallel port)
* by a program which assume it can (e.g., wine). */
/* This program must be setuid root.
compile with:
gcc -Wall -pedantic iowrapper.c -o iowrapper
set correct owner/permissions with (as root):
chown root:root iowrapper
chmod +s iowrapper
*/
/* v2: changes: use getuid and not a constant UID. */
#include
#include
#include
#include
#include
#include
#include
/**** Adjust those values according to your configuration. *****/
#define WINE_PATH "/usr/bin/wine" /* The program to launch. */
#define PORT_FROM 0x370 /* Beginning of the memory area to
authorize. */
#define PORT_TO 0x37F /* End of the area. */
/************************************************************/
int
main(int argc, char* argv[], char *const envp[])
{
char** nargv;
int i;
if (ioperm(PORT_FROM, PORT_TO - PORT_FROM + 1, 1)) {
fprintf(stderr, "ioperm: %s\n", strerror(errno));
return 1;
}
nargv = malloc((argc + 1) * sizeof(char*));
if (nargv == NULL) {
fprintf(stderr, "malloc: unable to allocate memory\n");
return 2;
}
for (i = 0; i < argc; i++)
nargv[i] = argv[i];
nargv[argc] = NULL;
if (setuid(getuid())) {
fprintf(stderr, "setuid: %s\n", strerror(errno));
return 3;
}
execve(WINE_PATH, nargv, envp);
fprintf(stderr, "execve: %s\n", strerror(errno));
return 4;
}