trying to make zgv work

trying to make zgv work

Post by Lars Eighne » Fri, 13 Oct 2000 04:00:00



I am trying to make zgv work with FreeBSD 4.1STABLE.

zgv is an image viewer using sgvalib.

WARNING:  Serious security issues: blah-blah blah commies
under your bed right now yadda yadda thermonuclear device
blah blah.

I want zgv for a quick image viewer that doesn't have to
fight with a massive bloated gui for resources and the
palette and to use with lynx and similar console programs.

The story so far:

I got the source distribution for zgv-5.1 from
svgalib.org.

I get it to work from a ttyv that root is signed
into, and it is swift, beautiful, wonderful, etc.  But it
is kind of beside the point as the whole idea is to run
it as a regular user.

So basically, I got the trivia out of the way but since
I have no idea what I am doing, I can't solve the
central problem.

Here is where the problem is in the original code:

/* if we're not running directly on a console, try to find a free console
 * and move us to it. Notes old VT so we can switch back to it when finished,
 * if we ran on a different one to start off with.
 *
 * svgalib 1.2.11 and up do something similar (which was based on this,
 * I think), but it doesn't *quite* do what we need (e.g. it changes stdout,
 * which is sensible generally but zgv wants to keep it the same). So, er,
 * that's why this code's still here. :-)
 *
 * NB: *This is run as root*. Think twice before messing with it.
 */
int fixvt()
{
static char vt_filename[128];
struct stat sbuf;
struct vt_stat vts;
int major,minor;
int fd;
int num;

/* see if terminal is a console */
fd=dup(2);
fstat(fd,&sbuf);
major=sbuf.st_rdev>>8;
zgv_vt=minor=sbuf.st_rdev&0xff;
close(fd);
if(major==4 && minor<64)
  return(1);    /* if on a console, already ok */

/* otherwise we need to look for a free VT, redirect std{in,out,err},
 * and switch to it. If there's no free VTs, give up now.
 */

separate_vt=1;

/* still root perms, so this shouldn't be a problem... */
if((fd=open("/dev/console",O_WRONLY))<0) return(0);
ioctl(fd,VT_GETSTATE,&vts);
original_vt=vts.v_active;
ioctl(fd,VT_OPENQRY,&num);
if(num==-1) return(0);  /* no VTs free */

/* now, before we go for it, we test the *current* VT to see if they
 * own it. If so, the user's probably `genuine'.
 * (NB: the kernel now does this, but there's no harm repeating it.)
 */
snprintf(vt_filename,sizeof(vt_filename),"/dev/tty%d",original_vt);
stat(vt_filename,&sbuf);
if(getuid()!=sbuf.st_uid)
  {
  fprintf(stderr,
    "zgv: you must be the owner of the current console to run zgv.\n");
  exit(1);
  }

/* switch to the new VT */
ioctl(fd,VT_ACTIVATE,num);
close(fd);

/* This is incredibly annoying, but the 2.0.x kernel just *will not*
 * work without it. :-(((
 * So, this gives really weird results for `zgv -h' etc., as the parent
 * returns immediately. Redirect stdout if this is a problem.
 */
if(fork()) exit(0);

zgv_vt=num;
sprintf(vt_filename,"/dev/tty%d",num);

setsid();

if(freopen(vt_filename,"r",stdin)==NULL)      return(0);
if(freopen(vt_filename,"w",stderr)==NULL)     return(0);

ioctl(0,VT_WAITACTIVE,num);

/* not needed, but... just in case... */
chown(vt_filename,getuid(),getgid());

/* ok, done it. */
return(1);

}

Here are the changes I have made to it so far: mostly due
to using consio.h instead of vt.h

int fixvt()
{
static char vt_filename[128];
struct stat sbuf;
int vts;
int major,minor;
int fd;
int num;

/* see if terminal is a console */
fd=dup(2);
fstat(fd,&sbuf);
major=sbuf.st_rdev>>8;
zgv_vt=minor=sbuf.st_rdev&0xff;
close(fd);
if(major==12 && minor<64)
  return(1);    /* if on a console, already ok */

/* otherwise we need to look for a free VT, redirect std{in,out,err},
 * and switch to it. If there's no free VTs, give up now.
 */

separate_vt=1;

/* still root perms, so this shouldn't be a problem... */
if((fd=open("/dev/console",O_WRONLY))<0) return(0);
ioctl(fd,VT_GETACTIVE,&vts);
original_vt=vts;
ioctl(fd,VT_OPENQRY,&num);
if(num==-1) return(0);  /* no VTs free */

/* now, before we go for it, we test the *current* VT to see if they
 * own it. If so, the user's probably `genuine'.
 * (NB: the kernel now does this, but there's no harm repeating it.)
 */
snprintf(vt_filename,sizeof(vt_filename),"/dev/ttyv%x",original_vt);
stat(vt_filename,&sbuf);
if(getuid()!=sbuf.st_uid)
  {
  fprintf(stderr,
    "zgv: you must be the owner of the current console to run zgv.\n");
  exit(1);
  }

/* switch to the new VT */
ioctl(fd,VT_ACTIVATE,num);
close(fd);

/* This is incredibly annoying, but the 2.0.x kernel just *will not*
 * work without it. :-(((
 * So, this gives really weird results for `zgv -h' etc., as the parent
 * returns immediately. Redirect stdout if this is a problem.
 */
if(fork()) exit(0);

zgv_vt=num;
sprintf(vt_filename,"/dev/tty%d",num);

setsid();

if(freopen(vt_filename,"r",stdin)==NULL)      return(0);
if(freopen(vt_filename,"w",stderr)==NULL)     return(0);

ioctl(0,VT_WAITACTIVE,num);

/* not needed, but... just in case... */
chown(vt_filename,getuid(),getgid());

/* ok, done it. */
return(1);

}

Known dependencies: svgalib, jpeglib, pnglib, tifflib --
uses gawk as is, but of course it could be awk (just for
man page), gmake, needs texinfo (but this comes with the
FreeBSD distribution, and of course gcc and the usual
build libraries.

zgv/Makefile

line 31: delete src/install-info from src:

This install-info is meant to take the place of texinfo
3.12. Since texinfo is installed with the system in
FreeBSD (and since I can't get this install-info to
work, and since it has nothing to do with the basic
purpose of zvg) we pretty much have no use for it.

lines 38 & 39:

Comment out the make for src/install-info as above.

zgv/config.mk

line 16: chance PREFIX from /usr to /usr/local

This is a /usr/local sort of program.

line 22: comment out SHARE_INFIX.

man/ and info/ attach directly to /usr/local and not to
/usr/local/share.

line 35: uncomment INFO_DIR_UPDATE=no

We are not using the package's version of install info.

line 48: note you can have pcd support if you install
libpcd.  I didn't want it.

line 58: note - uses rgb.txt from X.  Can be commented out
but then there is no support for xpm named colors.

line 69: Americans and others not using A4 paper will have
to change this if the manual is going to be printed.

zgv/doc/Makefile

line 29: could use awk instead of gawk to avoid having to
install gawk if you don't have it.

lines 32 & 34-36:  This is all very confusing.  Basically,
comment out these lines since we are not using the package
version of install-info.

lines 42-50: comment out for above reason.

line 51: a convenient place to add
<TAB>install-info zgv $(INFODIR)/dir

lines 52 & 53: comment out some more of the package
install-info stuff

zgv/src/Makefile

line 19 & 20 : add continue slash and add this line to
CFLAGS: -idirafter /usr/local/include -idirafter /usr/local
-L /usr/local/lib

There is bound to be a more elegant way of doing this, but
this lets gmake find the right headers and libraries -
mainly the jpeg, tiff, png, sgva libraries' stuff

line 30: delete (the package) install-info from the all
target list.

As above.  Texinfo is part of the FreeBSD distribution and
we don't need a replacement.

lines 51-52: remove rule for install info

line 55: there is no group root, so change -g root to -g
wheel.

line 72: comment out dependency rule for install-info

zgv/src/readnbkey.c

line 19: include sys/kbio.h instead of linux/kd.h

line 48 & line 52-62: comment out.

This is a bad hack to deal with a bad hack.  For certain
historic and mnemonic reason best known to the author, he
wishes to emmulate the old behavior of keyboards with only
10 F keys so that Shift-F1 = F11 and Shift-F2 = F12.  He is
testing here to see if you do indeed already have an old 10
Fkey keyboard so as not to emulate it if you already have
it.  I don't understand his method here and I can't make it
work, so I have hacked it to report there is a new keyboard
unconditionally.  This breaks it, of course, if you do have
an old keyboard.  It think the odds are very much against
your having an old keyboard attached to a virtual console,
but if you do, tough.

zgv/src/zgv.c

line 36: include sys/consio.h instead of sys/vt.h

line 3111: change struct vt_stat vts to int vts (per
consio.h)

/* line 3122: change major==4 to major==12 (?)

I think the major mode of virtual consoles is 12.

I have unchanged this.  I think the change is wrong
but I don't know if the original is right. */

line 3133: VT_GETSTATE changed to VT_GETACTIVE (?)

consio doesn't know from VT_GETSTATE.

line 3134: change vts.v_active to vts since vts is an int,
per line 3111 (?)

line 3142: /dev/tty%d to /dev/ttyv%x (?)

I think what we want to do is with ttyvs.

Here are the diffs.  The original distribution is in share/

diff -C 2 -r share/zgv-5.1/Makefile zgv-5.1/Makefile
*** share/zgv-5.1/Makefile      Thu Jun  1 09:48:58 2000
--- zgv-5.1/Makefile    Wed Oct 11 17:25:57 2000
***************
*** 29,33 ****
  all: src man infowarn

! src: zgv src/install-info

  # We try this the whole time, as the dependancies are a bit
--- 29,33 ----
  all: src man infowarn

! src: zgv

  # We try this the whole time, as the dependancies are a bit
***************
*** 36,41 ****
        $(MAKE) -C src zgv

! src/install-info: src/install-info.c
!       $(MAKE) -C src install-info

  man: doc/zgv.1
--- 36,41 ----
        $(MAKE) -C src zgv

! #src/install-info: src/install-info.c
! #     $(MAKE) -C src install-info

  man: doc/zgv.1
diff -C 2 -r share/zgv-5.1/config.mk zgv-5.1/config.mk
*** share/zgv-5.1/config.mk     Thu Jun  1 09:53:23 2000
--- zgv-5.1/config.mk   Wed Oct 11 20:00:07 2000
***************
*** 14,18 ****
  # Usually it will be simpler to just set PREFIX.
  #
! PREFIX=/usr

  # comment this out to use traditional info/man locations, e.g.
--- 14,18 ----
  # Usually it will be simpler to just set PREFIX.
  #
! PREFIX=/usr/local

  # comment this out to use traditional info/man locations, e.g.
***************
*** 20,24 ****
  # /usr/share/info and /usr/share/man/man1.
  #
! ...

read more »

 
 
 

trying to make zgv work

Post by Donn Mille » Sat, 14 Oct 2000 04:00:00



> I am trying to make zgv work with FreeBSD 4.1STABLE.
> I get it to work from a ttyv that root is signed
> into, and it is swift, beautiful, wonderful, etc.  But it
> is kind of beside the point as the whole idea is to run
> it as a regular user.

You just want to run zgv as suid root.  See man chmod(1) for details.
For example, if you have zgv installed with permissions 0711, you would
do

chmod 4711 zgv

to set the suid bit to give normal users root executable permissions.

For example, seejpeg is installed on my system as:

-rws--x--x  1 root  bin  29736 Oct 12 09:51 /usr/local/bin/seejpeg*
   ^

This is a svgalib app installed as suid root on my system.

- Donn

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----

 
 
 

1. ZGV, svgalib pictureviewer, doesn't work with ATI GUP..

Well, I have tried it, and it does not work with my ATI GUP. It does
not even try to change to the svga modes when using the function- or
shift-function keys. I know svgalib is set up right, since I am able
to view POV renderings in 24bit colour. And yes, I have checked the
system.zgvrc file for the proper settings.

Any suggestions or new releases coming up??

--
Marius Kjeldahl, student at The Norwegian Insitute of Technology and
The University of Karlsruhe - finishing MSc late autumn 1994

        www   : http://rzstud1.rz.uni-karlsruhe.de/~ulh0

2. Copying one file to multiple directories

3. Trying to get X to work (tried again)

4. CVS Permission Denied Error

5. Making GTK work in the background while my app works in foreground

6. Pls help: backup/archive software

7. Making UUCICO try again!

8. Mouse not being recognized during installation

9. any hints, bewares: will try making antiword-0.35 install for solaris9/sparc

10. made a reall mess trying to install the new gcc c compiler (please help)

11. Making changes to env variables and making them stick

12. Making a new kernel - CVSuped, not made world yet.

13. zgv gif viewer