🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: nl.comp.programmeren
Article #722

Paralelle Poort acess als gewone user?

#722
From: Bart Vandewoestyne
Date: Sat, 06 Nov 1999 00:00
132 lines
5086 bytes
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

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 -
Technical Details
Message-ID: <3824ACD8.A1206590@skynet.be>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 100a19,100fd66209ba543c,start
X-Google-Attributes: gid100a19,public
X-Google-Thread: 107324,100fd66209ba543c,start
X-Google-Attributes: gid107324,public
X-Google-Thread: fcea4,100fd66209ba543c,start
X-Google-Attributes: gidfcea4,public
X-Google-Thread: fb7d6,100fd66209ba543c,start
X-Google-Attributes: gidfb7d6,public
From: Bart Vandewoestyne <Bart.Vandewoestyne@skynet.be>
Subject: Paralelle Poort acess als gewone user?
Date: 1999/11/06
Message-ID: <3824ACD8.A1206590@skynet.be>
X-Deja-AN: 545340554
Content-Transfer-Encoding: 7bit
X-Accept-Language: nl-BE, nl, en, de
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@skynet.be
X-Trace: news0.skynet.be 941927680 21992 194.78.239.186 (6 Nov 1999 22:34:40 GMT)
Organization: MyHome
Mime-Version: 1.0
NNTP-Posting-Date: 6 Nov 1999 22:34:40 GMT
Newsgroups: nl.comp.programmeren,be.comp.os.linux,be.comp.programming,nl.comp.os.linux