🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: nl.comp.programmeren
Article #725

Re: Paralelle Poort acess als gewone user?

#725
From: Bernhard Dobbels
Date: Sun, 07 Nov 1999 00:00
229 lines
8170 bytes
In article <3824ACD8.A1206590@skynet.be>, Bart Vandewoestyne wrote:
>Ik zou willen een programma schrijven om de parallelle poort te sturen.
>Ik wil dit programma als gewone user kunnen uitvoeren.  Tot nu toe slaag
>ik erin om het programma goed te doen lopen als root.  In de Linux I/O
>port programming mini-HOWTO vond ik het volgende:
>
>The ioperm() call requires your program to have root privileges; thus
>you need to either run it as the root user, or make it setuid root.  You
>can drop the root privileges after you have called ioperm() to enable
>the ports you want to use.  You are not required to explicitly drop your
>port access privileges with ioperm(..., 0) at the end of your program;
>this is done automatically as the process exits.
>
>A setuid() to a non-root user does not disable the port access granted
>by ioperm(), but a fork() does (the child process does not get access,
>but the parent retains it).
>
>Ik denk dus dat ik ergens gebruik moet maken van setuid().  Probleem is
>echter volgende:
>
>Heaven:~/eindwerk/source$ man setuid
>No manual entry for setuid

Debian eens installeren, dan werken al die dingen goed :)

SETUID(2)           Linux Programmer's Manual           SETUID(2)


NAME
       setuid - set user identity

SYNOPSIS
       #include <unistd.h>

       int setuid(uid_t uid)

DESCRIPTION
       setuid  sets the effective user ID of the current process.
       If the effective userid of the caller is  root,  the  real
       and saved user ID's are also set.

       Under  Linux, setuid is implemented like the POSIX version
       with the _POSIX_SAVED_IDS feature.  This allows  a  setuid
       (other  than  root) program to drop all of its user privi-
       leges, do some un-privileged work, and then re-engage  the
       original effective user ID in a secure manner.

       If the user is root or the program is setuid root, special
       care must be taken. The setuid function checks the  effec-
       tive  uid  of  the  caller and if it is the superuser, all
       process related user ID's are set to uid.  After this  has
       occurred,  it is impossible for the program to regain root
       privileges.

       Thus, a setuid-root program wishing  to  temporarily  drop
       root  privileges,  assume the identity of a non-root user,
       and then regain  root  privileges  afterwards  cannot  use
       setuid.  You can accomplish this with the (non-POSIX, BSD)
       call seteuid.

RETURN VALUE
       On success, zero is returned.  On error, -1  is  returned,
       and errno is set appropriately.

ERRORS
       EPERM  The  user  is  not the super-user, and uid does not
              match the effective or saved user ID of the calling
              process.

CONFORMING TO
       SVr4, SVID, POSIX.1.  Not quite compatible with the 4.4BSD
       call, which sets all of the  real,  saved,  and  effective
       user  IDs.  SVr4 documents an additional EINVAL error con-
       dition.

LINUX-SPECIFIC REMARKS
       Linux has the concept  of  filesystem  user  ID,  normally
       equal to the effective user ID.  The setuid call also sets
       the filesystem user ID of the current process.  See  setf-
       suid(2).

       If  uid  is  different  from  the  old  effective uid, the



Linux 1.1.36               29 July 1994                         1





SETUID(2)           Linux Programmer's Manual           SETUID(2)


       process will be forbidden from leaving core dumps.

SEE ALSO
       getuid(2), setreuid(2), seteuid(2), setfsuid(2)












>
>Is dit een functie die ik in mijn progamma moet inbouwen?  Zo ja, welke
>header files moet ik dan includen en welke argumenten geef ik mee? 
>Kortom: hoe slaag ik erin om onderstaand programma uit te voeren vanaf
>command line als gewone user:
>
>/**********************************************************/
>/* This program demonstrates the use of the parallel port */
>/* compile with gcc -o partest1 -O partest1.c             */
>/*                                                        */
>/* Bart.Vandewoestyne@skynet.be                           */
>/**********************************************************/
>
>#include <asm/io.h>
>#include <unistd.h>
>#include <stdio.h>
>
>#define BASEPORT 0x378          /* lp1 */
>#define SLEEPTIME 100000        /* sleep time in micro-seconds */
>
>int main()
>{
> int i=0;       /* counter variabele */
>
> /* Get access to the ports */
> if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
>
> for (i=0; i<100; i++) {
>
> /* LED1  PIN 2  DATA0  BASEPORT  BIT0 */
> outb(1, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED2  PIN 3  DATA1  BASEPORT  BIT1 */
> outb(2, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED3  PIN 4  DATA2  BASEPORT  BIT2 */
> outb(4, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>partest1.c: unmodified: line 1
>
> /* LED4  PIN 5  DATA3  BASEPORT  BIT3 */
> outb(8, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
> 
> /* LED5  PIN 6  DATA4  BASEPORT  BIT4 */
> outb(16, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED6  PIN 7  DATA5  BASEPORT  BIT5 */
> outb(32, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED7  PIN 8  DATA6  BASEPORT  BIT6 */
> outb(64, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED8  PIN 9  DATA7  BASEPORT  BIT7 */
> outb(128, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED9  PIN 1  nStrobe  BASEPORT+2  BIT0  INVERTED OUTPUT!!*/
> outb(0, BASEPORT);
> outb(0x0A, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED10  PIN 14  nAuto-Line Feed  BASEPORT+2  BIT9 */
> outb(0, BASEPORT);
> outb(0x09, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED11  PIN 16  Initialize  BASEPORT+2  BIT2  INVERTED OUTPUT!!*/
> outb(0, BASEPORT);
> outb(0x0F, BASEPORT+2);
> usleep(SLEEPTIME);
>
> /* LED12  PIN 17  nSelect-Printer  BASEPORT+2  BIT3  INVERTED
>OUTPUT!!*/
> outb(0, BASEPORT);
> outb(0x03, BASEPORT+2);
> usleep(SLEEPTIME);
>
> outb(0, BASEPORT);
> outb(0x0B, BASEPORT+2);
> usleep(SLEEPTIME);
> }
>
> /* We don't need the ports anymore */
> if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
> exit(0);
>}
>
>-- 
>Bart Vandewoestyne		http://hello.to/MC303		
>Hugo Verrieststraat 48		Bart.Vandewoestyne@skynet.be
>8550 ZWEVEGEM			ICQ# 21275340
>BELGIUM - EUROPE		nick: MC303
>Phone: +32(0)56/75.48.11
>-------------------------------------------------------------------
>If carpenters made buildings the way programmers make programs, the 
>first woodpecker to come along would destroy all of civilization.
>				- Weinberg's Second Law -
>


-- 
Bernhard

"One World, One Web, One Program" - Microsoft Promotional Ad
"Ein Volk, Ein Reich, Ein Fuhrer" - Adolf Hitler
Technical Details
Message-ID: <slrn82aadl.ds1.Bernhard@Viking.tvd.kotnet.org>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3824ACD8.A1206590@skynet.be>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 100a19,100fd66209ba543c
X-Google-Attributes: gid100a19,public
X-Google-Thread: 107324,100fd66209ba543c
X-Google-Attributes: gid107324,public
X-Google-Thread: fcea4,100fd66209ba543c
X-Google-Attributes: gidfcea4,public
X-Google-Thread: fb7d6,100fd66209ba543c
X-Google-Attributes: gidfb7d6,public
From: Bernhard@KotNet.Org (Bernhard Dobbels)
Subject: Re: Paralelle Poort acess als gewone user?
Date: 1999/11/07
Message-ID: <slrn82aadl.ds1.Bernhard@Viking.tvd.kotnet.org>
X-Deja-AN: 545458076
Cache-Post-Path: marvin!dingy@tvd-10-67-68-47.tvd.kotnet.kuleuven.ac.be
Content-Transfer-Encoding: 8bit
References: <3824ACD8.A1206590@skynet.be>
Content-Type: text/plain; charset=iso-8859-1
X-Complaints-To: abuse@belnet.be
X-Trace: naxos.belnet.be 941959606 20703 134.58.127.3 (7 Nov 1999 07:26:46 GMT)
Organization: KULeuvenNet
X-Cache: nntpcache 2.3.3 (see http://www.nntpcache.org/)
Mime-Version: 1.0
User-Agent: slrn/0.9.5.7 (UNIX)
Reply-To: Bernhard@kotnet.org
NNTP-Posting-Date: 7 Nov 1999 07:26:46 GMT
Newsgroups: nl.comp.programmeren,be.comp.os.linux,be.comp.programming,nl.comp.os.linux