diff -r -u original-2.0.7pre2/source/include/proto.h 2.0.7pre2/source/include/proto.h --- original-2.0.7pre2/source/include/proto.h Fri Mar 17 09:29:10 2000 +++ 2.0.7pre2/source/include/proto.h Fri Mar 24 13:54:17 2000 @@ -2408,6 +2408,7 @@ void conn_close_all(void); BOOL conn_idle_all(time_t t, int deadtime); void conn_free(connection_struct *conn); +int conn_count(connection_struct *conn); /*The following definitions come from smbd/connection.c */ diff -r -u original-2.0.7pre2/source/smbd/conn.c 2.0.7pre2/source/smbd/conn.c --- original-2.0.7pre2/source/smbd/conn.c Fri Mar 17 09:29:43 2000 +++ 2.0.7pre2/source/smbd/conn.c Fri Mar 24 13:54:17 2000 @@ -187,3 +187,20 @@ ZERO_STRUCTP(conn); free(conn); } + +/**************************************************************************** +count connections from an ip +****************************************************************************/ +int conn_count(connection_struct *conn) +{ + connection_struct *curr, *next; + int a = 0; + + for (curr = Connections; curr; curr = curr->next) + { + if (strequal(curr->client_address, conn->client_address)) + a++; + } + + return a; +} diff -r -u original-2.0.7pre2/source/smbd/connection.c 2.0.7pre2/source/smbd/connection.c --- original-2.0.7pre2/source/smbd/connection.c Sat Mar 18 12:39:36 2000 +++ 2.0.7pre2/source/smbd/connection.c Fri Mar 24 14:03:26 2000 @@ -323,18 +323,46 @@ static int utmp_fill(struct utmp *u, const connection_struct *conn, pid_t pid, int i) { struct timeval timeval; - int rc; + struct utmp *u2; + /* int rc; */ + int high, low; pstrcpy(u->ut_user, conn->user); - rc = ut_id_encode(i, u->ut_id); - slprintf(u->ut_line, 12, "smb/%d", i); + /* rc = ut_id_encode(i, u->ut_id); */ + + /* we'll set u->ut_id to SMxx, where xx is a 2 char representation of pid */ + low = pid & 0x00FF; + high = (pid & 0xFF00)>>8; + + u->ut_id[0] = 'S'; + u->ut_id[1] = 'M'; + u->ut_id[2] = high; + u->ut_id[3] = low; + + DEBUG(1,("pid: %d high: %d low: %d\n", pid, high, low)); + + /* see if we have an entry with a matching ut_id */ + setutent(); + u2 = getutid(u); + endutent(); + + /* if so, copy it's ut_line to our ut_line, otherwise, use a new one */ + if (u2) + pstrcpy(u->ut_line, u2->ut_line); + else + slprintf(u->ut_line, 12, "smb/%d", i); u->ut_pid = pid; - gettimeofday(&timeval, NULL); - u->ut_time = timeval.tv_sec; + /* gettimeofday(&timeval, NULL); + u->ut_time = timeval.tv_sec; */ + + /* ut_time is just ut_tv.tv_sec */ + gettimeofday(&u->ut_tv, NULL); - return(rc); + /* return(rc); */ + /* no idea what I should return */ + return(0); } static void utmp_update(const pstring dirname, const struct utmp *u, const char *host) @@ -365,11 +393,20 @@ pstrcat(fname, "wtmpx"); updwtmpx(fname, &ux); #else - pstrcpy(fname, dirname); + /* why does this give a compiler warning? */ + if (host) + pstrcpy(u->ut_host, host); + + /* is this really neccesary? works fine with it commented out here */ + /* pstrcpy(fname, dirname); pstrcat(fname, "utmp"); - utmpname(fname); + utmpname(fname); */ + + /* rewind the utmp file before playing with it, then close it afterwards */ + setutent(); pututline(u); + endutent(); pstrcpy(fname, dirname); pstrcat(fname, "wtmp"); @@ -386,6 +423,15 @@ if (! lp_utmp(SNUM(conn))) { DEBUG(2,("utmp_yield: lp_utmp() NULL\n")); + return; + } + + /* this check only compares the client_address field, is this enough? */ + a = conn_count(conn); + a--; + if (a > 1) + { + DEBUG(1,("utmp_yield: not yielding utmp entry, %d connections still active\n", a)); return; }