These programs are distributed in the hope that they will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. You use
these programs at your own risk. The author disclaims responsibility for
any damages that might result from the use of these programs, even
if the damages result from negligence on the part of the author.

Please don't use these 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 or when
your NVRAM gets wiped out by some unfortunate accident.

----------------------------------------------------------------------

hid.c (Solaris 1.x only)
- change hostid reported by Solaris 1.x/SUN OS 4.1.x gethostid

1. compile hid.c
    e.g. cc -o hid hid.c
2. run hid with your desired hostid and it will output
   a script to stdout that will change the value reported by
   gethostid
    e.g. for hostid b0b1fb0b  (hex)
         ./hid b0b1fb0b >script.sh
         sh script.sh

    Unless your system security is terrible, you will have to run
    script.sh as root.

    or simply (as root)
        ./hid b0b1fb0b | sh

3. Rebooting will undo this change, if you want to make it permanent,
   you have two options
   a. just place the script output by hid in your /etc/rc.local
      file

   the script will look something like:

    #!/bin/sh
    # this script sets the hostid to b0b1bb0b
    adb -w -k /vmunix /dev/mem <<END
    _gethostid+4/W 112c2c6e
    _gethostid+8/W 9012230b
    END

    b. Modify hid so that the "/W" in the output is "?W" or just
       modify the file I call script.sh above. This writes 
       the changes to your /vmunix file instead of just to the in-core
       kernel image.

    Make a backup copy of your /vmunix before you try this.
    
    e.g.

    #!/bin/sh
    # modified output from "hid b0b1fb0b"
    # this script modifies /vmunix so that gethostid always reports b0b1fb0b
    adb -w -k /vmunix /dev/mem <<END
    _gethostid+4?W 112c2c6e
    _gethostid+8?W 9012230b
    END
   
    Note that you always input the hostid in hexadecimal, without a leading
    0x. hid doesn't do a sanity check on its parameter, so you need to
    be careful about the exact form of this parameter.

    There are some more technical details in the comment at the beginning
    of hid.c

----------------------------------------------------------------------

hid_solaris2.c (Solaris 2.3 - I don't know about other 2.x versions)
- change hostid reported by Solaris 2.3 gethostid and sysinfo

1. Compile hid_solaris2.c to make the binary hid
    gcc -o hid hid_solaris2.c
    (or use another compiler)

2. run hid with your desired hostid and it will output
   a script to stdout that will change the value reported by
   gethostid
    e.g. for hostid b0b1fb0b  (hex)
         ./hid b0b1fb0b >script.sh
         sh script.sh

    Unless your system security is terrible, you will have to run
    script.sh as root.

    or simply (as root)
        ./hid b0b1fb0b | sh

3. Rebooting will undo the change. If you want to make it "permanent",
   i.e. have this new hostid every time your reboot, put the output
   from hid in one of the system startup files.

----------------------------------------------------------------------

sidump.c (Solaris 2.3/1.x)

modify hostid reported by gethostid and sysinfo for Solaris 2.3 
   dynamically linked non-setuid/setgid binaries. You do not need
   to be root for this.

new for 0.8.8 - you can override the desired hostid on a per process
  basis by setting the environment variable HID to the desired hostid
  in hex - as usual - with no leading 0x
  e.g. export HID=fedc1234   (ksh)
       setenv HID "fedc1234" (csh)

Instructions:

Solaris 1.x
1. compile this program
    cc -o sidump sidump.c  (or use gcc)
2. run it with the desired hostid as the first parameter and save the output
    in a file with the extension .c 
    ./sidump b0b1fb0b >foo.c
3. make foo.o from foo.c
      gcc -fpic -c foo.c
      ld foo.o  -assert pure-text -o foo.so
   OR
      cc -PIC -c foo.c
      ld foo.o -assert pure-text -o foo.so
4. export LD_PRELOAD=$PWD/foo.so      (ksh)
   setenv LD_PRELOAD $PWD/foo.so      (csh)
5. run the desired program

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"

--------------
Solaris 2.x

1. compile this program
    gcc -DSOLARIS2 -o sidump sidump.c
2. run it with the desired hostid as the first parameter and save the output
    in a file with the extension .c 
    ./sidump b0b1fb0b >foo.c
3. make foo.o from foo.c
      gcc -fpic -c foo.c
      ld foo.o  -G -o foo.so
4. export LD_PRELOAD=$PWD/foo.so      (ksh)
   setenv LD_PRELOAD $PWD/foo.so      (csh)
5. run the desired program

here's a sample session:

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"

--
To undo this just unset LD_PRELOAD. This only effects processes
for which LD_PRELOAD points to the object you create.


---------------------------------------------------------------------
newhostid - Solaris 2.3 and Solaris 1.1
Again only for dynamically linked non setuid/setgid binaries.
  Run a single command "with a different hostid"

Simply type
newhostid Base10Hostid command [args]

e.g.
for hostid 72000000 (Hex) type
newhostid 1912602624 command arg1 arg2 arg3 ...

An older version for Solaris 1.1 only is also provided in newhostid.old
the syntax for this one is slightly different, just
newhostid 72000000 command arg1 arg2 arg3 ...
to run command with hostid 72000000 (all in hex)

---------------------------------------------------------------------

nvram.c
get/change hostid in NVRAM -- Solaris 1.1 and Sun4c or Sun4m only

This program is still experimental. Dangerous and tricky stuff.  If you
are unwilling to experiment and clean up after disasters don't use it.
USE AT YOUR OWN RISK.  If this program malfunctions or it is misused,
you can get your Sun into a state where it will not boot, even from
CDROM. In particular, you should avoid changing the most significant
byte of your hostid which identifies your system type on many Sun
models.

1. Read the complete instructions before you proceed. You should
   probably also read nvram.c

2. compile nvram
   cc -o nvram nvram.c

2a. If you aren't already root, become root

3. Run nvram without any parameters.
If it fails with some bizarre error message, then your architecture
is not supported. If you don't mind hacking the kernel you can probably
hack in support for your architecture.  If you send me mods I'll fold
them in to the distribution.  

It should suggest a few adb commands to execute to make a kernel 
modification.

4. Run nvram again without any parameters.  It just prints out the
hostid and hw ethernet address.  Check this against the arp tables on
another machine or against the information displayed on boot. If it is
not correct, do not proceed with the next step.

5. now you can try and modify the hostid by running
nvram with the desired hostid as the second parameter (without 0x)
e.g.
nvram b0b1fb0b

6. Run the eeprom command suggested by the program.

7. reboot (and cross your fingers).


---------------------------------------------------------------------
hostid-by-egid

see hostid-by-egid/README. I've only tested this on a Sparc LX running
Solaris 1.1C
---------------------------------------------------------------------
hostid-by-egid-modload

This is similar to hostid-by-egid but you don't have to go off and 
completely recompile your kernel. It loads a new system call using 
modload. You can restore your system state with modunload.

see hostid-by-egid-modload/README. I've only tested this on a Sparc 
LX running Solaris 1.1C

---------------------------------------------------------------------
hostid-by-egid-solaris2

Version of hostid-by-egid-modload for Solaris 2.3
see hostid-by-egid-solaris2/README.

---------------------------------------------------------------------
run is a convenience program which will run a command with a group id
in the range 900,...,909 added to its group list. For use with the
hostid-by-egid stuff. Works with both Solaris 1.1 and 2.3.

---------------------------------------------------------------------

nvram.info - this gives some information on modifying the NVRAM
from the Openprom monitor.

