pre-2.0.7: utmp adjustment
David Lee
T.D.Lee at durham.ac.uk
Thu Feb 17 17:30:49 GMT 2000
The "utmp directory" code (new at pre-2.0.7 under "--with-utmp") differs
somewhat from its documentation.
If the "utmp" feature is switched on, but "utmp directory" is not
specified, the documentation indicates that the default directory is the
system's own, whereas the code seems to default it to the root directory
("/"). I strongly suspect that the documented behaviour is preferable.
The patch below corrects this, I hope. (It seems OK on Solaris 2.6. Its
behaviour on other systems is untested. For the time being, if it can't
work out the filenames for the "utmp" files, it skips the logging.)
--
: David Lee I.T. Service :
: Systems Programmer Computer Centre :
: University of Durham :
: http://www.dur.ac.uk/~dcl0tdl South Road :
: Durham :
: Phone: +44 191 374 2882 U.K. :
*** smbd/connection.c.orig Wed Feb 2 15:29:53 2000
--- smbd/connection.c Thu Feb 17 16:56:05 2000
***************
*** 337,344 ****
return(rc);
}
! static void utmp_update(const pstring dirname, const struct utmp *u, const char *host)
{
pstring fname;
#ifdef HAVE_UTMPX_H
--- 337,402 ----
return(rc);
}
! /* Default path (if possible) */
! #ifdef HAVE_UTMPX_H
!
! # ifdef UTMPX_FILE
! static char *ut_pathname = UTMPX_FILE;
! # else
! static char *ut_pathname = "";
! # endif
! # ifdef WTMPX_FILE
! static char *wt_pathname = WTMPX_FILE;
! # else
! static char *wt_pathname = "";
! # endif
!
! #else /* HAVE_UTMPX_H */
!
! # ifdef UTMP_FILE
! static char *ut_pathname = UTMP_FILE;
! # else
! static char *ut_pathname = "";
! # endif
! # ifdef WTMP_FILE
! static char *wt_pathname = WTMP_FILE;
! # else
! static char *wt_pathname = "";
! # endif
!
! #endif /* HAVE_UTMPX_H */
!
! static void uw_pathname(pstring fname, const char *uw_name)
{
+ pstring dirname;
+
+ pstrcpy(dirname,lp_utmpdir());
+ trim_string(dirname,"","/");
+
+ /* Given directory: use it */
+ if (dirname != 0 && strlen(dirname) != 0) {
+ pstrcpy(fname, dirname);
+ pstrcat(fname, "/");
+ pstrcat(fname, uw_name);
+ return;
+ }
+
+ /* No given directory: attempt to use default paths */
+ if (uw_name[0] == 'u') {
+ pstrcpy(fname, ut_pathname);
+ return;
+ }
+
+ if (uw_name[0] == 'w') {
+ pstrcpy(fname, wt_pathname);
+ return;
+ }
+
+ pstrcpy(fname, "");
+ }
+
+ static void utmp_update(const struct utmp *u, const char *host)
+ {
pstring fname;
#ifdef HAVE_UTMPX_H
***************
*** 350,358 ****
pstrcpy(ux.ut_host, host);
}
! pstrcpy(fname, dirname);
! pstrcat(fname, "utmpx");
! utmpxname(fname);
uxrc = pututxline(&ux);
if (uxrc == NULL) {
DEBUG(2,("utmp_update: pututxline() failed\n"));
--- 408,418 ----
pstrcpy(ux.ut_host, host);
}
! uw_pathname(fname, "utmpx");
! DEBUG(2,("utmp_update: fname:%s\n", fname));
! if (strlen(fname) != 0) {
! utmpxname(fname);
! }
uxrc = pututxline(&ux);
if (uxrc == NULL) {
DEBUG(2,("utmp_update: pututxline() failed\n"));
***************
*** 359,378 ****
return;
}
! pstrcpy(fname, dirname);
! pstrcat(fname, "wtmpx");
! updwtmpx(fname, &ux);
#else
! pstrcpy(fname, dirname);
! pstrcat(fname, "utmp");
!
! utmpname(fname);
pututline(u);
! pstrcpy(fname, dirname);
! pstrcat(fname, "wtmp");
! /* *** OK. Appending wtmp (as distinct from overwriting utmp) has
me baffled. How is it to be done? *** */
#endif
}
--- 419,440 ----
return;
}
! uw_pathname(fname, "wtmpx");
! DEBUG(2,("utmp_update: fname:%s\n", fname));
! if (strlen(fname) != 0) {
! updwtmpx(fname, &ux);
! }
#else
! uw_pathname(fname, "utmp");
! DEBUG(2,("utmp_update: fname:%s\n", fname));
! if (strlen(fname) != 0) {
! utmpname(fname);
! }
pututline(u);
! uw_pathname(fname, "wtmp");
! /* *** Hmmm. Appending wtmp (as distinct from overwriting utmp) has
me baffled. How is it to be done? *** */
#endif
}
***************
*** 380,386 ****
static void utmp_yield(pid_t pid, const connection_struct *conn, int i)
{
struct utmp u;
- pstring dirname;
if (! lp_utmp(SNUM(conn))) {
DEBUG(2,("utmp_yield: lp_utmp() NULL\n"));
--- 442,447 ----
***************
*** 387,405 ****
return;
}
! pstrcpy(dirname,lp_utmpdir());
! trim_string(dirname,"","/");
! pstrcat(dirname,"/");
- DEBUG(2,("utmp_yield: dir:%s conn: user:%s cnum:%d i:%d\n",
- dirname, conn->user, conn->cnum, i));
-
memset((char *)&u, '\0', sizeof(struct utmp));
u.ut_type = DEAD_PROCESS;
u.ut_exit.e_termination = 0;
u.ut_exit.e_exit = 0;
if (utmp_fill(&u, conn, pid, i) == 0) {
! utmp_update(dirname, &u, NULL);
}
}
--- 448,462 ----
return;
}
! DEBUG(2,("utmp_yield: conn: user:%s cnum:%d i:%d\n",
! conn->user, conn->cnum, i));
memset((char *)&u, '\0', sizeof(struct utmp));
u.ut_type = DEAD_PROCESS;
u.ut_exit.e_termination = 0;
u.ut_exit.e_exit = 0;
if (utmp_fill(&u, conn, pid, i) == 0) {
! utmp_update(&u, NULL);
}
}
***************
*** 407,413 ****
{
extern int Client;
struct utmp u;
- pstring dirname;
if (conn == NULL) {
DEBUG(2,("utmp_claim: conn NULL\n"));
--- 464,469 ----
***************
*** 419,430 ****
return;
}
! pstrcpy(dirname,lp_utmpdir());
! trim_string(dirname,"","/");
! pstrcat(dirname,"/");
!
! DEBUG(2,("utmp_claim: dir:%s conn: user:%s cnum:%d i:%d\n",
! dirname, conn->user, conn->cnum, i));
DEBUG(2,("utmp_claim: crec: pid:%d, cnum:%d name:%s addr:%s mach:%s DNS:%s\n",
crec->pid, crec->cnum, crec->name, crec->addr, crec->machine, client_name(Client)));
--- 475,482 ----
return;
}
! DEBUG(2,("utmp_claim: conn: user:%s cnum:%d i:%d\n",
! conn->user, conn->cnum, i));
DEBUG(2,("utmp_claim: crec: pid:%d, cnum:%d name:%s addr:%s mach:%s DNS:%s\n",
crec->pid, crec->cnum, crec->name, crec->addr, crec->machine, client_name(Client)));
***************
*** 432,438 ****
memset((char *)&u, '\0', sizeof(struct utmp));
u.ut_type = USER_PROCESS;
if (utmp_fill(&u, conn, crec->pid, i) == 0) {
! utmp_update(dirname, &u, crec->machine);
}
}
--- 484,490 ----
memset((char *)&u, '\0', sizeof(struct utmp));
u.ut_type = USER_PROCESS;
if (utmp_fill(&u, conn, crec->pid, i) == 0) {
! utmp_update(&u, crec->machine);
}
}
More information about the samba-technical
mailing list