ioperm() and setuid()
Hello,
Does anyone know how to allow non root users in linux to access to i/o ports using ioperm() and setuid().
I tried using the ioperm() function and setuid() but i still get a message of permission access denied.
Can anyone help me on this?
Lejanson
Can you send your source code please????
Best regards,
Chris.
----- Original Message -----
From: "Lejanson C. Go" <[email protected]>
To: <[email protected]>
Sent: Monday, October 13, 2003 3:02 AM
Subject: ioperm() and setuid()
Quoted 8 lines
Hello,
Does anyone know how to allow non root users in linux to access to i/o ports using
ioperm()andsetuid().I tried using the
ioperm()function andsetuid()but i still get a message of permission access denied.
Quoted 6 lines
Can anyone help me on this?
Lejanson
-
To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
Quoted 3 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Lejanson C. Go
Hello,
Does anyone know how to allow non root users in linux to access to i/o ports using
ioperm()andsetuid().
I think you're misunderstanding setuid(). For a program to have I/O access, it needs root permissions.
For a normal user to gain those permissions, the executable needs to be owned by root and have the set-user-id bit set.
Or you can use the userhelper package to give temporary root permissions to the user for that program.
Here's code I use for that purpose (changed a little):
int main(int ac, char *av[])
{
/* parse and check args */
if (parse(ac, av))
return 1;
/* check if enough privileges for io ops */
if (geteuid()) {
if (!helped)
/* haven't tried consolehelper yet, try it */
use_ch(ac, av);
fprintf(stderr, "%s: must run with superuser privileges\n",
pname);
return 1;
}
/* get privileges for out|in_p delay */
if (ioperm(0x80, 1, 1)) {
err("port 0x80 (pause)");
return 1;
}
/* get privileges for out|in to lp ports */
if (ioperm(port, IORANGE, 1)) {
err2("port %#03x", port);
return 1;
}
...
}/* not running with root privileges, try consolehelper */ void use_ch(int oac, char *oav[])
{
extern char **environ;
char **nav;
if (!(nav = calloc(oac + 2, sizeof(char *)))) {
err("new args");
return;
}
/* copy old args */
memcpy(nav, oav, oac * sizeof(char *));
/* args = args + "-c" */
nav[oac] = "-c";
execve("/usr/bin/consolehelper", nav, environ);
err("consolehelper");
}Regards,
Luciano Rocha