Article 12734 of alt.sources:
Newsgroups: alt.sources
Path: nntpd.lkg.dec.com!crl.dec.com!crl.dec.com!caen!hookup!news.mathworks.com!tank.news.pipex.net!pipex!news.sprintlink.net!noc.netcom.net!netcom.com!henderso
From: henderso@netcom.com (Mark C. Henderson)
Subject: change sun hostid 1.4.9 -- 1/4
Message-ID: <hendersoDDqt34.8ou@netcom.com>
Organization: Netcom
Date: Wed, 23 Aug 1995 02:47:28 GMT
Lines: 1565
Sender: henderso@netcom8.netcom.com


#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1995-08-22 19:46 PDT by <mch@ratatosk>.
# Source directory was `/usr/local/src'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This is part 1 of a multipart archive.                                   
# Do not concatenate these parts, unpack them in order with `/bin/sh'.     
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   6335 -rw------- hid-1.4.9/00README.FIRST
#    495 -rw------- hid-1.4.9/CREDITS
#  18228 -rw------- hid-1.4.9/INSTRUCTIONS
#   2809 -rw------- hid-1.4.9/changelog
#   7466 -rw------- hid-1.4.9/chenet.c
#   3026 -rw------- hid-1.4.9/dloverlay.c
#   2852 -rw------- hid-1.4.9/getobphostid.c
#   3055 -rw------- hid-1.4.9/hid.c
#   2059 -rw------- hid-1.4.9/hid_solaris2.c
#   2060 -rw------- hid-1.4.9/hid_solaris2x86.c
#   1304 -rw------- hid-1.4.9/hostid-by-egid-modload/README
#   2536 -rw------- hid-1.4.9/hostid-by-egid-modload/kern_hostid.c
#    282 -rw------- hid-1.4.9/hostid-by-egid-modload/makefile
#   1197 -rw------- hid-1.4.9/hostid-by-egid-modload/sethostid.c
#     60 -rwx------ hid-1.4.9/hostid-by-egid-modload/sethostid.exec
#   1924 -rw------- hid-1.4.9/hostid-by-egid-solaris2/README
#    496 -rw------- hid-1.4.9/hostid-by-egid-solaris2/makefile
#   3998 -rw------- hid-1.4.9/hostid-by-egid-solaris2/sethostid.c
#   1121 -rw------- hid-1.4.9/hostid-by-egid-solaris2/sid.c
#   2686 -rw------- hid-1.4.9/hostid-by-egid/README
#   1700 -rw------- hid-1.4.9/hostid-by-egid/kern_hostid.c
#   1085 -rw------- hid-1.4.9/hostid-by-egid/sethostid.c
#   3145 -rwx------ hid-1.4.9/newhostid
#   1289 -rwx------ hid-1.4.9/newhostid.old
#  10095 -rw------- hid-1.4.9/nvram-sol2.c
#  11254 -rw------- hid-1.4.9/nvram.c
#  16630 -rw------- hid-1.4.9/nvram.info
#   7012 -rw------- hid-1.4.9/nvram_old.c
#   1726 -rw------- hid-1.4.9/run/README
#    141 -rw------- hid-1.4.9/run/makefile
#   1336 -rw------- hid-1.4.9/run/run.c
#    767 -rw------- hid-1.4.9/sethostid-simple-4.1/README
#   1992 -rw------- hid-1.4.9/sethostid-simple-4.1/kern_hostid.c
#    282 -rw------- hid-1.4.9/sethostid-simple-4.1/makefile
#   1083 -rw------- hid-1.4.9/sethostid-simple-4.1/sethostid.c
#     60 -rwx------ hid-1.4.9/sethostid-simple-4.1/sethostid.exec
#   1844 -rw------- hid-1.4.9/sethostid-simple-5.3/README
#    496 -rw------- hid-1.4.9/sethostid-simple-5.3/makefile
#   3237 -rw------- hid-1.4.9/sethostid-simple-5.3/sethostid.c
#   1086 -rw------- hid-1.4.9/sethostid-simple-5.3/sid.c
#   6378 -rw------- hid-1.4.9/sidump.c
#   3434 -rw------- hid-1.4.9/sidump_old.c
#   2009 -rwx------ hid-1.4.9/spoof-solaris1/README
#     50 -rwx------ hid-1.4.9/spoof-solaris1/hid_flags.h
#   4596 -rwx------ hid-1.4.9/spoof-solaris1/kern_hostid.c
#    282 -rwx------ hid-1.4.9/spoof-solaris1/makefile
#   1539 -rwx------ hid-1.4.9/spoof-solaris1/sethostid.c
#     60 -rwx------ hid-1.4.9/spoof-solaris1/sethostid.exec
#   3104 -rwx------ hid-1.4.9/spoof-solaris2/README
#     50 -rwx------ hid-1.4.9/spoof-solaris2/hid_flags.h
#    487 -rwx------ hid-1.4.9/spoof-solaris2/makefile
#   7239 -rwx------ hid-1.4.9/spoof-solaris2/sethostid.c
#   1374 -rwx------ hid-1.4.9/spoof-solaris2/sid.c
#    695 -rw------- hid-1.4.9/sysinfo.c
#
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 'Must unpack archives in sequence!'
  echo Please unpack part `cat _sharseq.tmp` next
  exit 1
fi
# ============= hid-1.4.9/00README.FIRST ==============
if test ! -d 'hid-1.4.9'; then
  echo 'x - creating directory hid-1.4.9'
  mkdir 'hid-1.4.9'
fi
if test -f 'hid-1.4.9/00README.FIRST' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/00README.FIRST (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/00README.FIRST (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/00README.FIRST' &&
Version: 1.4.9
Aug 1995
X
Ever been up at 3am on Monday morning trying to move an essential 
application from one piece of hardware to another and been unable to 
do it because you'll need a new licence key from your vendor and they 
don't give them out at weird hours? Well, here's a solution that 
works in many cases. Basically it allows you to modify the value 
returned by gethostid/sysinfo for the hostid on Solaris 1.x and 2.3/4
X
This package can also be used to reprogram a new NVRAM chip if your
NVRAM fails for some reason. In particular the NVRAM on the Sun 3/80 
and all sun4c machines (Sparc 1,1+,2,IPC,ELC,IPX,etc.) will fail after
a relatively short period of time. See nvram.info if you need to do this.
X
See the file INSTRUCTIONS for more details than provided here.
X
Note that there are examples which show how to load system calls via
modload into running kernels on Sun OS 4.1.x and 5.3/5.4. 
X
This kit contains scripts/programs to do this using four different
approaches. These are (pretty much in the order of severity and danger):
1. Use shared libraries to modify the value returned by gethostid/sysinfo
X   for a particular group of dynamically linked executables. Does not
X   work for statically linked executables.
X   newhostid, sidump.c (Solaris 1.x and 2.3), sysinfo.c (Solaris 2.3 & later)
X   newhostid was contributed by Jean-Louis Faraut <jlf@sauma.essi.fr>
X
2. Modify the in-core image of the kernel so that all processes on a running 
X   Solaris system will see a different hostid via gethostid/sysinfo.
X   hid.c, hid_solaris2.c (Solaris 1.1 and 2.3), 
X   sethostid-simple-4.1, sethostid-simple-5.3
X
3. Build a new kernel on which certain processes running on a Solaris 1.x 
X   system will see a different hostid which can be set by a new
X      system call (well, really just the old sethostid system call) 
X   hostid-by-egid (Solaris 1.1 only).
X   Contributed by someone who wishes to remain anonymous
X
X   hostid-by-egid-modload - dynamically loadable version of the
X   above. Basically, it lets you load the new sethostid system call
X   without completely rebuilding your kernel. Based on the above
X   contribution.  
X
X   hostid-by-egid-solaris2 - version of this for Solaris 2.3
X
X   As an aside these might be useful to someone because they show
X   how to dynamically load new system calls into the kernel on 
X   Solaris 1.1 and 2.3.
X
4. Reprogram your NVRAM so that you really have changed your hostid. 
X   SPARC only.
X   nvram.c (Solaris 1.x only), nvram.info (instructions for
X                                           reprogramming from the monitor)
X   nvram-sol2.c (solaris 2.4)
X   The other approaches just fake your OS into reporting a
X   different hostid via the standard system calls.  This approach is
X   much more dangerous, but you may have to resort to it if your
X   licence manager actually goes and fetches the IDPROM value (perhaps
X   through the OPENPROM interface, see getobphostid.c for a way of
X   doing this). In particular 1 and 2 can be undone very easily (reboot). 
X   Approach 3 can be undone by rebooting with one's old kernel.  The NVRAM 
X   modifier if it is abused or malfunctions can actually render your 
X   machine unbootable, even from CDROM. Read the comments in nvram.c and 
X   nvram.info before trying this. I don't generally recommend it.
X
------------------------------------
I'll try and maintain a copy of the latest version of this package
X  on ftp.netcom.com:/pub/he/henderso
X     ftp.wimsey.com:/pub/crypto/netcom-mirror
X
Please don't use these programs to steal software or to violate your
licence agreements with software vendors. 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.
X
USE AT YOUR OWN RISK.
X
nvram.c and nvram-sol2.c are particularly dangerous.  Read the comments
and proceed with extreme caution. If this program malfunctions or is
misused you can get your NVRAM into a state where you will no longer be
able to boot Sun OS.  Unless you absolutely need to modify your NVRAM,
I recommend going with the approach in hid/hid_solaris2.  Reprogramming
your NVRAM can be useful when it gets wiped out for some reason. BE
SURE TO WRITE DOWN YOUR NVRAM INFO BEFORE YOU MODIFY IT.
X
Finally, if you want to communicate with me regarding this package,
and have privacy concerns, you can send me PGP encrypted messages. 
X
I'd also really appreciate receiving any bug reports, encrypted or 
not.
X
Here's my public key:
X
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: 2.7
X
mQCPAivJ3w4AAAEEAMyer3mwrEAfnY65s17lbIzDKEJBJX5m1rceauKEMM5A41+L
kUvNzdGvvaTxYgvlgQS5u7Q4Iv96BvTJUJHKUTxp+ueZjrZX5glY+T1JVQWSvlph
pJ5QWr4o90de/S4GOpYdKo8JFLfGymzUDTqtm1qxT4KJb+G97eI11LPFgBXjABEB
AAG0Jk1hcmsgQy4gSGVuZGVyc29uIDxtYXJraEB3aW1zZXkuYmMuY2E+iQBFAgUQ
LUwfpi4uv5+/eaLVAQHRDwF/esVjxWAUgDs9A2ATwggbH3cSa+XRq5z3lfnUV+Ws
UuF8lVXg3rwt99JmvGpc7oeRiQCVAgUQLUhKSuULSAGiySfVAQFFvwQAobXItWUp
W+b6GxyLm+yPNNx39MAA9/gqQDbCDiCWHkzN6oVF36uDdEIyIPY9GkpDoucfRzD5
1J1ZYNu5IPa8olvcDpRNe8+WjMhGDw/qgkMFhQUepzsPaUF/7zXnZcLMFIhxY+/9
Jh1chCl+1ABJps/NhlKm6qFk+wgjShuzeFaJAJQCBRAtEatyrXg6KCkPNT0BAVPT
A/dLK1yBmDhYaUcH7ZDWfo29+M9sN+tq1Woq0Ys9tLzoi72LCGrLGTOnQnx2Dvq6
6PMCQ/neu6efY+YWLVOIbiOqjXrF6VAdPi9T+EFJwLDx5S5THgPWtbwzOft7yAPs
HBGZ3Qbc79mg/kj00nx9fHuwNdxMWb51NwkgTC9QqJr1iQCVAgUQK8nffeI11LPF
gBXjAQHOpgP9F67ES+2iWyEEj3JU/k8lT2GAYmxrp2GiZ5yGgFFsMPDob5ZVLK+f
695hcgA6E4218FS/p+BiJlYcjyWazOl1U7g0HB0DvYcKi5s0PF+M8b+0tuD83Hb9
1ygePMmlgHe1+B5w4E1LJtnqcqlhAcLqdz/ZJ31qAVnFUppEALTx2gA=
=VLrB
-----END PGP PUBLIC KEY BLOCK-----
X
Mark Henderson <markh@wimsey.bc.ca>
X
-- NEW FEATURES --
nvram-sol2.c   new to 1.3.5
spoof-solaris  (2.4) new to 1.4.0
spoof-solaris2 (1.1) new to 1.4.0
sysinfo.c - new to 1.4.1 (thanks to an anonymous contributor)
dloverlay.c - new to 1.4.3 
X     contributed by bf078@cleveland.Freenet.Edu (Brian S Walden)
XX86 support - thanks to Bogdan Urma <bogdan@xandau.com> for the use
X     of an X86 machine running Solaris 2.4
SS1000 nvram.info - thanks to Kevin Murty for use of an SS1000
nvram.info updates for 1.4.7, 1.4.8, 1.4.9
X
spoof-solaris and spoof-solaris2 allow you to spoof hostname, hostid,
and IP address in much the same way as hostid.
SHAR_EOF
  $shar_touch -am 0819144595 'hid-1.4.9/00README.FIRST' &&
  chmod 0600 'hid-1.4.9/00README.FIRST' ||
  echo 'restore of hid-1.4.9/00README.FIRST failed'
  shar_count="`wc -c < 'hid-1.4.9/00README.FIRST'`"
  test 6335 -eq "$shar_count" ||
    echo "hid-1.4.9/00README.FIRST: original size 6335, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/CREDITS ==============
if test -f 'hid-1.4.9/CREDITS' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/CREDITS (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/CREDITS (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/CREDITS' &&
Thanks to the following for help/code/resources/information.
If I've forgotten anyone, I apologize. Please drop me a note and I'll 
X   correct the list in the next release.
X
Jean-Louis Faraut
Kevin Murty
an anonymous contributor
bf078@cleveland.Freenet.Edu (Brian S Walden)
bogdan@xandau.com (Bogdan Urma)
coughlin@cfa0.harvard.edu (Michael Coughlin)
drzob@vectrex.login.qc.ca (Denis Solaro)
weindlin@pcs.mot.com
yokoyama@tkl.iis.u-tokyo.ac.jp
"Roderick Murchison, Jr." <murchiso@Newbridge.COM>
SHAR_EOF
  $shar_touch -am 0710151195 'hid-1.4.9/CREDITS' &&
  chmod 0600 'hid-1.4.9/CREDITS' ||
  echo 'restore of hid-1.4.9/CREDITS failed'
  shar_count="`wc -c < 'hid-1.4.9/CREDITS'`"
  test 495 -eq "$shar_count" ||
    echo "hid-1.4.9/CREDITS: original size 495, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/INSTRUCTIONS ==============
if test -f 'hid-1.4.9/INSTRUCTIONS' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/INSTRUCTIONS (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/INSTRUCTIONS (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/INSTRUCTIONS' &&
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.
X
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.
X
Please send bug reports to Mark Henderson <markh@wimsey.bc.ca>
X
----------------------------------------------------------------------
I've included several programs which do different things. All other than
the nvram modifiers nvram.c (nvram_old.c) essentially spoof the 
operating system into believing the system has different hostid
than it really does.
X
Basically I'll break them down as follows:
1. hid.c, hid_solaris2.c, sethostid-simple-4.1, sethostid-simple-5.3
X   These modify the kernel so that a different hostid is returned by
X     gethostid and sysinfo.
X   The first two (hid.c, hid_solaris2.c) just patch a few bytes into
X     the kernel to achieve the desired effect.
X   sethostid-simple-4.1 and sethostid-simple-5.3 add a sethostid system
X     call to the kernel which takes one parameter (the desired hostid).
X
X   Limitations: 
X        1. All processes on the system will report the same hostid.
X        2. Clever programs can figure out that the kernel is reporting
X           a "fake" hostid. There are a couple of ways of validating
X           this. Two I know are: 
X                Solaris 2.3 only - look at _idprom in the kernel
X                Solaris 1.1 and 2.3 - use the openprom interface to 
X                    get the idprom property. (see getobphostid.c)
X
2. hostid-by-egid-solaris2, hostid-by-egid-modload, hostid-by-egid, run
X    These modify the kernel so that a different hostid is returned by
X      gethostid and sysinfo if the process is a member of certain groups
X      or has egid in this set of groups.
X    This allows you to have multiple hostids on a single machine. For instance
X      process A which is in group 900, might see hostid 0x23000000 and process
X      B in group 901 might see hostid 0x80000000
X    run.c is a simple program which executes a command with a group added
X      to its membership list.
X
X    Limitations: as with the above clever programs can try and defeat you.
X
3. newhostid, sidump.c, sysinfo.c, sidump_old.c, newhostid.old
X    These spoof hostid using the LD_PRELOAD environment variable. Allows
X    a system to appear to have multiple hostids. You don't even need to 
X    have root access to do this.
X
X    Limitations: 
X        1. as with the above clever programs can try and defeat you.
X        2. only works for dynamically linked executables.
X
4. nvram.c, nvram_old.c, nvram.info, nvram-sol2.c
X    Instructions and software to modify the hostid in NVRAM for 
X    sun4m, sun4c. Really allows you to modify your hostid. Also 
X    some experimental support for sun4d.
X
X    Limitations:
X         - You need to be very careful with this. In particular, you
X           can't just change your hostid to an arbitary value. Read 
X           the instructions carefully.
X
One comment about clever programs. You can often defeat the extended
hostid checking they might do. In particular you can spoof the openprom
ioctl interface with these techniques by writing a wrapper around the
system ioctl.
X
Applicability:
X
X
X                            4.1.x  4.1.x 5.3/5.4    Notes
X                            sun3   sun4  sun4 x86  
getobphostid.c               X       X     X
hid.c                                X       
hid_solaris2.c                             X
hid_solaris2x86.c                              X  
hostid-by-egid               X       X 
hostid-by-egid-modload       X       X
hostid-by-egid-solaris2                    X   X 
newhostid                    X       X     X   X
nvram.c,chenet.c             X       X            sun3x, sun4c, sun4m only
nvram-sol2.c                               X      solaris 2.4, sun4c, sun4m
nvram.info                   X       X     X      sun 3/80, sun4c/m/d
run                          X       X     X   X  for use with egid stuff
sethostid-simple-4.1         X       X
sethostid-simple-5.3                       X   X
sidump.c                     X       X
sysinfo.c                                  X   X
dloverlay.c                  X       X            hostid/date and more
spoof-solaris2                             X   X
spoof-solaris1               ?       X            ? = should be ok, untested
X
X
---
Now for some detailed instructions.
X
----------------------------------------------------------------------
X
hid.c (Solaris 1.x only)
- change hostid reported by Solaris 1.x/SUN OS 4.1.x gethostid
X
1. compile hid.c
X    e.g. cc -o hid hid.c
2. run hid with your desired hostid and it will output
X   a script to stdout that will change the value reported by
X   gethostid
X    e.g. for hostid b0b1fb0b  (hex)
X         ./hid b0b1fb0b >script.sh
X         sh script.sh
X
X    Unless your system security is terrible, you will have to run
X    script.sh as root.
X
X    or simply (as root)
X        ./hid b0b1fb0b | sh
X
3. Rebooting will undo this change, if you want to make it permanent,
X   you have two options
X   a. just place the script output by hid in your /etc/rc.local
X      file
X
X   the script will look something like:
X
X    #!/bin/sh
X    # this script sets the hostid to b0b1bb0b
X    adb -w -k /vmunix /dev/mem <<END
X    _gethostid+4/W 112c2c6e
X    _gethostid+8/W 9012230b
X    END
X
X    b. Modify hid so that the "/W" in the output is "?W" or just
X       modify the file I call script.sh above. This writes 
X       the changes to your /vmunix file instead of just to the in-core
X       kernel image.
X
X    Make a backup copy of your /vmunix before you try this.
X    
X    e.g.
X
X    #!/bin/sh
X    # modified output from "hid b0b1fb0b"
X    # this script modifies /vmunix so that gethostid always reports b0b1fb0b
X    adb -w -k /vmunix /dev/mem <<END
X    _gethostid+4?W 112c2c6e
X    _gethostid+8?W 9012230b
X    END
X   
X    Note that you always input the hostid in hexadecimal, without a leading
X    0x. hid doesn't do a sanity check on its parameter, so you need to
X    be careful about the exact form of this parameter.
X
X    There are some more technical details in the comment at the beginning
X    of hid.c
X
----------------------------------------------------------------------
X
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
X
1. Compile hid_solaris2.c to make the binary hid
X    gcc -o hid hid_solaris2.c
X    (or use another compiler)
X
2. run hid with your desired hostid and it will output
X   a script to stdout that will change the value reported by
X   gethostid
X    e.g. for hostid b0b1fb0b  (hex)
X         ./hid b0b1fb0b >script.sh
X         sh script.sh
X
X    Unless your system security is terrible, you will have to run
X    script.sh as root.
X
X    or simply (as root)
X        ./hid b0b1fb0b | sh
X
3. Rebooting will undo the change. If you want to make it "permanent",
X   i.e. have this new hostid every time your reboot, put the output
X   from hid in one of the system startup files.
X
----------------------------------------------------------------------
X
sidump.c (Solaris 2.3/1.x)
X
modify hostid reported by gethostid and sysinfo for Solaris 2.3 
X   dynamically linked non-setuid/setgid binaries. You do not need
X   to be root for this.
X
new for 0.8.8 - you can override the desired hostid on a per process
X  basis by setting the environment variable HID to the desired hostid
X  in hex - as usual - with no leading 0x
X  e.g. export HID=fedc1234   (ksh)
X       setenv HID "fedc1234" (csh)
X
Instructions:
X
Solaris 1.x
1. compile this program
X    cc -o sidump sidump.c  (or use gcc)
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
--
To undo this just unset LD_PRELOAD. This only effects processes
for which LD_PRELOAD points to the object you create.
X
X
----------------------------------------------------------------------
X
sysinfo.c (Solaris 2.3 & later)
X
modify hostid reported by gethostid and sysinfo for Solaris 2.3 
X   dynamically linked non-setuid/setgid binaries. You do not need
X   to be root for this.
X
the major advantage of sysinfo.c over sidump is that a single copy of the
shared library can be used on any machine of the same CPU type (SPARC or
Intel).  this is done without invoking the compiler and linker each time, as
newhostid does, while providing complete sysinfo() emulation, like sidump.
X
Instructions:
X
Solaris 2.x
X
1. make sysinfo.o from sysinfo.c
X      gcc -O2 -fpic -c sysinfo.c
X      cc -O -pic -c sysinfo.c
X      ld sysinfo.o -G -o sysinfo.so
2. export LD_PRELOAD=$PWD/sysinfo.so      (ksh)
X   setenv LD_PRELOAD $PWD/sysinfo.so      (csh)
2. export SI_HW_SERIAL=1234567890      (ksh)
X   setenv SI_HW_SERIAL 1234567890      (csh)
4. run the desired program
X
here's a sample session:
X
ratatosk> gcc -fpic -c sysinfo.c
ratatosk> ld sysinfo.o -G -o sysinfo.so -ldl -lc
ratatosk> export LD_PRELOAD=$PWD/sysinfo.so
ratatosk> export SI_HW_SERIAL=3237998146
ratatosk> hostid
c0ffee42
ratatosk> lmhostid
lmhostid - Copyright (C) 1989, 1991 Highland Software, Inc.
The FLEXlm host ID of this machine is "c0ffee42"
X
--
To undo this just unset LD_PRELOAD or SI_HW_SERIAL. This only affects processes
for which LD_PRELOAD points to the object you create and for which SI_HW_SERIAL
is set.
X
X
---------------------------------------------------------------------
newhostid - Solaris 2.3 and Solaris 1.1
Again only for dynamically linked non setuid/setgid binaries.
X  Run a single command "with a different hostid"
X
Simply type
newhostid Base10Hostid command [args]
X
e.g.
for hostid 72000000 (Hex) type
newhostid 1912602624 command arg1 arg2 arg3 ...
X
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)
X
---------------------------------------------------------------------
nvram.c
get/change hostid in NVRAM -- Solaris 1.1 and Sun4c or Sun4m only
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.
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.
X
1. Read the complete instructions before you proceed. You should
X   probably also read nvram.c
X
2. compile nvram
X   cc -o nvram nvram.c
X
2a. If you aren't already root, become root
X
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.  
X
It should suggest a few adb commands to execute to make a kernel 
modification.
X
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.
X
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
X
6. reboot (and cross your fingers).
X
---------------------------------------------------------------------
X
nvram-sol2.c
get/change hostid in NVRAM -- Solaris 2.4 only
X
(68/11)
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.
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.
X
1. Read the complete instructions before you proceed. You should
X   probably also read nvram-sol2.c
X
2. compile nvram
X   /opt/SUNWspro/bin/cc -o nvram-sol2 nvram-sol2.c -lelf
X
2a. If you aren't already root, become root
X
2b. If you are running a sun4c machine skip to step 3.
If you are running a sun4m machine, go to a sun4c machine
running Solaris 2.4 and grab the file /kernel/drv/eeprom (and put
it in /kernel/drv/eeprom on the new machine). Alternatively you
can get the eeprom module by mounting your Solaris 2.4 distribution
media and grabbing the file 
/cdrom_root_dir/export/exec/kvm/sparc.sun4c.Solaris_2.4/kernel/drv/eeprom
X
now go back to your sun4m machine and execute the following
mknod /dev/eeprom c 68 11
/usr/sbin/modload /kernel/drv/eeprom 
X
(obviously I can't distribute the Sun eeprom module, but it is included by
default on sun4c machine and not on sun4m machines. The driver included
with the sun4c installation of Solaris 2.4 is smart enough to deal with the 
differences between the two machines)
X
3. Run nvram-sol2 without any parameters.
If it fails with some bizarre error message, then your architecture or
OS 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.
X
It should suggest a few adb commands to execute to make a kernel 
modification. 
X
It may also suggest that you need to load the eeprom module, in which case 
you should do so and repeat this step.
X
4. Run nvram-sol2 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.
X
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-sol2 b0b1fb0b
X
6. reboot (and cross your fingers).
X
---------------------------------------------------------------------
hostid-by-egid
X
see hostid-by-egid/README. I've only tested this on a Sparc LX running
Solaris 1.1C
---------------------------------------------------------------------
hostid-by-egid-modload
X
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.
X
see hostid-by-egid-modload/README. I've only tested this on a Sparc 
LX running Solaris 1.1C
X
---------------------------------------------------------------------
hostid-by-egid-solaris2
X
Version of hostid-by-egid-modload for Solaris 2.3/2.4
see hostid-by-egid-solaris2/README.
X
---------------------------------------------------------------------
spoof-solaris, spoof-solaris2
X
spoof-solaris and spoof-solaris2 are modified versions of 
hostid-by-egid-modload and hostid-by-egid-solaris2 which also allow you to 
spoof the hostname. There are also instructions for spoofing the IP address 
(using ifconfig with Solaris 2, or a package called vip with Solaris 1.1)
X
see the README files
X
---------------------------------------------------------------------
sethostid-simple-4.1, sethostid-simple-5.3
see README files.
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/4.
X
---------------------------------------------------------------------
X
nvram.info - this gives some information on modifying the NVRAM
from the Openprom monitor.
X
---------------------------------------------------------------------
run/run.c is useful with the hostid-by-egid* modules.
see run/README for details
---------------------------------------------------------------------
dloverlay.c 
X  see the comments. Another hack to use LD_PRELOAD to override
X  various system calls (includes hostid, date, hostname etc.)
X  contributed by Brian S. Walden
X
SHAR_EOF
  $shar_touch -am 0627212495 'hid-1.4.9/INSTRUCTIONS' &&
  chmod 0600 'hid-1.4.9/INSTRUCTIONS' ||
  echo 'restore of hid-1.4.9/INSTRUCTIONS failed'
  shar_count="`wc -c < 'hid-1.4.9/INSTRUCTIONS'`"
  test 18228 -eq "$shar_count" ||
    echo "hid-1.4.9/INSTRUCTIONS: original size 18228, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/changelog ==============
if test -f 'hid-1.4.9/changelog' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/changelog (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/changelog (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/changelog' &&
0.8.6
-Added file called INSTRUCTIONS which contains documentation. You can
X now probably use the stuff now without looking at the comments in the C
X code.
X
0.8.7
-minor change to nvram.info
-minor fix to hostid-by-egid/sethostid. Passing bad parameters
X could have caused problems.
-changed name of distribution.
-unless some serious problems come up, 0.8.7 will be the last public release
X before version 1.0
X
1.0
-changed sidump.c so that the hostid can also be set be an environment
X variable (for dynamically linked executables, SUN OS 4.1, 5.3)
-cosmetic changes to documentation
X
1.1
- hostid-by-egid now available as a loadable module. Sun OS 4.1 only.
X  can load and unload via modload
X
1.2
- obvious bug fix to chenet.c
- hostid-by-egid now available as a loadable module for both Solaris
X  2.3 and 1.1.  Can load and unload via modload.
X
1.2b
- 1.2 and 1.2a had a nasty bug in the sethostid module for Solaris 2.3.
X  If the module failed to load, the sysent table was often left in a bad
X  state which would lead to a kernel panic pretty soon.
- added Makefile lines to install sid in /usr/local/bin and sethostid
X  in /kernel/sys (if one does "make install"). I'm actually beginning
X  to appreciate Solaris 2.x; automatically loading system calls into the
X  kernel on the fly when they are called is pretty cool.
X
1.2c
- bug in some of the user sethostid programs (not the kernel modules)
X  would not allow hostid > 0x7fffffff because of signed vs unsigned
X  problems. On solaris 2.3 changes strtol to strtoul. On Solaris 1.1
X  changed strtol to appropriate sscanf calls. The sscanf calls are not
X  tolerant of a leading 0x as are strtol and strtoul, but this doesn't
X  really both me.
X
1.3
- minor changes to documentation
X
1.3.1
- added information about sun 3/80 to nvram.info
X
1.3.2
- fixed solaris 2 instructions. important to reboot after modifying
X  /etc/name_to_sysnum
- added a couple of systems to nvram.info
- explicit path to ld added in solaris 2 makefiles (/usr/ccs/bin/ld)
X
1.3.3
- added nvram-sol2.c
- minor change to nvram.c that should be harmless.
X
1.3.4 
- cosmetic changes to nvram-sol2.c and nvram.c
X
1.3.5
- mods to nvram-sol2.c for sun4m
X
1.4.0
- correction to nvram.info
- spoof-solaris and spoof-solaris2 released.
X
1.4.2
- by default sun4m installations don't include the eeprom driver. But you
X  can get the eeprom driver from a sun4c machine and it is smart enough
X  to work nicely. Forgot to mention this in 1.4.1.
X
1.4.5
- added SS1000 Flash EEPROM repogramming information.
- added Solaris 2.4 x86 support
X
1.4.6
- fixed stupid bug introduced at last minite into nvram-sol2.c in 1.4.5
X
1.4.8 
- updated nvram.info. Quick and dirty instructions for NVRAM replacement.
X
1.4.9 
- added the examples to nvram.info which will hopefully make things
X  a little more clear
SHAR_EOF
  $shar_touch -am 0819144695 'hid-1.4.9/changelog' &&
  chmod 0600 'hid-1.4.9/changelog' ||
  echo 'restore of hid-1.4.9/changelog failed'
  shar_count="`wc -c < 'hid-1.4.9/changelog'`"
  test 2809 -eq "$shar_count" ||
    echo "hid-1.4.9/changelog: original size 2809, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/chenet.c ==============
if test -f 'hid-1.4.9/chenet.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/chenet.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/chenet.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/chenet.c' &&
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <nlist.h>
X
X
/* 
get/change enet addr in NVRAM --
see the comments and instructions in nvram.c
USE AT YOUR OWN RISK
X
1. run chenet without any parameters, follow the instruction 
2. run chenet without any parameters again. It should spit out
X   your enet addr. Do not proceed if it doesn't spit out anything
X   sensible.
3. now run chenet to actually modify the NVRAM
X   e.g. chenet 08 00 20 fd fe fd
X
Placed in the public domain by the author - 1 July 1994
X
only tested on some sun4m architecture and sun4c architecture machines.
The kernel patches will be different for Sun4 and I don't have one to
play with.
X
If your particular machine is not supported, you may be able
to hack support for the machine into this program.
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.  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.
X
*/
X
X
#define OFFSET1 017730       /* for Sun 4m, Sun OS 4.1.3 */
#define OFFSET2 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
/* #define TEST        /* doesn't actually do mods if TEST is defined */
unsigned char buf[17];  /* larger than it needs to be */ 
X
/* offset table -- in ascending order of magnitude */
off_t offtab[2] = { OFFSET2, OFFSET1 };
#define nofftab  (sizeof(offtab) / sizeof(off_t))
off_t offset;
X
struct nlist nl[] = { "_mmeeprom" };
void check_eeprom_driver()
{
X    int kmem;
X    off_t where;
X    unsigned int kbuf[12];
X    if ((kmem = open("/dev/kmem", O_RDONLY)) < 0) {
X        fprintf(stderr, "cannot open /dev/kmem\n");
X        exit(1);
X    }
X    if (nlist("/vmunix", nl) < 0) {
X        fprintf(stderr, "cannot read namelist out of /vmunix\n");
X        exit(1);
X    }
X    if ((where = nl[0].n_value) == 0) {
X        fprintf(stderr, "unknown kernel variable _mmeeprom\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    if (lseek(kmem, where, SEEK_SET) == (-1)) {
X        fprintf(stderr, "lseek on /dev/kmem failed\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    if (read(kmem, (char *)&kbuf[0], 48) < 48) {
X        fprintf(stderr, "read from /dev/kmem failed\n");
X        fprintf(stderr, 
X            "your kernel is strange - nvram modifier won't operate\n");
X        exit(1);
X    }
X    close(kmem);
X    if (kbuf[1] == 0x80a6a7d8 && kbuf[10] == 0x80a6a7d8) {
X        fprintf(stderr, "please execute the following:\n");
X        fprintf(stderr, 
X            "adb -w -k /vmunix /dev/mem <<END\n_mmeeprom+4/W 80a6a7ff\n");
X        fprintf(stderr, "_mmeeprom+0x28/W 80a6a7ff\nEND\n");
X        exit(0);
X    }
X    if (kbuf[2] == 0x901223d8) {
X        fprintf(stderr, "please execute the following:\n");
X        fprintf(stderr, 
X            "adb -k -w /vmunix /dev/mem <<END\n_mmeeprom+8/W 901223ff\nEND\n");
X        exit(0);
X    }
X    if (kbuf[1] == 0x80a6a7ff && kbuf[10] == 0x80a6a7ff) {
X        fprintf(stderr, "your kernel looks good (sun4c)\n");
X    }
X    if (kbuf[2] == 0x901223ff) {
X        fprintf(stderr, "your kernel looks good (sun4m)\n");
X    }
}
X    
X
main(argc,argv)
int argc;
char *argv[];
{
X    int fd;
X    int i;
X    int j;
X    unsigned int new[6];
X    unsigned int acc;
X    int read_enet;
X    unsigned int hid_reported_by_gethostid = gethostid();
X
X    if (argc == 1) {
X        /* no args - just get enetaddr from prom */
X        read_enet = 1;
X    }
X    else if (argc == 7) {
X        read_enet = 0;
X        for (i=0;i<6;i++) {
X            sscanf(argv[i+1],"%x",&new[i]);
X            if (new[i] > 0xff) {
X                fprintf(stderr, "usage: %s [xx xx xx xx xx xx]\n",argv[0]);
X                fprintf(stderr, "  e.g. %s [8 0 20 7 19 4d]\n", argv[0]);
X                exit(1);
X            }
X        }
X    }
X    else {
X        fprintf(stderr, "usage: %s [xx xx xx xx xx xx]\n",argv[0]);
X        fprintf(stderr, "  e.g. %s [8 0 20 7 19 4d]\n", argv[0]);
X        exit(1);
X    }
X    check_eeprom_driver(); /* note: if you know what you are doing you might 
X                                want to comment this line out. */
X    if (read_enet) {
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 write\n");
X            exit(1);
X        }
#endif
X    }
X
X    offset = 0xffffffff;     /* dummy value */
X
X    for (j = 0; j < nofftab; j++) {
X        if (lseek(fd,offtab[j],SEEK_SET) < 0) { 
X            fprintf(stderr, "lseek failed for %o\n", offtab[j]);
X            continue;
X        }
X        if (read(fd,buf,16) < 16) {
X            fprintf(stderr, "read of /dev/eeprom failed for %o\n", offtab[j]);
X            continue;
X        }
#ifdef TEST
X        for (i=0; i<16; i++)
X            printf("%02x ", buf[i]);
X        printf("\n");
#endif
/* 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 disable this check, but restore your old 
X   gethostid behaviour or replace the gethostid call in this code 
X   with 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. (remember the AT YOUR OWN RISK 
X   comment). 
X  */
X
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            continue;
X        }
X        offset = offtab[j];
X        break;
X    }
X    if (offset == 0xffffffff) {
X        fprintf(stderr, "perhaps you have a weird kernel -- failed\n");
X        exit(1);
X    }
X    printf("current hostid = %02x%02x%02x%02x\n", 
X    buf[1], buf[12], buf[13], buf[14]);
X
X    printf("enetaddr       = %02x:%02x:%02x:%02x:%02x:%02x\n", 
X    buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]);
X    if (!read_enet) {
X        if (lseek(fd,offset,SEEK_SET) < 0) { 
X            fprintf(stderr, "lseek failed\n");
X            exit(1);
X        }
X        for (i=0; i<6; i++) 
X            buf[i+2] = (unsigned char) new[i];
X
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");
#endif
X    fprintf(stderr, "now please execute the following command\n");
X    fprintf(stderr, "/usr/etc/eeprom 'diag-switch?=false'\n");
X    }
X    close(fd);
}
X
SHAR_EOF
  $shar_touch -am 0811155794 'hid-1.4.9/chenet.c' &&
  chmod 0600 'hid-1.4.9/chenet.c' ||
  echo 'restore of hid-1.4.9/chenet.c failed'
  shar_count="`wc -c < 'hid-1.4.9/chenet.c'`"
  test 7466 -eq "$shar_count" ||
    echo "hid-1.4.9/chenet.c: original size 7466, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/dloverlay.c ==============
if test -f 'hid-1.4.9/dloverlay.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/dloverlay.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/dloverlay.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/dloverlay.c' &&
/*
X * dloverlay.c - dynamic library system call pre-emption
X * brian.s.walden	mcmxciii
X *
X * for Solaris 1.x
X * 
X * cc -O -PIC -c dloverlay.c;ld dloverlay.o -assert pure-text -o dloverlay.so
X * LD_PRELOAD=dloverlay.so
X *
X * currently only overlays gettimeofday(2), hostid(2),
X *  gethostname(2), getdomainname(2), uname(2), and open(2)
X *
X * set any of these envrinment variables:
X *	TIMEOFDAY	set clock offest in seconds: +/- or absolute
X *	HOSTID		hex hostid (0x prefix is OK, non-hex will make it 0)
X *	HOSTNAME	hostname
X *	DOMAINNAME	domainname
X *	SYSNAME		system os type (eg. SunOS)
X *	RELEASE		system os release (eg. 4.1.3)
X *	VERSION		system os version (eg. 5)
X *	MACHINE		machine type (eg. sun4c)
X *	OPEN_DEBUG	setting it in env prints opens on stderr
X *
X * Note: the env vars must be unset and not just nulled out to get back
X * the real syscall operations.
X *
X */
X
#include <string.h>
#include <sys/syscall.h>
X
extern char *getenv();
X
#include <sys/time.h>
X
gettimeofday(tp, tzp)
struct timeval *tp;
struct timezone *tzp;
{
X	int rc;
X	if((rc = syscall(SYS_gettimeofday, tp, tzp)) == 0) {
X		char *tmmod = getenv("TIMEOFDAY");
X		if(tmmod) {
X			long delta = atol(tmmod);
X			switch (*tmmod) {
X			case '-':
X			case '+':
X				tp->tv_sec += delta;
X				break;
X			default:
X				tp->tv_sec = delta;
X				break;
X			}
X		}
X	}
X	return rc;
}
X
gethostid()
{
X	char *strhostid = getenv("HOSTID");
X	long hostid = strhostid ?
X		 strtol(strhostid, (char **)0, 16) : syscall(SYS_gethostid);
X	return hostid;
}
X
gethostname(name, len)
char *name;
{
X	char *hostname = getenv("HOSTNAME");
X	if(hostname && name) {
X		strncpy(name, hostname, len);
X		return 0;
X	}
X	return syscall(SYS_gethostname, name, len);
}
X
getdomainname(name, len)
char *name;
{
X	char *domainname = getenv("DOMAINNAME");
X	if(domainname && name) {
X		strncpy(name, domainname, len);
X		return 0;
X	}
X	return syscall(SYS_getdomainname, name, len);
}
X
#include <sys/utsname.h>
X
uname(name)
struct utsname *name;
{
X	int rc;
X	char *env;
X
X	if( (rc = syscall(SYS_uname, name)) == 0) {
X		/* you have to "know" the utsname structure sizes */
X		if(env=getenv("SYSNAME")) strncpy(name->sysname, env, 8);
X		if(env=getenv("HOSTNAME")) strncpy(name->nodename, env, 64);
X		if(env=getenv("RELEASE")) strncpy(name->release, env, 8);
X		if(env=getenv("VERSION")) strncpy(name->version, env, 8);
X		if(env=getenv("MACHINE")) strncpy(name->machine, env, 8);
X	}
X	return rc;
}
X
#include <stdio.h> /* for stderr */
extern errno;
X
/* WARNING1: this open does not implement the system v
X * style error if given a null path name, see open(2)
X * WARNING2: this does I/O, caveat if you overlay write(2).
X * NB: this should be expanded to decode the flags and errno
X */
open(path, flags, mode)
char *path;
{	
X	char *odebug = getenv("OPEN_DEBUG");
X	int fd;
X
X	if(odebug) fprintf(stderr, "[pid=%d/uid=%d] open(\"%s\", %o, %o) = ",
X			getpid(), getuid(), path, flags, mode);
X	fd = syscall(SYS_open, path, flags, mode);
X	if(odebug) fprintf(stderr, fd==(-1)?"[errno %d]\n":"%d\n",
X			fd==(-1)?errno:fd);
X	return fd;
}
SHAR_EOF
  $shar_touch -am 0323215395 'hid-1.4.9/dloverlay.c' &&
  chmod 0600 'hid-1.4.9/dloverlay.c' ||
  echo 'restore of hid-1.4.9/dloverlay.c failed'
  shar_count="`wc -c < 'hid-1.4.9/dloverlay.c'`"
  test 3026 -eq "$shar_count" ||
    echo "hid-1.4.9/dloverlay.c: original size 3026, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/getobphostid.c ==============
if test -f 'hid-1.4.9/getobphostid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/getobphostid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/getobphostid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/getobphostid.c' &&
/* get idprom info via openprom interface - markh@wimsey.bc.ca 
X *   placed in the public domain by the author - 1 July 1994
X * N.B. the idprom info is actually in NVRAM, so the name is misleading
X *
X * define SOLARIS2 if you are compiling for SOLARIS2 
X * define TEST to include the very simple test driver
X * define DEBUG to produce copious output - including the complete idprom
X *    contents according to openprom 
X *
X * Of course, you need read permission to /dev/openprom to do this. It
X * appears that the default configuration on Solaris 1.x gives everyone
X * read permission, but on Solaris 2.3 you need to be root or in group 
X * sys.
X */
X
#include <fcntl.h>
#include <sys/types.h>
X
#if defined(TEST) || defined(DEBUG)
#include <stdio.h>
#endif
X
#ifdef SOLARIS2
#include <sys/openpromio.h>
#define bzero(a,b) memset((a),0,(b))
#else
#include <sundev/openpromio.h>
#endif
X
X
/* 
X * getobphostid - gets hostid according to the openprom driver
X * returns 0 on failure 
X */
unsigned int getobphostid()
{
X    struct opio {
X       unsigned int size;
X       unsigned char arr[OPROMMAXPARAM];
X    } foo;
X    int fd,done = 0;
#ifdef DEBUG
X    int i;
#endif
X    if ((fd = open("/dev/openprom", O_RDONLY)) < 0) {
#ifdef DEBUG
X        perror("cannot open /dev/openprom");
#endif
X        return (0);
X    }
X    foo.size =  OPROMMAXPARAM;
X    bzero(&foo.arr[0],OPROMMAXPARAM);
X    if (ioctl(fd, OPROMNEXT, &foo) < 0) {
#ifdef DEBUG
X        perror("ioctl failed (OPROMNEXT)");
#endif
X        return(0);
X    }
X    foo.size =  OPROMMAXPARAM;
X    bzero(&foo.arr[0],OPROMMAXPARAM);
X    for (;!done;) {
X        foo.size =  OPROMMAXPARAM;
X        if (ioctl(fd, OPROMNXTPROP, &foo) < 0) {
#ifdef DEBUG
X            perror("ioctl failed (OPROMNXTPROP)");
#endif
X            return(0);
X        }
X        if (foo.size == 0)   /* not on list ! */
X            return 0;
X        if (strncmp(&foo.arr[0], "idprom", 6)) 
X            continue;
#ifdef DEBUG
X        printf("%s: ", &foo.arr[0]);
#endif
X        strcpy(&foo.arr[0],&foo.arr[0]);
X        foo.size=OPROMMAXPARAM;
X        if (ioctl(fd, OPROMGETPROP, &foo) < 0) {
#ifdef DEBUG
X            perror("ioctl failed (OPROMGETPROP)");
#endif
X            return(0);
X        }
#ifdef DEBUG
X        for (i=0;i<foo.size;i++) {
X            if (!(i%8))
X                printf("\n");
X            printf("%02x ",foo.arr[i] & 0xff);
X        }
X        printf("\n");
X        printf("hostid = %02x%02x%02x%02x\n", foo.arr[1], foo.arr[12],
X            foo.arr[13], foo.arr[14]);
X        printf("enet   = %02x:%02x:%02x:%02x:%02x:%02x\n", foo.arr[2],
X            foo.arr[3],foo.arr[4],foo.arr[5],foo.arr[6],foo.arr[7]);
#endif
X        done=1;
X    }   
X    close(fd);
X    return ((foo.arr[1] << 24)|(foo.arr[12] << 16)|(foo.arr[13] << 8)
X            |(foo.arr[14]));
}
#ifdef TEST
X
main()
{
X    printf("%08x\n", getobphostid());
}
#endif
SHAR_EOF
  $shar_touch -am 0123181595 'hid-1.4.9/getobphostid.c' &&
  chmod 0600 'hid-1.4.9/getobphostid.c' ||
  echo 'restore of hid-1.4.9/getobphostid.c failed'
  shar_count="`wc -c < 'hid-1.4.9/getobphostid.c'`"
  test 2852 -eq "$shar_count" ||
    echo "hid-1.4.9/getobphostid.c: original size 2852, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/hid.c ==============
if test -f 'hid-1.4.9/hid.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/hid.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/hid.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/hid.c' &&
/* 
X
change hostid reported by Solaris 1.x/SUN OS 4.1.x gethostid
run the script produced by this file 
X 
e.g. you could put the following script (produced by hid b0b1fb0b)
X   in /etc/rc.local
X
#!/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
X
to change the hostid to b0b1fb0b
X
Mark Henderson <markh@wimsey.bc.ca>
Placed in the public domain by the author - 3 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
By way of explanation:
X
hid produces a script which, when executed on a Solaris 1.x machine
will change the value reported by gethostid to the desired value.  adb
is used to alter the in-core kernel image.  No changes are made to the
kernel file itself (/vmunix), so rebooting will undo any
modifications.  If you want to permanently change the value returned by
gethostid/sysinfo, one way to do this is to put the script output
by hid in /etc/rc.local
X
This overwrites two key instructions in the gethostid routine in the
memory image of the kernel (the kernel itself on disk is NOT modified)
X
the original instructions that are overwritten are
_gethostid+4:   call    _machineid
_gethostid+8:   nop
X
If you want the hostid
b0b1fb0b
hid outputs the script
X
adb -w -k /vmunix /dev/mem <<END
_gethostid+4/W 112c2c7e
_gethostid+8/W 9012230b
END
X
going to assembler
the new instructions are:
_gethostid+4:   sethi   %hi(0xb0b1f800), %o0
_gethostid+8:   or      %o0, 0x30b, %o0
X
basically 0x30b is the 10 rightmost bits of the desired
0xb0b1f800 is the 22 rightmost bits of the desired hostid
X
These two instructions set register o0 to the desired value, 
so it is as if machineid returned the desired hostid.
X
*/
X
X
#include <stdio.h>
main(argc,argv)
int argc;
char *argv[];
{
X    unsigned int hid;
X    unsigned int hi;
X    unsigned int low;
X
X    if (argc != 2) {
X        fprintf(stderr, "usage: %s hostid\n",argv[0]);
X        fprintf(stderr, "  e.g. %s b0b1fb0b\n", argv[0]);
X        exit(1);
X    }
X    sscanf(argv[1],"%08x",&hid);
X
X    hi = (hid & 0xfffffc00) >> 10;
X
X    printf("#!/bin/sh\n");
X    printf("# this script sets the hostid to %08x\n",hid);
X    printf("adb -w -k /vmunix /dev/mem <<END\n");
X    printf("_gethostid+4/W 11");
X    printf("%06x\n", hi);
X
X    low = hid & 0x3ff;
X    printf("_gethostid+8/W 90122");
X    printf("%03x\n",low);
X    printf("END\n");
}
SHAR_EOF
  $shar_touch -am 0811082994 'hid-1.4.9/hid.c' &&
  chmod 0600 'hid-1.4.9/hid.c' ||
  echo 'restore of hid-1.4.9/hid.c failed'
  shar_count="`wc -c < 'hid-1.4.9/hid.c'`"
  test 3055 -eq "$shar_count" ||
    echo "hid-1.4.9/hid.c: original size 3055, current size $shar_count"
  rm -f _sharnew.tmp
fi
# ============= hid-1.4.9/hid_solaris2.c ==============
if test -f 'hid-1.4.9/hid_solaris2.c' && test X"$1" != X"-c"; then
  echo 'x - skipping hid-1.4.9/hid_solaris2.c (file already exists)'
  rm -f _sharnew.tmp
else
  > _sharnew.tmp
  echo 'x - extracting hid-1.4.9/hid_solaris2.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'hid-1.4.9/hid_solaris2.c' &&
/* change the hostid reported by sysinfo and gethostid on Solaris 2.3/2.4 SPARC
X   - run the script this produces on stdout to actually make the change. Note
X     that you must have adb installed to use this 
X
X    e.g. hid_solaris2 b0b1fb0b | sh -v
X
Mark Henderson <markh@wimsey.bc.ca>
Placed in the public domain by the author - 3 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
SHAR_EOF
  : || echo 'restore of hid-1.4.9/hid_solaris2.c failed'
fi
echo 'End of archive part 1'
echo 'File hid-1.4.9/hid_solaris2.c is continued in part 2'
echo 2 > _sharseq.tmp
exit 0
-- 
Mark Henderson -- markh@wimsey.bc.ca, henderso@netcom.com (personal accounts)
ViaCrypt PGP Key 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


