Article 12780 of alt.sources:
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!spool.mu.edu!agate!news.mindlink.net!van-bc!vanbc.wimsey.com!not-for-mail
From: markh@vanbc.wimsey.com (Mark C. Henderson)
Newsgroups: alt.sources
Subject: change sun hostid 1.5.0 -- part 4/4
Date: 8 Sep 1995 09:16:52 -0700
Organization: Online at Wimsey Information Services Inc - Vancouver, Canada
Lines: 1476
Message-ID: <42pq9k$m29@vanbc.wimsey.com>
NNTP-Posting-Host: vanbc.wimsey.com


#!/bin/sh
# This is `hid150.04' (part 4 of a multipart archive).
# Do not concatenate these parts, unpack them in order with `/bin/sh'.
# File `hid-1.5.0/sethostid-simple-5.3/sethostid.c' is being continued...
#
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
#
if test ! -r _sharseq.tmp; then
  echo 'Please unpack part 1 first!'
  exit 1
fi
shar_sequence=`cat _sharseq.tmp`
if test "$shar_sequence" != 4; then
  echo "Please unpack part $shar_sequence next!"
  exit 1
fi
if test ! -f _sharnew.tmp; then
  echo 'x - still skipping hid-1.5.0/sethostid-simple-5.3/sethostid.c'
else
  echo 'x - continuing file hid-1.5.0/sethostid-simple-5.3/sethostid.c'
  sed 's/^X//' << 'SHAR_EOF' >> 'hid-1.5.0/sethostid-simple-5.3/sethostid.c' &&
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
  echo 'File hid-1.5.0/sethostid-simple-5.3/sethostid.c is complete' &&
  $shar_touch -am 0816104994 'hid-1.5.0/sethostid-simple-5.3/sethostid.c' &&
  chmod 0600 'hid-1.5.0/sethostid-simple-5.3/sethostid.c' ||
  echo 'restore of hid-1.5.0/sethostid-simple-5.3/sethostid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/sethostid-simple-5.3/sethostid.c'`"
  test 3237 -eq "$shar_count" ||
    echo "hid-1.5.0/sethostid-simple-5.3/sethostid.c: original size 3237, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/sethostid-simple-5.3/sid.c ==============
if test -f 'hid-1.5.0/sethostid-simple-5.3/sid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/sethostid-simple-5.3/sid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/sethostid-simple-5.3/sid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/sethostid-simple-5.3/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.5.0/sethostid-simple-5.3/sid.c' &&
  chmod 0600 'hid-1.5.0/sethostid-simple-5.3/sid.c' ||
  echo 'restore of hid-1.5.0/sethostid-simple-5.3/sid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/sethostid-simple-5.3/sid.c'`"
  test 1086 -eq "$shar_count" ||
    echo "hid-1.5.0/sethostid-simple-5.3/sid.c: original size 1086, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/sidump.c ==============
if test -f 'hid-1.5.0/sidump.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/sidump.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/sidump.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.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.5.0/sidump.c' &&
  chmod 0600 'hid-1.5.0/sidump.c' ||
  echo 'restore of hid-1.5.0/sidump.c failed'
  shar_count="`wc -c < 'hid-1.5.0/sidump.c'`"
  test 6378 -eq "$shar_count" ||
    echo "hid-1.5.0/sidump.c: original size 6378, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/sidump_old.c ==============
if test -f 'hid-1.5.0/sidump_old.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/sidump_old.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/sidump_old.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.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.5.0/sidump_old.c' &&
  chmod 0600 'hid-1.5.0/sidump_old.c' ||
  echo 'restore of hid-1.5.0/sidump_old.c failed'
  shar_count="`wc -c < 'hid-1.5.0/sidump_old.c'`"
  test 3434 -eq "$shar_count" ||
    echo "hid-1.5.0/sidump_old.c: original size 3434, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/README ==============
if test ! -d 'hid-1.5.0/spoof-solaris1'; then
  echo 'x - creating directory hid-1.5.0/spoof-solaris1'
  mkdir 'hid-1.5.0/spoof-solaris1'
fi
if test -f 'hid-1.5.0/spoof-solaris1/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/README (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.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.5.0/spoof-solaris1/README' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/README' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/README failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/README'`"
  test 2009 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/README: original size 2009, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/hid_flags.h ==============
if test -f 'hid-1.5.0/spoof-solaris1/hid_flags.h' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/hid_flags.h (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/hid_flags.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris1/hid_flags.h' &&
#define HID_HOSTID 0x01
#define HID_HOSTNAME 0x02
SHAR_EOF
  $shar_touch -am 0201153995 'hid-1.5.0/spoof-solaris1/hid_flags.h' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/hid_flags.h' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/hid_flags.h failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/hid_flags.h'`"
  test 50 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/hid_flags.h: original size 50, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/kern_hostid.c ==============
if test -f 'hid-1.5.0/spoof-solaris1/kern_hostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/kern_hostid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/kern_hostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris1/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 <sys/kernel.h>
#include <sun/vddrv.h>
#include "hid_flags.h"
X
#define NHOSTID 10
X
static unsigned hostid[NHOSTID]={0};
static char xhostname[NHOSTID][MAXHOSTNAMELEN];
static int hid_flags[NHOSTID];
X
int sethostid();
int gethostname();
X
static struct sysent sethostid_sysent = { 5, 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
Gethostid()
{
X    unsigned machineid;
X    u_short gid;
X    int i;
X
X    gethostid();
X    machineid = u.u_r.r_val1;
X
X    gid = u.u_gid;
X    if (gid >= 900 && gid < 900+NHOSTID) {
X        if (hid_flags[gid-900] & HID_HOSTID) {
X            u.u_r.r_val1 = hostid[gid-900] ? hostid[gid-900] : machineid;
X            return;
X        }
X    }
X
X    i = 0;
X    while (gid=u.u_groups[i++]) {
X        if (gid >= 900 && gid < 900+NHOSTID) {
X            if (hid_flags[gid-900] & HID_HOSTID) {
X                u.u_r.r_val1 = hostid[gid-900] ? hostid[gid-900] : machineid;
X                return;
X            }
X        }
X    }
X    u.u_r.r_val1 = machineid;
X    return;
}
X
Gethostname(uap)
X    register struct a {
X        char *namebuf;
X        int namebuflen;
X    } *uap;
{
X    char *hp;
X    int hl,i;
X    u_short gid;
X
X    gid = u.u_gid;
X    hp = hostname;
X    hl = hostnamelen;
X    if (gid >= 900 && gid < 900+NHOSTID) {
X        if (hid_flags[gid-900] & HID_HOSTNAME) {
X            hp = xhostname[gid-900]; hl = strlen(xhostname[gid-900]);
X        }
X    }
X
X    i = 0;
X    while (gid=u.u_groups[i++]) {
X        if (gid >= 900 && gid < 900+NHOSTID) {
X            if (hid_flags[gid-900] & HID_HOSTNAME) {
X                hp = xhostname[gid-900]; hl = strlen(xhostname[gid-900]);
X            }
X        }
X    }
X    hl++;
X    if (hl > uap->namebuflen) 
X        hl = uap->namebuflen;
X    if (copyout(hp, uap->namebuf, hl) < 0) {
X         u.u_r.r_val1 = (-1); u.u_error = EFAULT; return;
X    }
X    u.u_r.r_val1 = 0;
X    u.u_error = 0;
X    return;
}
X
sethostid(uap)
X    register struct a {
X        int n;
X        int flags;
X        char *hostname;
X        int hostnamelen;
X        unsigned hostid;
X    } *uap;
{
X    if (!suser()) {
X        u.u_r.r_val1 = (-1); u.u_error = EACCES; return;
X    }
X
X    if ((uap->n >= NHOSTID )||(uap->n < 0)) {  
X        u.u_r.r_val1 = (-1); u.u_error = EINVAL; return;
X    }
X
X    hid_flags[uap->n] = uap->flags;
X    if (uap->flags & HID_HOSTID) {
X        hostid[uap->n] = uap->hostid;
X    }
X    if (uap->flags & HID_HOSTNAME) {
X        if (uap->hostnamelen >= MAXHOSTNAMELEN || uap->hostnamelen < 0) {
X            u.u_r.r_val1 = (-1); u.u_error = EINVAL; return;
X        }
X        if ((copyin(uap->hostname,xhostname[uap->n],uap->hostnamelen) < 0)) {
X            u.u_r.r_val1 = (-1); u.u_error = EFAULT; return;
X        }
X        xhostname[uap->n][uap->hostnamelen] = '\0'; /* null terminate */
X    }
X    u.u_r.r_val1 = 0;
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  int i;
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    sysent[SYS_gethostname].sy_narg = 2;
X    sysent[SYS_gethostname].sy_call = Gethostname;
X    for (i=0; i<NHOSTID; i++) {
X        xhostname[i][0] = '\0';
X        hostid[i] = 0x0;
X        hid_flags[i] = 0;
X    }
X    return 0;
X  case VDUNLOAD:
X    sysent[SYS_gethostname].sy_narg = 2;
X    sysent[SYS_gethostname].sy_call = gethostname;
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 0201161795 'hid-1.5.0/spoof-solaris1/kern_hostid.c' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/kern_hostid.c' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/kern_hostid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/kern_hostid.c'`"
  test 4596 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/kern_hostid.c: original size 4596, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/makefile ==============
if test -f 'hid-1.5.0/spoof-solaris1/makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/makefile (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris1/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 0201153995 'hid-1.5.0/spoof-solaris1/makefile' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/makefile' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/makefile failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/makefile'`"
  test 282 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/makefile: original size 282, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/sethostid.c ==============
if test -f 'hid-1.5.0/spoof-solaris1/sethostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/sethostid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/sethostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris1/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"
#include "hid_flags.h"
X
main(argc, argv)
int argc;
char *argv[];
{
X  unsigned hostid;
X  int n;
X
X  if (argc<3) {
X    fprintf(stderr, "%s <n> <hostid> [hostname]\n", argv[0]);
X    exit(1);
X  }
X  n=atoi(argv[1]);
X  sscanf(argv[2], "%x", &hostid);
X  fprintf(stderr, "will set hostid for group %d set to %08x\n", 900+n,hostid);
X  if (argc == 4) {
X    fprintf(stderr, "will set for hostname group %d set to %s\n", 900+n,argv[3]);
X    if (syscall(SYS_sethostid, n, HID_HOSTID|HID_HOSTNAME, 
X        argv[3], strlen(argv[3]), hostid)==-1) {
X      perror(argv[0]);
X      exit(1);
X    }
X  }
X  else {
X    if (syscall(SYS_sethostid, n, HID_HOSTID, 
X        NULL, 0, hostid)==-1) {
X      perror(argv[0]);
X      exit(1);
X    }
X  }
}  
SHAR_EOF
  $shar_touch -am 0201153995 'hid-1.5.0/spoof-solaris1/sethostid.c' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/sethostid.c' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/sethostid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/sethostid.c'`"
  test 1539 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/sethostid.c: original size 1539, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris1/sethostid.exec ==============
if test -f 'hid-1.5.0/spoof-solaris1/sethostid.exec' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris1/sethostid.exec (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris1/sethostid.exec (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris1/sethostid.exec' &&
#!/bin/csh -f
echo "#define SYS_sethostid $3" > sethostid.h
SHAR_EOF
  $shar_touch -am 0201153995 'hid-1.5.0/spoof-solaris1/sethostid.exec' &&
  chmod 0700 'hid-1.5.0/spoof-solaris1/sethostid.exec' ||
  echo 'restore of hid-1.5.0/spoof-solaris1/sethostid.exec failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris1/sethostid.exec'`"
  test 60 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris1/sethostid.exec: original size 60, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris2/README ==============
if test ! -d 'hid-1.5.0/spoof-solaris2'; then
  echo 'x - creating directory hid-1.5.0/spoof-solaris2'
  mkdir 'hid-1.5.0/spoof-solaris2'
fi
if test -f 'hid-1.5.0/spoof-solaris2/README' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris2/README (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris2/README (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris2/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 for Solaris 2.3 - just be reasonable if you
are using 2.4)
X
adb -k /dev/ksyms /dev/mem
sysentsize/D
^D        #  i.e. control-D
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
Now reboot your system.
X
2. Look at the makefile and check that the location of the C compiler is
right for your system. 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 and hostname for group 900 to be 
23000000 and joe.test.com respectively by typing
X./sid 0 23000000 joe.test.com
X
You'll probably want to make sure that joe.test.com is in whatever
name->ip address resolution scheme you use. (DNS,NIS, files)
X
X
6. 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
If you also need to "spoof" IP addresses, proceed as follows. Otherwise
you can stop here.
X
7. To make the system think it has additional IP addresses (say the one
X   corresponding to joe.test.com) you can use ifconfig
X
X   /usr/sbin/ifconfig lo0:1 joe.test.com up       # joe.test.com
X   /usr/sbin/ifconfig lo0:2 192.1.1.1 up          # also be 192.1.1.1
X
8. add a route to joe.test.com
X    /usr/sbin/route add joe.test.com ratatosk 0
X    (where ratatosk is the real name of the local host)
X
9. compile and link run (in ../run) if you haven't already done this.
X
10. If you are running YP/NIS you need to do the following
X    run 0 /usr/sbin/rpcbind
X    run 0 /usr/lib/netsvc/yp/ypbind -broadcast
there will be some console messages from rpcbind, but you will have
two copies of rpcbind.
X
You may also need to start up rpcbind as above for other applications.
X
11. If you want another host, say squirrel to be able to reach joe.test.com
X    login to squirrel and execute
X    route add joe.test.com ratatosk 1
X    (where ratatosk is the real name of the local host)
X
X    then from squirrel when you "telnet joe.test.com" you'll get to 
X    ratatosk.
X
X
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.
SHAR_EOF
  $shar_touch -am 0627001695 'hid-1.5.0/spoof-solaris2/README' &&
  chmod 0700 'hid-1.5.0/spoof-solaris2/README' ||
  echo 'restore of hid-1.5.0/spoof-solaris2/README failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris2/README'`"
  test 3104 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris2/README: original size 3104, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris2/hid_flags.h ==============
if test -f 'hid-1.5.0/spoof-solaris2/hid_flags.h' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris2/hid_flags.h (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris2/hid_flags.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris2/hid_flags.h' &&
#define HID_HOSTID 0x01
#define HID_HOSTNAME 0x02
SHAR_EOF
  $shar_touch -am 0201153895 'hid-1.5.0/spoof-solaris2/hid_flags.h' &&
  chmod 0700 'hid-1.5.0/spoof-solaris2/hid_flags.h' ||
  echo 'restore of hid-1.5.0/spoof-solaris2/hid_flags.h failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris2/hid_flags.h'`"
  test 50 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris2/hid_flags.h: original size 50, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris2/makefile ==============
if test -f 'hid-1.5.0/spoof-solaris2/makefile' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris2/makefile (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris2/makefile (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris2/makefile' &&
CFLAGS = -D_KERNEL 
ASFLAGS = -P
CC = /opt/gnu/bin/gcc
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/sbin -m 0755 -u root -g sys ./sid
X
clean:
X	rm -f core *.o sid sethostid sethostid.h
SHAR_EOF
  $shar_touch -am 0201165895 'hid-1.5.0/spoof-solaris2/makefile' &&
  chmod 0700 'hid-1.5.0/spoof-solaris2/makefile' ||
  echo 'restore of hid-1.5.0/spoof-solaris2/makefile failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris2/makefile'`"
  test 487 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris2/makefile: original size 487, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris2/sethostid.c ==============
if test -f 'hid-1.5.0/spoof-solaris2/sethostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris2/sethostid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris2/sethostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris2/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
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>
1 Oct 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/utsname.h>
#include <sys/systeminfo.h>
#include <netdb.h>
#include "hid_flags.h"
X
#define NHOSTID 10
X
static char serials[NHOSTID][16];
char xyzzy_rbuf[SYS_NMLN];
char xhostname[NHOSTID][SYS_NMLN];
int hid_flags[NHOSTID];
X
int sethostid();
X
struct sysent sethostid_sysent = {5,0,sethostid,0};
X
extern struct mod_ops mod_syscallops;
X
static struct modlsys modlsys = {
&mod_syscallops,
"spoof v1.0", 
&sethostid_sysent,
};
X
extern systeminfo();
extern uname();
X
static struct modlinkage modlinkage = {
X    MODREV_1, /* magic number */
X    &modlsys, 
X    0
};
X
struct as3 {struct utsname *up;};
int new_uname(struct as3 *uap, rval_t *foo)
{
X    int ret,i,bsize;
X    gid_t gid;
X    cred_t *creds = CRED();
X    uname(uap,foo);
X    ret = foo->r_val1;
X    gid = creds->cr_gid;
X    bsize = SYS_NMLN;
X    if ((gid >= 900 && gid < 900+NHOSTID) && 
X            (hid_flags[gid-900] & HID_HOSTNAME)) {
X        if (xhostname[gid - 900][0]) {
X            for (i=0;i < bsize - 1;i++)
X                xyzzy_rbuf[i]  = xhostname[gid-900][i];
X            xyzzy_rbuf[bsize - 1] = 0;
X            ret = strlen(xyzzy_rbuf) + 1;
X            if (copyout(xyzzy_rbuf,uap->up->nodename,ret) < 0)
X                return EFAULT;
X        }
X    }
X    for (gid = 900; gid < 900+NHOSTID; gid++) {
X        if (groupmember(gid, creds)) {
X            if ((hid_flags[gid-900]&HID_HOSTNAME)&&xhostname[gid-900][0]) {
X                for (i=0;i< bsize - 1;i++)
X                    xyzzy_rbuf[i]  = xhostname[gid-900][i];
X                xyzzy_rbuf[bsize - 1] = 0;
X                ret = strlen(xyzzy_rbuf) + 1;
X                if (copyout(xyzzy_rbuf,uap->up->nodename,ret) < 0)
X                    return EFAULT;
X                break;
X            }
X        }
X    }
X    foo->r_val1 = ret;
X    return 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    gid_t gid;
X    cred_t *creds = CRED();
X    systeminfo(uap,foo);
X    ret = foo->r_val1;
X    if (uap->command == SI_HW_SERIAL) {
X        gid = creds->cr_gid;
X        bsize = (uap->count > 16) ? 16 : uap->count; /* min(16,count)*/
X        if ((gid >= 900 && gid < 900+NHOSTID) && 
X                (hid_flags[gid-900] & HID_HOSTID)) {
X            if (serials[gid - 900][0]) {
X                for (i=0;i < bsize - 1;i++)
X                    xyzzy_rbuf[i]  = serials[gid-900][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        for (gid = 900; gid < 900+NHOSTID; gid++) {
X            if (groupmember(gid, creds)) {
X                if ((hid_flags[gid-900]&HID_HOSTID)&&serials[gid - 900][0]) {
X                    for (i=0;i< bsize - 1;i++)
X                        xyzzy_rbuf[i]  = serials[gid-900][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                    break;
X                }
X            }
X        }
X    }
X    if (uap->command == SI_HOSTNAME) {
X        gid = creds->cr_gid;
X        bsize = (uap->count > SYS_NMLN) ? SYS_NMLN: uap->count;
X        if ((gid >= 900 && gid < 900+NHOSTID) && 
X                (hid_flags[gid-900] & HID_HOSTNAME)) {
X            if (xhostname[gid - 900][0]) {
X                for (i=0;i < bsize - 1;i++)
X                    xyzzy_rbuf[i]  = xhostname[gid-900][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        for (gid = 900; gid < 900+NHOSTID; gid++) {
X            if (groupmember(gid, creds)) {
X                if ((hid_flags[gid-900]&HID_HOSTNAME)&&xhostname[gid-900][0]) {
X                    for (i=0;i< bsize - 1;i++)
X                        xyzzy_rbuf[i]  = xhostname[gid-900][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                    break;
X                }
X            }
X        }
X    }
X    foo->r_val1 = ret;
X    return 0;
}
X
struct as {int n; int flags; char *hostname; int hostnamelen;
X    unsigned 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->n >= NHOSTID )||(uap->n < 0)) {  
X        return EINVAL;
X    }
X    hid_flags[uap->n] = uap->flags; 
X    if (hid_flags[uap->n] & HID_HOSTID) 
X        numtos( (unsigned long)uap->hostid, &serials[uap->n][0]);
X    if (hid_flags[uap->n] & HID_HOSTNAME) {
X        if (uap->hostnamelen >= SYS_NMLN || uap->hostnamelen < 0) 
X            return EINVAL;
X        if ((copyin(uap->hostname,xhostname[uap->n],uap->hostnamelen) < 0)) 
X            return EFAULT; 
X        xhostname[uap->n][uap->hostnamelen] = '\0'; /* null terminate */
X    }
X    foo->r_val1 = 0;
X    return 0;
}
X
_init(void)
{
X    int i,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        sysent[SYS_uname].sy_narg = 1;
X        sysent[SYS_uname].sy_call = new_uname;
X        for (i=0; i < NHOSTID; i++)  {
X            serials[i][0] = 0;
X            xhostname[i][0] =  0;
X        }
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        sysent[SYS_uname].sy_narg = 1;
X        sysent[SYS_uname].sy_call = uname;
X    }
X    return status;
}
X
_info(struct modinfo *modinfop)
{
X    return (mod_info(&modlinkage, modinfop));
}
SHAR_EOF
  $shar_touch -am 0201164595 'hid-1.5.0/spoof-solaris2/sethostid.c' &&
  chmod 0700 'hid-1.5.0/spoof-solaris2/sethostid.c' ||
  echo 'restore of hid-1.5.0/spoof-solaris2/sethostid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris2/sethostid.c'`"
  test 7239 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris2/sethostid.c: original size 7239, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/spoof-solaris2/sid.c ==============
if test -f 'hid-1.5.0/spoof-solaris2/sid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/spoof-solaris2/sid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/spoof-solaris2/sid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/spoof-solaris2/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"
#include "hid_flags.h"
X
main(argc, argv)
int argc;
char *argv[];
{
X  unsigned hostid;
X  int n;
X
X  if (argc<4) {
X    fprintf(stderr, "%s <n> <hostid> <hostname>\n", argv[0]);
X    exit(1);
X  }
X  n=atoi(argv[1]);
X  hostid=strtoul(argv[2], NULL, 16);
X  fprintf(stderr, "will set hostid for group %d set to %08x\n", 900+n,hostid);
X  fprintf(stderr, "will set for hostname group %d set to %s\n", 900+n,argv[3]);
X  if (syscall(SYS_sethostid, n, HID_HOSTID|HID_HOSTNAME, 
X        argv[3], strlen(argv[3]), hostid)==-1) {
X    perror(argv[0]);
X    exit(1);
X  }
}  
X
SHAR_EOF
  $shar_touch -am 0201153895 'hid-1.5.0/spoof-solaris2/sid.c' &&
  chmod 0700 'hid-1.5.0/spoof-solaris2/sid.c' ||
  echo 'restore of hid-1.5.0/spoof-solaris2/sid.c failed'
  shar_count="`wc -c < 'hid-1.5.0/spoof-solaris2/sid.c'`"
  test 1374 -eq "$shar_count" ||
    echo "hid-1.5.0/spoof-solaris2/sid.c: original size 1374, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.5.0/sysinfo.c ==============
if test -f 'hid-1.5.0/sysinfo.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.5.0/sysinfo.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.5.0/sysinfo.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.5.0/sysinfo.c' &&
/* make sure that errno is set correctly in MT applications */
#define _REENTRANT
X
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <errno.h>
#include <sys/systeminfo.h>
X
int sysinfo(command, buf, count)
int command; char *buf; long count;
{
switch (command)
X  {
X  case SI_HW_SERIAL:
X    {
X      char *hid;
X
X      if ((hid = getenv ("SI_HW_SERIAL")) != 0)
X	{
X	  strncpy (buf, hid, count);
X	  buf[count - 1] = '\0';
X	  return strlen (hid) + 1;
X	}
X    }
X  default:
X    {
X      long (*real_sysinfo) ();
X
X      if ((real_sysinfo = (long (*)()) dlsym (RTLD_NEXT, "sysinfo")) == 0)
X	{
X	  errno = EINVAL;
X	  return -1;
X	}
X      return real_sysinfo (command, buf, count);
X    }
X  }
}
SHAR_EOF
  $shar_touch -am 0209101595 'hid-1.5.0/sysinfo.c' &&
  chmod 0600 'hid-1.5.0/sysinfo.c' ||
  echo 'restore of hid-1.5.0/sysinfo.c failed'
  shar_count="`wc -c < 'hid-1.5.0/sysinfo.c'`"
  test 695 -eq "$shar_count" ||
    echo "hid-1.5.0/sysinfo.c: original size 695, current size $shar_count"
  rm -f _sharnew.tmp
fi
rm -f _sharseq.tmp
echo 'You have unpacked the last part'
exit 0
-- 
Mark Henderson -- markh@wimsey.bc.ca, henderso@netcom.com, mch@squirrel.com
PGP 1024/C58015E3 fingerprint=21 F6 AF 2B 6A 8A 0B E1 A1 2A 2A 06 4A D5 92 46
cryptography archive maintainer  --  ftp://ftp.wimsey.com/pub/crypto
ftp://ftp.netcom.com/pub/he/henderso/change-sun-hostid-1.4.9.tar.gz


