Fixed tty logging

Signed-off-by: Russ Magee <rmagee@gmail.com>
This commit is contained in:
Russ Magee 2019-07-04 20:23:04 -07:00
parent 907ffc4058
commit f388f970e4

View file

@ -16,23 +16,15 @@ package goutmp
//typedef char char_t; //typedef char char_t;
// //
// //
//void pututmp(struct utmp* entry, char* name, char* host) { //void pututmp(struct utmp* entry, char* uname, char* ptsname, char* host) {
// //TODO: if ttyname returns NULL, it's probably a network
// // connection and the pty should be passed in to this func.
// char* stdinName = ttyname(STDIN_FILENO);
// if( !stdinName ) {
// stdinName = "/dev/ptyN";
// }
//
// entry->ut_type = USER_PROCESS; // entry->ut_type = USER_PROCESS;
// entry->ut_pid = getpid(); // entry->ut_pid = getpid();
// strcpy(entry->ut_line, stdinName + strlen("/dev/")); // strcpy(entry->ut_line, ptsname + strlen("/dev/"));
// /* only correct for ptys named /dev/tty[pqr][0-9a-z] */
// //
// strcpy(entry->ut_id, stdinName + strlen("/dev/tty")); // strcpy(entry->ut_id, ptsname + strlen("/dev/pts/"));
// //
// entry->ut_time = time(NULL); // entry->ut_time = time(NULL);
// strcpy(entry->ut_user, name); // strcpy(entry->ut_user, uname);
// strcpy(entry->ut_host, host); // strcpy(entry->ut_host, host);
// entry->ut_addr = 0; // entry->ut_addr = 0;
// setutent(); // setutent();
@ -109,11 +101,11 @@ func GetHost(addr string) (h string) {
} }
// Put a username and the originating host/IP to utmp // Put a username and the originating host/IP to utmp
func Put_utmp(user string, host string) UtmpEntry { func Put_utmp(user, ptsName, host string) UtmpEntry {
var entry UtmpEntry var entry UtmpEntry
//log.Println("Put_utmp:host ", host, " user ", user) //log.Println("Put_utmp:host ", host, " user ", user)
C.pututmp(&entry.entry, C.CString(user), C.CString(host)) C.pututmp(&entry.entry, C.CString(user), C.CString(ptsName), C.CString(host))
return entry return entry
} }
@ -123,7 +115,7 @@ func Unput_utmp(entry UtmpEntry) {
} }
// Put the login app, username and originating host/IP to lastlog // Put the login app, username and originating host/IP to lastlog
func Put_lastlog_entry(app string, usr string, host string) { func Put_lastlog_entry(app, usr, ptsname, host string) {
u, e := user.Lookup(usr) u, e := user.Lookup(usr)
if e != nil { if e != nil {
return return