wtmpx utility for solaris

Ryan (warf@GOODNET.COM)
Mon, 30 Mar 1998 04:18:31 -0700

This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
Send mail to mime@docserver.cac.washington.edu for more info.

--Boundary_(ID_J0scN9ur2dd7HrJID/CzOQ)
Content-id: <Pine.GSO.3.95.980330041759.22806B@goodguy>
Content-type: TEXT/PLAIN; CHARSET=US-ASCII

There seems to be a problem with the tmpx file for solairs. Doesn't log
the full IP's of the users loging in, it truncates it somehow. Therefore,
the 'last' utility is praticly useless when trying to track down someone.

The wtmpx file logs the full data and doesn't truncate anything. I
could not find a utility that viewed the wtmpx file. So, I wrote a quick
one. It has come in very handy. I have attached the source code that I
wrote.

Feel free to revise the code or give comments. If you do revise it,
please leave my name / e-mail address on there somewhere so I could get
contacted if someone makes it better so I can get a copy! :) It could
have been writen cleaner, but it was a quicky to get the options I wanted
on it. I didn't want to spend a WHOLE lot of time on it, I just needed
it working (if you know what I mean).

____
| _ \ _ _ __ _ _ __
| |_) | | | |/ _` | '_ \
| _ <| |_| | (_| | | | |
|_| \_\\__, |\__,_|_| |_|
|___/
GoodNet System Administration
warf@goodnet.com/ryanw@goodnet.com

--Boundary_(ID_J0scN9ur2dd7HrJID/CzOQ)
Content-id: <Pine.GSO.3.95.980330041831.22806C@goodguy>
Content-type: TEXT/PLAIN; name=lastx.c; charset=US-ASCII
Content-description: lastx.c
Content-disposition: ATTACHMENT; FILENAME=lastx.c
Content-transfer-encoding: BASE64

LyoNCiAgICAgTGFzdHggdjEuMCAgICBXcml0dGVuIGJ5IFJ5YW4gV3lsZXIg
IChyeWFud0Bnb29kbmV0LmNvbSkNCg0KICAgIA0KRGVjcmlwdGlvbjoNCg0K
ICAgIEEgJ2xhc3QnIHR5cGUgdXRpbGl0eSBmb3IgU29sYXJpcyB3aGljaCBk
aXNwbGF5cyB0aGUgZnVsbCBpbmZvcm1hdGlvbg0KZm9yIHRoZSB1c2Vycy4N
Cg0KV2h5Og0KD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WUgdGltZSBz
cGVjaWZ5IHNwZWNpZmljIHVzZXIpXG4iKTsNCiAgICAgICAgICAgICAgcHJp
bnRmKCIgICVzICAlc1xuIix1dG1wX2VudC51dF91c2VyLHV0bXBfZW50LnV0
X2hvc3QpOw0KICAgICAgICAgICAgICBjb3VudCsrOw0KICAgICAgICAgIH0N
CiAgICAgICAgbmwoKTsNCiAgICAgICAgcHJpbnRmKCJUaGVyZSB3ZXJlICVp
IHJlY29yZHMgbGlzdGVkIixjb3VudCk7DQogICAgICAgIG5sKCk7DQogICAg
ICAgIGNsb3NlKGYpOyAgDQogICAgICB9DQogICAgfSBlbHNlIHsNCiAgICAg
IGlmKGRlYnVnPT0xKSB7DQogICAgICAgIGlmKG90aGVyX2ZpbGU9PTApDQog
ICAgICAgICAgaWYoKGY9b3BlbihXVE1QLE9fUkRXUikpPj0wKQ0KICAgICAg
ICAgICAgc3VjY2Vzcz0xOw0KICAgICAgICAgIGVsc2UgDQogICAgICAgICAg
ICBwcmludGYoIiAgRXJyb3I6ICBDaGVjayBmaWxlbmFtZS9wYXRoOiAgJXNc
blxuIixXVE1QKTsNCiAgICAgICAgaWYoc3VjY2Vzcz09MSkgew0KICAgICAg
ICAgIHdoaWxlKHJlYWQoZiwmdXRtcF9lbnQsc2l6ZW9mKHV0bXBfZW50KSkp
IHsNCiAgICAgICAgICAgICAgaWYoY291bnQ9PTApDQogICAgICAgICAgICAg
ICAgcHJpbnRmKCIgIFVzZXIgICAgICAgIElQIEFkZHJlc3MgICAgICAgICAo
dG8gc2VlIHRpbWUgc3BlY2lmeSBzcGVjaWZpYyB1c2VyKVxuIik7DQogICAg
ICAgICAgICAgIHByaW50ZigiICAlcyAgJXNcbiIsdXRtcF9lbnQudXRfdXNl
cix1dG1wX2VudC51dF9ob3N0KTsNCiAgICAgICAgICAgICAgY291bnQrKzsN
CiAgICAgICAgICAgIH0NCiAgICAgICAgICBubCgpOw0KICAgICAgICAgIHBy
aW50ZigiVGhlcmUgd2VyZSAlaSByZWNvcmRzIGxpc3RlZCIsY291bnQpOw0K
ICAgICAgICAgIG5sKCk7DQogICAgICAgICAgY2xvc2UoZik7ICANCiAgICAg
ICAgfQ0KICAgICAgfSBlbHNlIHsNCiAgICAgICAgaWYob3RoZXJfZmlsZT09
MCkNCiAgICAgICAgICBpZigoZj1vcGVuKFdUTVAsT19SRFdSKSk+PTApDQog
ICAgICAgICAgICBzdWNjZXNzPTE7DQogICAgICAgICAgZWxzZSANCiAgICAg
ICAgICAgIHByaW50ZigiICBFcnJvcjogIENoZWNrIGZpbGVuYW1lL3BhdGg6
ICAlc1xuXG4iLFdUTVApOw0KICAgICAgICBpZihzdWNjZXNzPT0xKSB7DQog
ICAgICAgICAgd2hpbGUocmVhZChmLCZ1dG1wX2VudCxzaXplb2YodXRtcF9l
bnQpKSkNCiAgICAgICAgICAgIGlmKCFzdHJjbXAodXRtcF9lbnQudXRfbmFt
ZSwgJnVzZXIpKSB7ICANCiAgICAgICAgICAgICAgICBpZihjb3VudD09MCkN
CiAgICAgICAgICAgICAgICAgIHByaW50ZigiICBVc2VyICAgICAgICBJUCBB
ZGRyZXNzICAgICAgICAgICAgIFRpbWVcbiIpOw0KICAgICAgICAgICAgICAg
IGRhdGUgPSBjdGltZSgmdXRtcF9lbnQudXRfeHRpbWUpOw0KICAgICAgICAg
ICAgICAgIGRhdGVbc3RybGVuKGRhdGUpLTFdID0gJ1wwJzsgDQogICAgICAg
ICAgICAgICAgcHJpbnRmKCIgICVzICAlcyAgJXNcbiIsdXRtcF9lbnQudXRf
dXNlcix1dG1wX2VudC51dF9ob3N0LGRhdGUpOw0KICAgICAgICAgICAgICAg
Y291bnQrKzsNCiAgICAgICAgICAgICAgfQ0KICAgICAgICAgIG5sKCk7DQog
ICAgICAgICAgcHJpbnRmKCJUaGVyZSB3ZXJlICVpIHJlY29yZHMgbGlzdGVk
Iixjb3VudCk7DQogICAgICAgICAgbmwoKTsNCiAgICAgICAgICBjbG9zZShm
KTsgIA0KICAgICAgICB9DQogICAgICB9DQogICAgfQ0KICB9IGVsc2Ugew0K
ICAgIHByaW50ZigiICAgVXNhZ2U6ICVzIDwtaCB8IC1hIHwgLWQgfCBbdXNl
cm5hbWVdPiA8LWYgW2ZpbGVuYW1lXT4iLGFyZ3ZbMF0pOw0KICAgIG5sKCk7
DQogICAgcHJpbnRmKCIgT3B0aW9uczogIC1hICAgICBEaXNwbGF5IGFsbCB1
c2VycyIpOw0KICAgIG5sKCk7DQogICAgcHJpbnRmKCIgICAgICAgICAgIC1k
ICAgICBEaXNwbGF5IGFsbCBFbnRyeXMiKTsNCiAgICBubCgpOw0KICAgIHBy
aW50ZigiICAgICAgICAgICB1c2VyICAgRGlzcGxheXMgZW50cmllcyBmb3Ig
b25seSB0aGF0IHVzZXIiKTsNCiAgICBubCgpOw0KICAgIHByaW50ZigiICAg
ICAgICAgICAtZiAgICAgU3BlY2lmeSBhIHNwZWNpZmljIHd0bXB4IGZpbGUg
dG8gdXNlIik7DQogICAgbmwoKTsgDQogICAgcHJpbnRmKCIgICAgICAgICAg
IC1oICAgICBFeHRlbmRlZCBoZWxwIChleGFtcGxlcykgJWkiLGhlbHApOw0K
ICAgIG5sKCk7IG5sKCk7DQogICAgaWYoaGVscD09MSkgew0KICAgICAgcHJp
bnRmKCIgRXhhbXBsZXM6Iik7DQogICAgICBubCgpOw0KICAgICAgcHJpbnRm
KCIgICAlcyByeWFudyIsYXJndlswXSk7DQogICAgICBubCgpOw0KICAgICAg
cHJpbnRmKCIgICAgIFNob3dzIGFsbCBsb2dpbnMgZm9yIHJ5YW53Iik7DQog
ICAgICBubCgpOyBubCgpOw0KICAgICAgcHJpbnRmKCIgICAlcyAtYSIsYXJn
dlswXSk7DQogICAgICBubCgpOw0KICAgICAgcHJpbnRmKCIgICAgIFNob3dz
IGFsbCByZWNvcmRzIGluIHd0bXB4IGZpbGUiKTsNCiAgICAgIG5sKCk7IG5s
KCk7DQogICAgICBwcmludGYoIiAgICVzIC1kIixhcmd2WzBdKTsNCiAgICAg
IG5sKCk7DQogICAgICBwcmludGYoIiAgICAgU2hvd3MgZXZlbiBNT1JFIHJl
Y29yZHMgaW4gd3RtcHggZmlsZSIpOw0KICAgICAgbmwoKTsgbmwoKTsNCiAg
ICAgIHByaW50ZigiICAgJXMgLWYgL3Zhci9hZG0vYmFja3VwL3d0bXAuMSBy
eWFudyIsYXJndlswXSk7DQogICAgICBubCgpOw0KICAgICAgcHJpbnRmKCIg
ICAgIFNob3dzIGFsbCBsb2dpbnMgb2YgdXNlciByeWFudyBpbiBmaWxlIC92
YXIvYWRtL2JhY2t1cC93dG1wLjEiKTsNCiAgICAgIG5sKCk7IG5sKCk7DQog
ICAgICBwcmludGYoIiAgICVzIC1hIC1mIDxmaWxlbmFtZT4iLGFyZ3ZbMF0p
Ow0KICAgICAgbmwoKTsNCiAgICAgIHByaW50ZigiICAgICBTaG93cyBhbGwg
cmVjb3JkcyBpbiA8ZmlsZW5hbWU+Iik7DQogICAgICBubCgpOw0KICAgIH0N
CiAgfQ0KICBleGl0KDApOw0KfQ0K

--Boundary_(ID_J0scN9ur2dd7HrJID/CzOQ)--