linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* ioperm() and setuid()
@ 2003-10-13  0:02 Lejanson C. Go
  2003-10-13 13:11 ` Chris Nanakos
  2003-10-13 13:42 ` Luciano Miguel Ferreira Rocha
  0 siblings, 2 replies; 3+ messages in thread
From: Lejanson C. Go @ 2003-10-13  0:02 UTC (permalink / raw)
  To: linux-c-programming

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ioperm() and setuid()
  2003-10-13  0:02 ioperm() and setuid() Lejanson C. Go
@ 2003-10-13 13:11 ` Chris Nanakos
  2003-10-13 13:42 ` Luciano Miguel Ferreira Rocha
  1 sibling, 0 replies; 3+ messages in thread
From: Chris Nanakos @ 2003-10-13 13:11 UTC (permalink / raw)
  To: Lejanson C. Go, linux-c-programming

Can you send your source code please????


Best regards,
Chris.

----- Original Message -----
From: "Lejanson C. Go" <lejanson@ntsp.nec.co.jp>
To: <linux-c-programming@vger.kernel.org>
Sent: Monday, October 13, 2003 3:02 AM
Subject: 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
>
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: ioperm() and setuid()
  2003-10-13  0:02 ioperm() and setuid() Lejanson C. Go
  2003-10-13 13:11 ` Chris Nanakos
@ 2003-10-13 13:42 ` Luciano Miguel Ferreira Rocha
  1 sibling, 0 replies; 3+ messages in thread
From: Luciano Miguel Ferreira Rocha @ 2003-10-13 13:42 UTC (permalink / raw)
  To: Lejanson C. Go; +Cc: linux-c-programming

On Mon, Oct 13, 2003 at 08:02:25AM +0800, Lejanson C. Go wrote:
> Hello,
> 
> Does anyone know how to allow non root users in linux to
> access to i/o ports using ioperm() and setuid().

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-10-13 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-13  0:02 ioperm() and setuid() Lejanson C. Go
2003-10-13 13:11 ` Chris Nanakos
2003-10-13 13:42 ` Luciano Miguel Ferreira Rocha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).