Article 13045 of alt.sources:
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!spool.mu.edu!sol.ctr.columbia.edu!news.uoregon.edu!tank.news.pipex.net!pipex!news.mathworks.com!newsfeed.internetmci.com!in2.uu.net!van-bc!vanbc.wimsey.com!not-for-mail
From: markh@vanbc.wimsey.com (Mark C. Henderson)
Newsgroups: alt.sources
Subject: change-sun-hostid version 1.6.0 -- part 4/5
Date: 30 Nov 1995 22:31:42 -0800
Organization: Online at Wimsey Information Services Inc - Vancouver, Canada
Lines: 1564
Message-ID: <49m7ge$30r@vanbc.wimsey.com>
NNTP-Posting-Host: vanbc.wimsey.com


#!/bin/sh
# This is part 04 of a multipart archive.
touch -am 1231235999 $$.touch >/dev/null 2>&1
if test ! -f 1231235999 && test -f $$.touch; then
  shar_touch=touch
else
  shar_touch=:
  echo
  echo 'WARNING: not restoring timestamps.  Consider getting and'
  echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 1231235999 $$.touch
#
# ============= hid-1.6.0/nvram_old.c ==============
if test ! -d 'hid-1.6.0'; then
  echo 'x - creating directory hid-1.6.0'
  mkdir 'hid-1.6.0'
fi
if test -f 'hid-1.6.0/nvram_old.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/nvram_old.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/nvram_old.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/nvram_old.c' &&
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
X
/* 
get/change hostid in NVRAM --
X
old version -- I should throw this away. Less friendly but perhaps
X  easier to modify for other types of machines.
X
only tested on sun4m architecture and sun4c architecture. The
kernel patches will be different for Sun4 and I don't have one
to play with. 
X
This program is still experimental. Dangerous and tricky stuff.
If you are unwilling to experiment and clean up after disasters
don't use it. hid is probably safer. USE AT YOUR OWN RISK.
X
Note the define OFFSET below!
X
running this will invalidate the overall NVRAM checksum. So after it
make some trivial change with the eeprom command (change the baud
rate on a serial port or something like that
e.g.
/usr/etc/eeprom diag-switch?=false
)
X
first you need to turn off the protection in the OS to keep
you from modifying /dev/eeprom locations after 017730 
use adb
adb -k -w /vmunix /dev/mem
_mmeeprom+8/W 901223ff
X
which changes
or      %o1, 0x3d8, %o1
to
or      %o1, 0x3ff, %o1
X
X
Unfortunately this change with adb to the eeprom device seems to depend
on the exact version of Sun OS you are running. Don't assume it will
work without looking around intelligently.
X
e.g. For SUN OS 4.1.1 on a Sun 4c you need to:
adb -w /vmunix /dev/mem
_mmeeprom+4/W 80a6a7ff
_mmeeprom+0x28/W 80a6a7ff
which changes a couple of compare operations. 
X
Also be very careful. The first byte of the hostid identifies the type 
of system you are running. On modern Suns OS boot CDs depend on this 
information to get the correct architecture. If you change it you may 
be reduced to poking around in NVRAM from the monitor next time you have
to boot from CD.
X
Here's a mapping of what gets read into buf (at OFFSET)
buf[0] = always 01?
buf[1] = system id/first byte of hostid.
buf[2] \
buf[3]  \
buf[4]   \  HW ethernet address (6 bytes)
buf[5]    /  
buf[6]  /
buf[7]/
buf[8],...,buf[11] = always 00?
buf[12] = second byte of hostid
buf[13] = third byte of hostid
buf[14] = fourth byte of hostid
buf[15] = checksum
X
the checksum is buf[0] ^ buf[1] ^ ... ^ buf[14]
i.e. it must be the case that the  xor of buf[0] through buf[15] is 0
X
Without any parameters, it reports the hostid from NVRAM. Otherwise it
changes it. 
X
Mark Henderson <markh@wimsey.bc.ca>
Placed in the public domain by the author - 23 June 1994
X
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
X
*/
X
X
#define OFFSET 017730       /* for Sun 4m, Sun OS 4.1.3 */
/* #define OFFSET 03730     /* for Sun 4c, SUN OS 4.1.1 */
X
#define SANITY_CHECK        /* don't turn this off unless you need to. If this
X                               fails it generally means that the program won't
X                               work and very well may be destructive */
X
#undef TEST         /* doesn't actually do mods if TEST is defined */
unsigned char buf[17]; 
X
main(argc,argv)
int argc;
char *argv[];
{
X    unsigned int hid;
X    int fd;
X    int i;
X    unsigned int acc;
X    int read_hostid;
X    unsigned int hid_reported_by_gethostid = gethostid();
X
X    if (argc == 1) {
X        /* no args - just get hostid from prom */
X        read_hostid = 1;
X    }
X    else if (argc == 2) {
X        read_hostid = 0;
X        sscanf(argv[1],"%08x",&hid);
X    }
X    else {
X        fprintf(stderr, "usage: %s [hostid]\n",argv[0]);
X        fprintf(stderr, "  e.g. %s b0b1fb0b\n", argv[0]);
X        exit(1);
X    }
X    if (read_hostid) {
X        if ((fd = open("/dev/eeprom", O_RDONLY)) < 0) {
X            fprintf(stderr, "cannot open /dev/eeprom for read\n");
X            exit(1);
X        }
X    } 
X    else {
#ifdef TEST
X        if ((fd = open("/dev/eeprom", O_RDONLY)) < 0) {
X            fprintf(stderr, "cannot open /dev/eeprom for read\n");
X            exit(1);
X        }
#else
X        if ((fd = open("/dev/eeprom", O_RDWR)) < 0) {
X            fprintf(stderr, "cannot open /dev/eeprom for read\n");
X            exit(1);
X        }
#endif
X    }
X
X    if (lseek(fd,OFFSET,SEEK_SET) < 0) { 
X        fprintf(stderr, "lseek failed\n");
X        exit(1);
X    }
X
X    if (read_hostid) {
X        if (read(fd,buf,16) < 16) {
X            fprintf(stderr, "read of /dev/eeprom failed\n");
X            exit(1);
X        }
X        printf("%02x%02x%02x%02x\n", buf[1], buf[12], buf[13], buf[14]);
X        for (acc = 0 , i=0; i<15; i++) acc^=buf[i];
X        if (acc != buf[15])  {
X            fprintf(stderr, "warning: ID CHKSUM INVALID\n");
X            fprintf(stderr,"^buf = %02x\n", acc & 0xff);
X            fprintf(stderr,"buf[15] = %02x\n", buf[15] & 0xff);
X        }
X    }
X    else {
#ifdef SANITY_CHECK 
/* this will fail if you have modified the value returned by
X   gethostid by using one of the other programs in this package.
X   In that case I wouldn't turn this off but restore your old 
X   gethostid behaviour or replace the gethostid call above with
X   a reference to your "real" hostid, if your architecture 
X   is weird this should detect the problem and not try and
X   write into places we shouldn't. */
X
X        if (read(fd,buf,16) < 16) {
X            fprintf(stderr, "read of /dev/eeprom failed\n");
X            exit(1);
X        }
#ifdef TEST
X        for (i=0; i<16; i++)
X            printf("%02x ", buf[i]);
X        printf("\n");
#endif
X        for (acc = 0 , i=0; i<15; i++) acc^=buf[i];
X        if ((acc != buf[15]) 
X            || (buf[1] != (hid_reported_by_gethostid >> 24) )
X            || (buf[12] != ((hid_reported_by_gethostid >> 16) &0xff))
X            || (buf[13] != ((hid_reported_by_gethostid >> 8) &0xff))
X            || (buf[14] != (hid_reported_by_gethostid &0xff))) {
X        
X            fprintf(stderr, "SANITY CHECK FAILED -- aborting\n");
X            fprintf(stderr, 
X                "perhaps the value of the define OFFSET is wrong\n");
X            exit(1);
X        }
X            
X        if (lseek(fd,OFFSET,SEEK_SET) < 0) { 
X            fprintf(stderr, "lseek failed\n");
X            exit(1);
X        }
X
#endif
X        buf[1] = hid >> 24;
X        buf[12] = (hid >> 16) &0xff;
X        buf[13] = (hid >> 8) &0xff;
X        buf[14] = hid &0xff;
X        for (acc = 0 , i=0; i<15; i++) acc^=buf[i];
X        buf[15] = acc & 0xff;
#ifndef TEST
X        if (write(fd,buf,16) < 16) {
X            fprintf(stderr, "write failed\n");
X        }
#else
X    for (i=0; i<16; i++)
X        printf("%02x ", buf[i]);
X    printf("\n");
X
#endif
X    }
X    close(fd);
}
X
SHAR_EOF
  $shar_touch -am 0811082994 'hid-1.6.0/nvram_old.c' &&
  chmod 0600 'hid-1.6.0/nvram_old.c' ||
  echo 'restore of hid-1.6.0/nvram_old.c failed'
  shar_count="`wc -c < 'hid-1.6.0/nvram_old.c'`"
  test 7012 -eq "$shar_count" ||
    echo "hid-1.6.0/nvram_old.c: original size 7012, current size $shar_count"
fi
# ============= hid-1.6.0/run/README ==============
if test ! -d 'hid-1.6.0/run'; then
  echo 'x - creating directory hid-1.6.0/run'
  mkdir 'hid-1.6.0/run'
fi
if test -f 'hid-1.6.0/run/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/run/README (file already exists)'
else
  echo 'x - extracting hid-1.6.0/run/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/run/README' &&
run.c is a small program to run a program with any group in the
range 900,...,909 added to the group list.
X
Take a look at the makefile to make sure you have the correct settings
for CC and CFLAGS
X
You might want to install it in /usr/local/bin setuid root. Anyway,
that's what the install program does. I'm not an expert on writing
"safe" setuid programs, so please check this out carefully before you
install it. (General good instructios for any setuid root program!)
X
An example of its use (with the solaris 2 hostid-by-egid module) is
as follows:
X
(edit /etc/name_to_sysnum as described in the documentation for 
X hostid-by-egid-solaris2)
X
ratatosk# cd hostid-by-egid-solaris2
ratatosk# make load
/opt/SUNWspro/bin/cc -D_KERNEL  -c  sethostid.c
ld -r -o sethostid sethostid.o
/usr/sbin/modload ./sethostid
ratatosk# make sid
grep sethostid /etc/name_to_sysnum | sed 's/^/#define SYS_/' ratatosk#sethostid.h
/opt/SUNWspro/bin/cc -o sid -I. sid.c
ratatosk# ./sid 0 24000000
ratatosk# ./sid 1 25000000
ratatosk# cd ../run
ratatosk# make
cc -o run run.c
chmod 4755 run
ratatosk# hostid
80512f45
ratatosk# ./run 0 hostid
24000000
ratatosk# ./run 1 hostid
25000000
ratatosk# ./run 2 hostid
80512f45
ratatosk# ./run 0 lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "24000000"
ratatosk# ./run 0 lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "25000000"
ratstosk# ./run 0 csh
ratatosk# hostid
24000000
ratatosk# lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "24000000"
ratatosk# modinfo
X...
X 78 fc6a50a0   a62 277   1  sethostid (kern_hostid v1.02)
X...
ratatosk# modunload -i 78
ratatosk# hostid
80512f45
ratatosk# ./run 0 hostid
80512f45
SHAR_EOF
  $shar_touch -am 1130102795 'hid-1.6.0/run/README' &&
  chmod 0600 'hid-1.6.0/run/README' ||
  echo 'restore of hid-1.6.0/run/README failed'
  shar_count="`wc -c < 'hid-1.6.0/run/README'`"
  test 1816 -eq "$shar_count" ||
    echo "hid-1.6.0/run/README: original size 1816, current size $shar_count"
fi
# ============= hid-1.6.0/run/makefile ==============
if test -f 'hid-1.6.0/run/makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/run/makefile (file already exists)'
else
  echo 'x - extracting hid-1.6.0/run/makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/run/makefile' &&
# comment out next line for Solaris 1
CFLAGS = -DSOLARIS2
run: run.c
X	$(CC) $(CFLAGS) -o run run.c
X	chmod 4755 run
install: run
X	cp run /usr/local/bin
X	chmod 4755 /usr/local/bin/run
clean:
X	rm -f *.o core run
SHAR_EOF
  $shar_touch -am 1130102595 'hid-1.6.0/run/makefile' &&
  chmod 0600 'hid-1.6.0/run/makefile' ||
  echo 'restore of hid-1.6.0/run/makefile failed'
  shar_count="`wc -c < 'hid-1.6.0/run/makefile'`"
  test 209 -eq "$shar_count" ||
    echo "hid-1.6.0/run/makefile: original size 209, current size $shar_count"
fi
# ============= hid-1.6.0/run/run.c ==============
if test -f 'hid-1.6.0/run/run.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/run/run.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/run/run.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/run/run.c' &&
/* 
X * run a program with a group from the range 900,...,909 added to the
X *   group list
X * Mark Henderson <markh@wimsey.bc.ca>
X * 11 Aug 1994 
X * e.g.
X *  run 0 hostid
X * executes hostid with group 900 added to the group list
X *
X * must be installed setuid root. I recommend 4755 or 4711 for the
X *  permissions
X */
X
X
#include <unistd.h>
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
X
#ifdef SOLARIS2
#define GID_T gid_t
#else
#define GID_T int 
#endif
X  /* should be gid_t for Solaris 2, but it really doesn't matter */
X
GID_T grouplist[NGROUPS_MAX];
#define NHOSTID 10
main(argc,argv)
int argc;
char *argv[];
{
X    int i,j;
X
X    if (argc < 3) {
X        fprintf(stderr, "usage: run <int> command\n");
X        exit(1);
X    }
X    
X    i = getgroups(NGROUPS_MAX, grouplist);
#ifdef DEBUG
X    for (j=0; j< i ; j++)
X        fprintf(stderr, "%d\n", grouplist[j]);
#endif
X    grouplist[i] = (GID_T)(atoi(argv[1]) + 900);
X    if (grouplist[i] < 900 || grouplist[i] >= NHOSTID + 900) {
X        fprintf(stderr, "usage: run <int> command\n<int> is out of range\n");
X        exit(1);
X    }
X
X    if (i >= NGROUPS_MAX) {
X        fprintf(stderr, "already in NGROUPS_MAX groups\n");
X        exit(1);
X    }
X    i = setgroups(i+1, grouplist);
X    if (i < 0) {
X        fprintf(stderr, "setgroups failed\n");
X        exit(1);
X    }
X    seteuid(getuid());
X    execvp(argv[2], argv+2);
}
SHAR_EOF
  $shar_touch -am 1130102695 'hid-1.6.0/run/run.c' &&
  chmod 0600 'hid-1.6.0/run/run.c' ||
  echo 'restore of hid-1.6.0/run/run.c failed'
  shar_count="`wc -c < 'hid-1.6.0/run/run.c'`"
  test 1385 -eq "$shar_count" ||
    echo "hid-1.6.0/run/run.c: original size 1385, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-4.1/README ==============
if test ! -d 'hid-1.6.0/sethostid-simple-4.1'; then
  echo 'x - creating directory hid-1.6.0/sethostid-simple-4.1'
  mkdir 'hid-1.6.0/sethostid-simple-4.1'
fi
if test -f 'hid-1.6.0/sethostid-simple-4.1/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-4.1/README (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-4.1/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-4.1/README' &&
This is based, in part, upon an anonymous contribution. I've improved
it by making it loadable, so one does not have to build a new kernel.
You'll find the original contribution in ../hostid-by-egid
X
This will probably only work on versions of Sun OS later than 4.1.
X
I've tried it on both a Sun 3 and Sun 4.
X
to use this:
make load
make sethostid
X./sethostid 72000000
X
All numbers are in hex. Do NOT put in the leading 0x.
X
You can remove the sethostid call by using modunload. You can check
whether or not it is currently installed with modstat.
X
N.B. sethostid.exec must be executable. Depending upon where you got
the distribution you might have to chmod +x it.
X
Calling sethostid with the hostid of 0 will restore the hostid to the
default.
X
e.g.
X./sethostid 0
X
SHAR_EOF
  $shar_touch -am 0816104894 'hid-1.6.0/sethostid-simple-4.1/README' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-4.1/README' ||
  echo 'restore of hid-1.6.0/sethostid-simple-4.1/README failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-4.1/README'`"
  test 767 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-4.1/README: original size 767, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-4.1/kern_hostid.c ==============
if test -f 'hid-1.6.0/sethostid-simple-4.1/kern_hostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-4.1/kern_hostid.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-4.1/kern_hostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-4.1/kern_hostid.c' &&
/*
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
*/
X
#include <sys/param.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sun/vddrv.h>
X
static unsigned hostid = 0;
X
int sethostid();
X
static struct sysent sethostid_sysent = { 1, sethostid } ;
X
static struct vdlsys vd = {
X  VDMAGIC_SYS, /* magic number */
X  "sethostid", /* name */
X  0, /* syscall number (filled in automagically) */
X  &sethostid_sysent /* description of syscall */
};
X
X
Gethostid()
{
X    gethostid();
X
X    if (hostid)  
X    u.u_r.r_val1 = hostid;
X    u.u_error = 0;
X    return;
}
X
sethostid(uap)
X    register struct a {
X        unsigned hostid;
X    } *uap;
{
X    if (!suser()) {
X        u.u_error = EACCES;
X        return;
X    }
X
X    hostid = uap->hostid;
X
X    u.u_r.r_val1 = hostid;
X    u.u_error = 0;
X    return;
}
X
X
sethostidinit(function_code, vdp, vdi, vds)
unsigned int function_code;
struct vddrv *vdp;
addr_t vdi;
struct vdstat *vds;
{
X  switch (function_code) {
X  case VDLOAD:
X    vdp->vdd_vdtab = (struct vdlinkage *)&vd;
X    sysent[SYS_gethostid].sy_narg = 2;
X    sysent[SYS_gethostid].sy_call = Gethostid;
X    return 0;
X  case VDUNLOAD:
X    sysent[SYS_gethostid].sy_narg = 2;
X    sysent[SYS_gethostid].sy_call = gethostid;
X    return 0;
X  case VDSTAT:
X    return 0;
X  default:
X    return EIO;
X  }
}
X
SHAR_EOF
  $shar_touch -am 0816104894 'hid-1.6.0/sethostid-simple-4.1/kern_hostid.c' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-4.1/kern_hostid.c' ||
  echo 'restore of hid-1.6.0/sethostid-simple-4.1/kern_hostid.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-4.1/kern_hostid.c'`"
  test 1992 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-4.1/kern_hostid.c: original size 1992, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-4.1/makefile ==============
if test -f 'hid-1.6.0/sethostid-simple-4.1/makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-4.1/makefile (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-4.1/makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-4.1/makefile' &&
CFLAGS = -DKERNEL
ASFLAGS = -P
X
load: kern_hostid.o
X	chmod +x sethostid.exec
X	/usr/etc/modload kern_hostid.o -v -entry _sethostidinit -exec sethostid.exec
X
sethostid: sethostid.o sethostid.h
X	cc -o sethostid -I. sethostid.c
X
clean:
X	rm -f core *.o sethostid kern_hostid sethostid.h
SHAR_EOF
  $shar_touch -am 0816064894 'hid-1.6.0/sethostid-simple-4.1/makefile' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-4.1/makefile' ||
  echo 'restore of hid-1.6.0/sethostid-simple-4.1/makefile failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-4.1/makefile'`"
  test 282 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-4.1/makefile: original size 282, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-4.1/sethostid.c ==============
if test -f 'hid-1.6.0/sethostid-simple-4.1/sethostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-4.1/sethostid.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-4.1/sethostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-4.1/sethostid.c' &&
/*
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
*/
X
#include <stdio.h>
#include <sys/syscall.h>
#include <errno.h>
#include "sethostid.h"
X
main(argc, argv)
int argc;
char *argv[];
{
X  unsigned hostid;
X
X  if (argc<2) {
X    fprintf(stderr, "%s <hostid>\n", argv[0]);
X    exit(1);
X  }
X  sscanf(argv[1], "%x", &hostid);
X  if (syscall(SYS_sethostid, hostid)==-1) {
X    perror(argv[0]);
X    exit(1);
X  }
}  
X
SHAR_EOF
  $shar_touch -am 0816104894 'hid-1.6.0/sethostid-simple-4.1/sethostid.c' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-4.1/sethostid.c' ||
  echo 'restore of hid-1.6.0/sethostid-simple-4.1/sethostid.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-4.1/sethostid.c'`"
  test 1083 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-4.1/sethostid.c: original size 1083, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-4.1/sethostid.exec ==============
if test -f 'hid-1.6.0/sethostid-simple-4.1/sethostid.exec' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-4.1/sethostid.exec (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-4.1/sethostid.exec (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-4.1/sethostid.exec' &&
#!/bin/csh -f
echo "#define SYS_sethostid $3" > sethostid.h
SHAR_EOF
  $shar_touch -am 0816063494 'hid-1.6.0/sethostid-simple-4.1/sethostid.exec' &&
  chmod 0700 'hid-1.6.0/sethostid-simple-4.1/sethostid.exec' ||
  echo 'restore of hid-1.6.0/sethostid-simple-4.1/sethostid.exec failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-4.1/sethostid.exec'`"
  test 60 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-4.1/sethostid.exec: original size 60, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-5.x/README ==============
if test ! -d 'hid-1.6.0/sethostid-simple-5.x'; then
  echo 'x - creating directory hid-1.6.0/sethostid-simple-5.x'
  mkdir 'hid-1.6.0/sethostid-simple-5.x'
fi
if test -f 'hid-1.6.0/sethostid-simple-5.x/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-5.x/README (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-5.x/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-5.x/README' &&
Instructions:
X
You need to do everything below as root.
X
1. Add an entry to /etc/name_to_sysnum for the sethostid system call.
For instance, I use the following line.
sethostid		177
X
Do not put any leading whitespace on the line in /etc/name_to_sysnum.
X
The important thing is to pick an unused syscall number. There
is also a limit on the number you can pick, which is determined
by the size of the sysent table. To find out what the limit is
you can use adb (only in Solaris 2.3 - for 2.4 just be reasonable)
X
adb -k /dev/ksyms /dev/mem
sysentsize/D
^D        #  i.e. control-D
X
Look at the define NSYSCALL in /usr/include/sys/systm.h under 2.5
X
You should be able to pick any unused syscall number between 1 and the
number output by adb above minus 1. Alternatively just use an unused
number which is less than the largest number which occurs in
/etc/name_to_sysnum
X
After modifying /etc/name_to_sysnum you must reboot for the change
to take effect. If you fail to do this, you'll get a message like:
can't load module: Out of memory or no room in system tables
when you try to load the module
X
2. Look at the makefile and check that the location of the C compiler is
right for your system. Also if you are running Solaris 2.3 or 2.4 you
must uncomment the define -DPRE_SOLARIS_2_5 in the makefile (otherwise
the result will be unpredictable)
X
You do NOT want to get /usr/ucb/cc. gcc should be OK.
X
3. Type
make load
X
This should load the sethostid call. 
X
4. Type 
make sid
X
This makes the program that allows you to modify the hostid for
a particular group.
X
e.g. Now you can modify the hostid to be 23000000 by typing
X./sid 23000000
X
6. You can unload the system call as follows.
X
Type
/usr/sbin/modinfo
X
X You'll get output which includes a line which looks something like
76 fc42d000   621 177   1  sethostid (kern_hostid v1.0)
X
To remove the module type
/usr/sbin/modunload -i 76
Replace 76 by the first number in the line output by modinfo.
X
7. If you like you can install sid and sethostid by typing
make install
X
If you do this, when you reboot, the sethostid module will be
automatically loaded when sethostid is called (i.e. when you run sid).
X
setting the hostid to 0 with the sethostid call will restore the default.
SHAR_EOF
  $shar_touch -am 1130090295 'hid-1.6.0/sethostid-simple-5.x/README' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-5.x/README' ||
  echo 'restore of hid-1.6.0/sethostid-simple-5.x/README failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-5.x/README'`"
  test 2232 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-5.x/README: original size 2232, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-5.x/makefile ==============
if test -f 'hid-1.6.0/sethostid-simple-5.x/makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-5.x/makefile (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-5.x/makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-5.x/makefile' &&
# be sure to uncomment the -DPRE_SOLARIS_2_5 for Solaris 2.3 and 2.4
# otherwise this module may cause unpredictable results
CFLAGS = -D_KERNEL  # -DPRE_SOLARIS_2_5
ASFLAGS = -P
CC = /opt/SUNWspro/bin/cc
X
load: sethostid
X	/usr/sbin/modload ./sethostid
X
sethostid: sethostid.o
X	/usr/ccs/bin/ld -r -o sethostid sethostid.o
X
sid: sid.c
X	grep sethostid /etc/name_to_sysnum | sed 's/^/#define SYS_/' >sethostid.h
X	$(CC) -o sid -I. sid.c
X
install: sethostid sid
X	/usr/sbin/install -f /kernel/sys -m 0755 -u root -g sys ./sethostid
X	/usr/sbin/install -f /usr/local/bin -m 0755 -u root -g sys ./sid
X
clean:
X	rm -f core *.o sid sethostid sethostid.h
SHAR_EOF
  $shar_touch -am 1129220195 'hid-1.6.0/sethostid-simple-5.x/makefile' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-5.x/makefile' ||
  echo 'restore of hid-1.6.0/sethostid-simple-5.x/makefile failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-5.x/makefile'`"
  test 641 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-5.x/makefile: original size 641, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-5.x/sethostid.c ==============
if test -f 'hid-1.6.0/sethostid-simple-5.x/sethostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-5.x/sethostid.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-5.x/sethostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-5.x/sethostid.c' &&
/*
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outsethostide of business hours.
X
before you install this modify /etc/name_to_sysnum to bind sethostid to 
an _unused_ system call number
X
As far as I can determine the details of how to load system calls in
Solaris 2.3 are undocumented. I've done this by poking around in the
header files in sys and the man pages, and extrapolating from what 
I know about how loadable device drivers work and how the procedure 
works in Solaris 1.1
X
Mark Henderson <markh@wimsey.bc.ca>
14 Aug 1994
*/
X
#include <sys/param.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sys/modctl.h>
#include <sys/cred.h>
#include <sys/systeminfo.h>
X
static char serial[16];
char xyzzy_rbuf[16];
X
int sethostid();
X
struct sysent sethostid_sysent = {1,0,sethostid,0};
X
extern struct mod_ops mod_syscallops;
X
static struct modlsys modlsys = {
&mod_syscallops,
"simple sethostid v1.1", 
&sethostid_sysent,
};
X
#ifdef PRE_SOLARIS_2_5
extern systeminfo();
#else
extern longlong_t systeminfo();
#endif
X
static struct modlinkage modlinkage = {
X    MODREV_1, /* magic number */
X    &modlsys, 
X    0
};
X
#ifdef PRE_SOLARIS_2_5
struct as2 {int command; char *buf; long count;};
int new_systeminfo(struct as2 *uap, rval_t *foo)
{
X    int ret,i,bsize;
X    systeminfo(uap,foo);
X    ret = foo->r_val1;
X    if (uap->command == SI_HW_SERIAL) {
X        bsize = (uap->count > 16) ? 16 : uap->count; /* min(16,count)*/
X        if (serial[0]) {
X            for (i=0;i < bsize - 1;i++)
X                xyzzy_rbuf[i]  = serial[i];
X            xyzzy_rbuf[bsize - 1] = 0;
X            ret = strlen(xyzzy_rbuf) + 1;
X            if (copyout(xyzzy_rbuf,uap->buf,ret) < 0)
X                return EFAULT;
X        }
X    }
X    foo->r_val1 = ret;
X    return 0;
}
#else 
longlong_t new_systeminfo(int command, char *buf, long count) 
{
X	longlong_t ret;
X	int bsize,i;
X	int modified = 0;
X	ret = systeminfo(command, buf, count);
X	if (command == SI_HW_SERIAL && serial[0]) {
X       bsize = (count > 16) ? 16 : count; /* min(16,count)*/
X	   for (i=0;i < bsize - 1;i++)
X			xyzzy_rbuf[i]  = serial[i];
X		xyzzy_rbuf[bsize - 1] = 0;
X		ret = strlen(xyzzy_rbuf) + 1;
X		modified = 1;
X		if (copyout(xyzzy_rbuf,buf,ret) < 0)
X			return EFAULT;
X	}
X	if (modified)
X		return (ret << 32);
X	else
X		return ret;
}
#endif
X
struct as {int hostid; };
X
sethostid(struct as *uap, rval_t *foo)
{
X    cred_t *creds = CRED();
X    if (!suser(creds)) {
X        return EACCES;
X    }
X
X    if (!uap->hostid) {
X        serial[0] = '\0';
X        foo->r_val1 = 0;
X    }
X    else {
X        numtos( (unsigned long)uap->hostid, &serial[0]);
X        foo->r_val1 = uap->hostid;
X    }
X    return 0;
}
X
_init(void)
{
X    int status;
X    status = mod_install(&modlinkage);
X    if (!status) {
X        sysent[SYS_systeminfo].sy_narg = 3;
#ifdef PRE_SOLARIS_2_5
X        sysent[SYS_systeminfo].sy_call = new_systeminfo;
#else
X        sysent[SYS_systeminfo].sy_callc = new_systeminfo;
#endif
X        serial[0] = 0;
X    }
X    return status;
}
_fini(void)
{
X    int status;
X    status = mod_remove(&modlinkage);
X    if (!status) {
X        sysent[SYS_systeminfo].sy_narg = 3;
#ifdef PRE_SOLARIS_2_5
X        sysent[SYS_systeminfo].sy_call = systeminfo;
#else
X		/* for Solaris 2.5 and (hopefully) later */
X        sysent[SYS_systeminfo].sy_callc = systeminfo;
#endif
X    }
X    return status;
}
X
_info(struct modinfo *modinfop)
{
X    return (mod_info(&modlinkage, modinfop));
}
SHAR_EOF
  $shar_touch -am 1130093095 'hid-1.6.0/sethostid-simple-5.x/sethostid.c' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-5.x/sethostid.c' ||
  echo 'restore of hid-1.6.0/sethostid-simple-5.x/sethostid.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-5.x/sethostid.c'`"
  test 4092 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-5.x/sethostid.c: original size 4092, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-5.x/sethostid.c~ ==============
if test -f 'hid-1.6.0/sethostid-simple-5.x/sethostid.c~' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-5.x/sethostid.c~ (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-5.x/sethostid.c~ (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-5.x/sethostid.c~' &&
/*
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outsethostide of business hours.
X
before you install this modify /etc/name_to_sysnum to bind sethostid to 
an _unused_ system call number
X
As far as I can determine the details of how to load system calls in
Solaris 2.3 are undocumented. I've done this by poking around in the
header files in sys and the man pages, and extrapolating from what 
I know about how loadable device drivers work and how the procedure 
works in Solaris 1.1
X
Mark Henderson <markh@wimsey.bc.ca>
14 Aug 1994
*/
X
#include <sys/param.h>
#include <sys/syscall.h>
#include <sys/systm.h>
#include <sys/user.h>
#include <sys/modctl.h>
#include <sys/cred.h>
#include <sys/systeminfo.h>
X
static char serial[16];
char xyzzy_rbuf[16];
X
int sethostid();
X
struct sysent sethostid_sysent = {1,0,sethostid,0};
X
extern struct mod_ops mod_syscallops;
X
static struct modlsys modlsys = {
&mod_syscallops,
"simple sethostid v1.0", 
&sethostid_sysent,
};
X
extern systeminfo();
X
static struct modlinkage modlinkage = {
X    MODREV_1, /* magic number */
X    &modlsys, 
X    0
};
X
struct as2 {int command; char *buf; long count;};
int new_systeminfo(struct as2 *uap, rval_t *foo)
{
X    int ret,i,bsize;
X    systeminfo(uap,foo);
X    ret = foo->r_val1;
X    if (uap->command == SI_HW_SERIAL) {
X        bsize = (uap->count > 16) ? 16 : uap->count; /* min(16,count)*/
X        if (serial[0]) {
X            for (i=0;i < bsize - 1;i++)
X                xyzzy_rbuf[i]  = serial[i];
X            xyzzy_rbuf[bsize - 1] = 0;
X            ret = strlen(xyzzy_rbuf) + 1;
X            if (copyout(xyzzy_rbuf,uap->buf,ret) < 0)
X                return EFAULT;
X        }
X    }
X    foo->r_val1 = ret;
X    return 0;
}
X
struct as {int hostid; };
X
sethostid(struct as *uap, rval_t *foo)
{
X    cred_t *creds = CRED();
X    if (!suser(creds)) {
X        return EACCES;
X    }
X
X    if (!uap->hostid) {
X        serial[0] = '\0';
X        foo->r_val1 = 0;
X    }
X    else {
X        numtos( (unsigned long)uap->hostid, &serial[0]);
X        foo->r_val1 = uap->hostid;
X    }
X    return 0;
}
X
_init(void)
{
X    int status;
X    status = mod_install(&modlinkage);
X    if (!status) {
X        sysent[SYS_systeminfo].sy_narg = 3;
X        sysent[SYS_systeminfo].sy_call = new_systeminfo;
X        serial[0] = 0;
X    }
X    return status;
}
_fini(void)
{
X    int status;
X    status = mod_remove(&modlinkage);
X    if (!status) {
X        sysent[SYS_systeminfo].sy_narg = 3;
X        sysent[SYS_systeminfo].sy_call = systeminfo;
X    }
X    return status;
}
X
_info(struct modinfo *modinfop)
{
X    return (mod_info(&modlinkage, modinfop));
}
SHAR_EOF
  $shar_touch -am 1129215195 'hid-1.6.0/sethostid-simple-5.x/sethostid.c~' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-5.x/sethostid.c~' ||
  echo 'restore of hid-1.6.0/sethostid-simple-5.x/sethostid.c~ failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-5.x/sethostid.c~'`"
  test 3237 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-5.x/sethostid.c~: original size 3237, current size $shar_count"
fi
# ============= hid-1.6.0/sethostid-simple-5.x/sid.c ==============
if test -f 'hid-1.6.0/sethostid-simple-5.x/sid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sethostid-simple-5.x/sid.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sethostid-simple-5.x/sid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sethostid-simple-5.x/sid.c' &&
/*
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
*/
X
#include <stdio.h>
#include <sys/syscall.h>
#include <errno.h>
#include "sethostid.h"
X
main(argc, argv)
int argc;
char *argv[];
{
X  unsigned hostid;
X
X  if (argc<2) {
X    fprintf(stderr, "%s <hostid>\n", argv[0]);
X    exit(1);
X  }
X  hostid=strtoul(argv[1], NULL, 16);
X  if (syscall(SYS_sethostid, hostid)==-1) {
X    perror(argv[0]);
X    exit(1);
X  }
}  
X
SHAR_EOF
  $shar_touch -am 0816104994 'hid-1.6.0/sethostid-simple-5.x/sid.c' &&
  chmod 0600 'hid-1.6.0/sethostid-simple-5.x/sid.c' ||
  echo 'restore of hid-1.6.0/sethostid-simple-5.x/sid.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sethostid-simple-5.x/sid.c'`"
  test 1086 -eq "$shar_count" ||
    echo "hid-1.6.0/sethostid-simple-5.x/sid.c: original size 1086, current size $shar_count"
fi
# ============= hid-1.6.0/sidump.c ==============
if test -f 'hid-1.6.0/sidump.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sidump.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sidump.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sidump.c' &&
/* modify hostid reported by gethostid and sysinfo for Solaris 2.3 and 1.1
X   dynamically linked binaries 
Placed in the public domain by the author 
Mark Henderson - markh@wimsey.bc.ca - 18 July 1994
X
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
X
New feature to be included in version 1.0 of the package: 18 July 1994
the environment variable HID can be set to the desired hostid in hex.
(no leading 0x, a-f lower case)
X
In retrospect, I should have written this in perl.
X
Instructions:
X
Solaris 1.x
1. compile this program
X    cc -o sidump sidump.c
2. run it with the desired hostid as the first parameter and save the output
X    in a file with the extension .c 
X    ./sidump b0b1fb0b >foo.c
3. make foo.o from foo.c
X      gcc -fpic -c foo.c
X      ld foo.o  -assert pure-text -o foo.so
X   OR
X      cc -PIC -c foo.c
X      ld foo.o -assert pure-text -o foo.so
4. export LD_PRELOAD=$PWD/foo.so      (ksh)
X   setenv LD_PRELOAD $PWD/foo.so      (csh)
5. run the desired program
X
here's a sample session
feral> cc -o sidump sidump.c
feral> ./sidump b0b1fb0b >foo.c
feral> cc -PIC -c foo.c
feral> ld -assert pure-text foo.o -o foo.so
feral> export LD_PRELOAD=$PWD/foo.so
feral> lmhostid
feral> lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "b0b1fb0b"
feral> export HID=72000000
feral> lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "72000000"
X
--------------
Solaris 2.x
X
1. compile this program
X    gcc -DSOLARIS2 -o sidump sidump.c
2. run it with the desired hostid as the first parameter and save the output
X    in a file with the extension .c 
X    ./sidump b0b1fb0b >foo.c
3. make foo.o from foo.c
X      gcc -fpic -c foo.c
X      ld foo.o  -G -o foo.so
4. export LD_PRELOAD=$PWD/foo.so      (ksh)
X   setenv LD_PRELOAD $PWD/foo.so      (csh)
5. run the desired program
X
here's a sample session:
X
ratatosk> gcc -o sidump sidump.c
ratatosk> ./sidump b0b1fb0b >foo.c
ratatosk> gcc -fpic -c foo.c
ratatosk> ld foo.o  -G -o foo.so
ratatosk> export LD_PRELOAD=$PWD/foo.so
ratatosk> hostid
b0b1fb0b
ratatosk> lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "b0b1fb0b"
ratatosk> export HID=72000000
ratatosk> lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "72000000"
X
X
*/
X
X
#include <stdio.h>
#ifdef SOLARIS2
#include <sys/systeminfo.h>
int commands[] = {SI_HW_SERIAL, SI_SYSNAME,SI_HOSTNAME,
X SI_RELEASE,SI_VERSION,SI_MACHINE,SI_ARCHITECTURE,SI_HW_PROVIDER,
X SI_SRPC_DOMAIN};
#endif
X
#define NCOMMANDS (sizeof(commands)/sizeof(int))
X
main(argc,argv)
int argc;
char *argv[];
{
X    int i,j;
X    char buf[1024];
X    unsigned int hostid;
X    if (argc != 2) {
X        fprintf(stderr, "usage: %s hostid\n", argv[0]);
X        exit(1);
X    }
X    sscanf(argv[1], "%x", &hostid);
X    printf("#include <string.h>\n");
X    printf("#include <stdlib.h>\n");
X    printf("extern char **environ;\n");
X    printf("unsigned int xyzzy_ghid()\n");
X    printf("{\n");
X    printf("    int i,j,c; char **s; char *e;\n");
X    printf("    unsigned int hid;\n");
X    printf("    hid = 0;\n");
X    printf("    s = environ;\n");
X    printf("    for (; *s; s++) {\n");
X    printf("        e = *s;\n");
X    printf("        if (*e++ == \'H\' \n");
X    printf("            && (*e++ == \'I\')\n");
X    printf("            && (*e++ == \'D\')\n");
X    printf("            && (*e++ == \'=\'))  {\n");
X    printf("                for (j=28; (*e) && j>=0; j -=4 ) {\n");
X    printf("                    c = (-1);\n");
X    printf("                    if (*e >= \'0\' && *e <= \'9\') \n");
X    printf("                        c = *e - \'0\';\n");
X    printf("                    if (*e >= \'a\' && *e <= \'f\') \n");
X    printf("                        c = *e - \'a\' + 10;\n");
X    printf("                    e++;\n");
X    printf("                    if (c == (-1))\n");
X    printf("                        break;\n");
X    printf("                    hid = hid | (c << j);\n");
X    printf("                }\n");
X    printf("            return hid;\n");
X    printf("        }\n");
X    printf("    }\n");
X    printf("    return 0;\n");
X    printf("}\n");
X    printf("gethostid() { \n");
X    printf("unsigned x;\n");
X    printf("if (x=xyzzy_ghid()) \n");
X    printf("{return x; }");
X    printf("else return 0x%08x; }\n", hostid);
#ifdef SOLARIS2
X    printf("long sysinfo(command,buf,count)\nint command;\nchar *buf;\n");
X    printf("long count;\n{\nchar *c = buf; int i; unsigned int x,y;\n");
X    printf("switch(command) { \n");
X    printf("case %u:\n", commands[0]);
X    sprintf(buf,"%u",hostid);  /* should this be %010u ??? */
X    printf("if (!(x = xyzzy_ghid())) {\n");
X    for (j=0; j < strlen(buf); j++)
X        printf("if (c < (buf + count)) *c++ = '%c';\n", buf[j]);
X    printf("if (c < (buf + count)) *c++ = 0;\n");
X    printf("buf[count-1] = 0;\n");
X    printf("}\n");
X    printf("else {\n");
X    printf("y = 1000000000;\n");
X    printf("for (i=0; (i<10) && (i<count); i++) {\n");
X    printf("buf[i] = (x/y) + '0'; x -= (x/y) * y;");
X    printf("y/=10; }\n");
X    printf("if (count < 11) buf[count - 1] = 0 ; else buf[10] = 0;}\n");
X    printf("break;\n");
X    for (i=1; i< NCOMMANDS; i++) {
X        sysinfo(commands[i], buf,1024);
X        printf("case %u:\n", commands[i]);
X        for (j=0; j < strlen(buf); j++)
X            printf("if (c < (buf + count)) *c++ = '%c';\n", buf[j]);
X        printf("if (c < (buf + count)) *c++ = 0;\n");
X        printf("buf[count-1] = 0;\n");
X        printf("break;\n");
X    }
X    printf("default: \nreturn(-1); \n}\n");
X    printf("return(strlen(buf) + 1);}\n");
#endif
}
SHAR_EOF
  $shar_touch -am 0811082994 'hid-1.6.0/sidump.c' &&
  chmod 0600 'hid-1.6.0/sidump.c' ||
  echo 'restore of hid-1.6.0/sidump.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sidump.c'`"
  test 6378 -eq "$shar_count" ||
    echo "hid-1.6.0/sidump.c: original size 6378, current size $shar_count"
fi
# ============= hid-1.6.0/sidump_old.c ==============
if test -f 'hid-1.6.0/sidump_old.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/sidump_old.c (file already exists)'
else
  echo 'x - extracting hid-1.6.0/sidump_old.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/sidump_old.c' &&
/* modify hostid reported by gethostid and sysinfo for Solaris 2.3 
X   dynamically linked binaries 
Basically a simpler version of sidump.c - this one doesn't have hooks for
X   the HID environment variable. 
Placed in the public domain by the author 
Mark Henderson - markh@wimsey.bc.ca - 8 July 1994
X
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
this program at your own risk. The author disclaims responsibility for
any damages that might result from the use of this program, even
if they result from negligence on the part of the author.
X
Also, please don't use this program to steal software. The intended
use is for emergency situations where an application has to be moved from
one computer to another (e.g. in the event of a hardware malfunction)
and licence keys cannot be obtained quickly from the vendor. Many
vendors will not supply licence keys outside of business hours.
X
Instructions:
1. compile this program
X    gcc -o sidump sidump_old.c
2. run it with the desired hostid as the first parameter and save the output
X    in a file with the extension .c 
X    ./sidump b0b1fb0b >foo.c
3. make foo.o from foo.c
X      gcc -fpic -c foo.c
X      ld foo.o  -G -o foo.so
4. export LD_PRELOAD=$PWD/foo.so      (ksh)
X   setenv LD_PRELOAD $PWD/foo.so      (csh)
5. run the desired program
X
(Note: it actually seems enough to do the following in 3/4:
gcc -c foo.c
export LD_PRELOAD=$PWD/foo.o
)
X
here's a sample session:
X
ratatosk> gcc -o sidump sidump_old.c
ratatosk> ./sidump b0b1fb0b >foo.c
ratatosk> gcc -fpic -c foo.c
ratatosk> ld foo.o  -G -o foo.so
ratatosk> export LD_PRELOAD=$PWD/foo.so
ratatosk> hostid
b0b1fb0b
ratatosk> lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "b0b1fb0b"
X
You could wrap this in a script for convenience (q.v. newhostid)
X       Solaris 1.1)
X
*/
X
X
#include <stdio.h>
#include <sys/systeminfo.h>
int commands[] = {SI_HW_SERIAL, SI_SYSNAME,SI_HOSTNAME,
X SI_RELEASE,SI_VERSION,SI_MACHINE,SI_ARCHITECTURE,SI_HW_PROVIDER,
X SI_SRPC_DOMAIN};
X
#define NCOMMANDS (sizeof(commands)/sizeof(int))
X
main(argc,argv)
int argc;
char *argv[];
{
X    int i,j;
X    char buf[1024];
X    unsigned int hostid;
X    if (argc != 2) {
X        fprintf(stderr, "usage: %s hostid\n", argv[0]);
X        exit(1);
X    }
X    sscanf(argv[1], "%x", &hostid);
X    printf("#include <string.h>\n");
X    printf("gethostid() { return 0x%08x; }\n", hostid);
X    printf("long sysinfo(command,buf,count)\nint command;\nchar *buf;\n");
X    printf("long count;\n{\nchar *c = buf;\n");
X    printf("switch(command) { \n");
X    printf("case %u:\n", commands[0]);
X    sprintf(buf,"%u",hostid);
X    for (j=0; j < strlen(buf); j++)
X        printf("if (c < (buf + count)) *c++ = '%c';\n", buf[j]);
X    printf("if (c < (buf + count)) *c++ = 0;\n");
X    printf("buf[count-1] = 0;\n");
X    printf("break;\n");
X    for (i=1; i< NCOMMANDS; i++) {
X        sysinfo(commands[i], buf,1024);
X        printf("case %u:\n", commands[i]);
X        for (j=0; j < strlen(buf); j++)
X            printf("if (c < (buf + count)) *c++ = '%c';\n", buf[j]);
X        printf("if (c < (buf + count)) *c++ = 0;\n");
X        printf("buf[count-1] = 0;\n");
X        printf("break;\n");
X    }
X    printf("default: \nreturn(-1); \n}\n");
X    printf("return(strlen(buf) + 1);}\n");
}
SHAR_EOF
  $shar_touch -am 0811082994 'hid-1.6.0/sidump_old.c' &&
  chmod 0600 'hid-1.6.0/sidump_old.c' ||
  echo 'restore of hid-1.6.0/sidump_old.c failed'
  shar_count="`wc -c < 'hid-1.6.0/sidump_old.c'`"
  test 3434 -eq "$shar_count" ||
    echo "hid-1.6.0/sidump_old.c: original size 3434, current size $shar_count"
fi
# ============= hid-1.6.0/spoof-solaris1/README ==============
if test ! -d 'hid-1.6.0/spoof-solaris1'; then
  echo 'x - creating directory hid-1.6.0/spoof-solaris1'
  mkdir 'hid-1.6.0/spoof-solaris1'
fi
if test -f 'hid-1.6.0/spoof-solaris1/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/spoof-solaris1/README (file already exists)'
else
  echo 'x - extracting hid-1.6.0/spoof-solaris1/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/spoof-solaris1/README' &&
Mark Henderson <markh@wimsey.bc.ca>, <henderso@netcom.com>
X
This package allows you modify the hostname and hostid returned
by gethostname and gethostid depending upon the group membership
of the process calling gethostname and gethostid.
X
It has been tested under Solaris 1.1.
X
Together with vif-1.0 by Steinar Haug, this allows you to also spoof IP addresses
X  in a limited sense. You can get vif-1.0 from the following ftp sites:
X
X  ftp.netcom.com:/pub/he/henderso
X  ftp.rahul.net:/pub/mch
X  ugle.unit.no:/pub/unix/network/vif-1.0.tar.gz
X  any alt.sources archive (posted on 15 Jan 1995 00:45:27 GMT)
X
to use this:
X
example/instructions
X         - you want certain processes to see the hostname joe.test.com
X         - the "real" hostname of the host is ratatosk
X
You'll need to be root to do most of this. 
X
0. make sure that joe.test.com is in /etc/hosts, the YP hosts database or
X   DNS as appropriate.
1. fetch, unpack, make, and install vif-1.0
2. install run (source is in ../run)
3. make load
4. make sethostid
5. ./sethostid 0 72000000 joe.test.com
X   which should modify the hostid and hostname for processes with gid 900
X   to be 0x72000000 and joe.test.com resp.
6. /usr/etc/ifconfig vif0 joe.test.com up
X   now "telnet joe.test.com" should connect to the local host
7. /usr/etc/route add joe.test.com ratatosk 0
8. If you want another host (say squirrel) to also be able to communicate
X   with ratatosk as joe.test.com, login to squirrel and do
X   /usr/etc/route add joe.test.com ratatosk 1
X   go back to ratatosk
9. run 0 /bin/sh
X   hostname will return joe.test.com
X   hostid will return 0x72000000
X   most programs that run in group 900 and try to determine the IP address of 
X       the machine will think it is the IP address of joe.test.com. The point 
X       is that this will spoof many licence manager daemons which are locked to 
X       hostname and/or IP address.
X
N.B. sethostid.exec must be executable. Depending upon where you got
the distribution you might have to chmod +x it.
X
SHAR_EOF
  $shar_touch -am 0201162395 'hid-1.6.0/spoof-solaris1/README' &&
  chmod 0700 'hid-1.6.0/spoof-solaris1/README' ||
  echo 'restore of hid-1.6.0/spoof-solaris1/README failed'
  shar_count="`wc -c < 'hid-1.6.0/spoof-solaris1/README'`"
  test 2009 -eq "$shar_count" ||
    echo "hid-1.6.0/spoof-solaris1/README: original size 2009, current size $shar_count"
fi
# ============= hid-1.6.0/spoof-solaris1/hid_flags.h ==============
if test -f 'hid-1.6.0/spoof-solaris1/hid_flags.h' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.6.0/spoof-solaris1/hid_flags.h (file already exists)'
else
  echo 'x - extracting hid-1.6.0/spoof-solaris1/hid_flags.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.6.0/spoof-solaris1/hid_flags.h' &&
#define HID_HOSTID 0x01
#define HID_HOSTNAME 0x02
SHAR_EOF
  $shar_touch -am 0201153995 'hid-1.6.0/spoof-solaris1/hid_flags.h' &&
  chmod 0700 'hid-1.6.0/spoof-solaris1/hid_flags.h' ||
  echo 'restore of hid-1.6.0/spoof-solaris1/hid_flags.h failed'
  shar_count="`wc -c < 'hid-1.6.0/spoof-solaris1/hid_flags.h'`"
  test 50 -eq "$shar_count" ||
    echo "hid-1.6.0/spoof-solaris1/hid_flags.h: original size 50, current size $shar_count"
fi
: || echo 'restore of hid-1.6.0/spoof-solaris1/kern_hostid.c failed'
echo 'End of part 4, continue with part 5'
exit 0


