Correct "succeded" typos.
[nivanova/samba-autobuild/.git] / source3 / smbd / utmp.c
index af947ef4620fd29cf460e82fcec0deadf01248de..cdbcc28cce62f560a6ecd1d875e6b4b60bf585ec 100644 (file)
@@ -19,6 +19,8 @@
 */
 
 #include "includes.h"
+#include "system/filesys.h"
+#include "smbd/smbd.h"
 
 /****************************************************************************
 Reflect connection status in utmp/wtmp files.
@@ -113,18 +115,18 @@ Notes:
  */
 
 void sys_utmp_claim(const char *username, const char *hostname,
-                       const char *ip_addr_str,
-                       const char *id_str, int id_num)
+                   const char *id_str, int id_num)
 {}
 
 void sys_utmp_yield(const char *username, const char *hostname,
-                       const char *ip_addr_str,
-                       const char *id_str, int id_num)
+                   const char *id_str, int id_num)
 {}
 
 #else /* WITH_UTMP */
 
+#ifdef HAVE_UTMP_H
 #include <utmp.h>
+#endif
 
 #ifdef HAVE_UTMPX_H
 #include <utmpx.h>
@@ -142,7 +144,7 @@ void sys_utmp_yield(const char *username, const char *hostname,
 
 #ifdef HAVE_UTMPX_H
 
-static const char *ux_pathname =
+static const char * const ux_pathname =
 # if defined (UTMPX_FILE)
        UTMPX_FILE ;
 # elif defined (_UTMPX_FILE)
@@ -153,7 +155,7 @@ static const char *ux_pathname =
        "" ;
 # endif
 
-static const char *wx_pathname =
+static const char * const wx_pathname =
 # if defined (WTMPX_FILE)
        WTMPX_FILE ;
 # elif defined (_WTMPX_FILE)
@@ -166,7 +168,7 @@ static const char *wx_pathname =
 
 #endif /* HAVE_UTMPX_H */
 
-static const char *ut_pathname =
+static const char * const ut_pathname =
 # if defined (UTMP_FILE)
        UTMP_FILE ;
 # elif defined (_UTMP_FILE)
@@ -177,7 +179,7 @@ static const char *ut_pathname =
        "" ;
 # endif
 
-static const char *wt_pathname =
+static const char * const wt_pathname =
 # if defined (WTMP_FILE)
        WTMP_FILE ;
 # elif defined (_WTMP_FILE)
@@ -216,7 +218,7 @@ static char *uw_pathname(TALLOC_CTX *ctx,
 
        /* For w-files, first look for explicit "wtmp dir" */
        if (uw_name[0] == 'w') {
-               dirname = talloc_strdup(ctx, lp_wtmpdir());
+               dirname = talloc_strdup(ctx, lp_wtmp_directory());
                if (!dirname) {
                        return NULL;
                }
@@ -225,7 +227,7 @@ static char *uw_pathname(TALLOC_CTX *ctx,
 
        /* For u-files and non-explicit w-dir, look for "utmp dir" */
        if ((dirname == NULL) || (strlen(dirname) == 0)) {
-               dirname = talloc_strdup(ctx, lp_utmpdir());
+               dirname = talloc_strdup(ctx, lp_utmp_directory());
                if (!dirname) {
                        return NULL;
                }
@@ -470,22 +472,23 @@ static int ut_id_encode(int i, char *fourbyte)
        int nbase;
        const char *ut_id_encstr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
-       fourbyte[0] = 'S';
-       fourbyte[1] = 'M';
-
 /*
- * Encode remaining 2 bytes from 'i'.
  * 'ut_id_encstr' is the character set on which modulo arithmetic is done.
  * Example: digits would produce the base-10 numbers from '001'.
  */
        nbase = strlen(ut_id_encstr);
 
+       fourbyte[0] = ut_id_encstr[i % nbase];
+       i /= nbase;
+       fourbyte[1] = ut_id_encstr[i % nbase];
+       i /= nbase;
        fourbyte[3] = ut_id_encstr[i % nbase];
        i /= nbase;
        fourbyte[2] = ut_id_encstr[i % nbase];
        i /= nbase;
 
-       return(i);      /* 0: good; else overflow */
+       /* we do not care about overflows as i is a random number */
+       return 0;
 }
 #endif /* defined(HAVE_UT_UT_ID) */
 
@@ -495,7 +498,6 @@ static int ut_id_encode(int i, char *fourbyte)
 */
 static bool sys_utmp_fill(struct utmp *u,
                        const char *username, const char *hostname,
-                       const char *ip_addr_str,
                        const char *id_str, int id_num)
 {
        struct timeval timeval;
@@ -516,15 +518,10 @@ static bool sys_utmp_fill(struct utmp *u,
         * ut_line:
         *      If size limit proves troublesome, then perhaps use "ut_id_encode()".
         */
-       if (strlen(id_str) > sizeof(u->ut_line)) {
-               DEBUG(1,("id_str [%s] is too long for %lu char utmp field\n",
-                        id_str, (unsigned long)sizeof(u->ut_line)));
-               return False;
-       }
        utmp_strcpy(u->ut_line, id_str, sizeof(u->ut_line));
 
 #if defined(HAVE_UT_UT_PID)
-       u->ut_pid = sys_getpid();
+       u->ut_pid = getpid();
 #endif
 
 /*
@@ -546,27 +543,6 @@ static bool sys_utmp_fill(struct utmp *u,
 #if defined(HAVE_UT_UT_HOST)
        utmp_strcpy(u->ut_host, hostname, sizeof(u->ut_host));
 #endif
-#if defined(HAVE_IPV6) && defined(HAVE_UT_UT_ADDR_V6)
-       memset(&u->ut_addr_v6, '\0', sizeof(u->ut_addr_v6));
-       if (ip_addr_str) {
-               struct in6_addr addr;
-               if (inet_pton(AF_INET6, ip_addr_str, &addr) > 0) {
-                       memcpy(&u->ut_addr_v6, &addr, sizeof(addr));
-               }
-       }
-#elif defined(HAVE_UT_UT_ADDR)
-       memset(&u->ut_addr, '\0', sizeof(u->ut_addr));
-       if (ip_addr_str) {
-               struct in_addr addr;
-               if (inet_pton(AF_INET, ip_addr_str, &addr) > 0) {
-                       memcpy(&u->ut_addr, &addr, sizeof(addr));
-               }
-       }
-       /*
-        * "(unsigned long) ut_addr" apparently exists on at least HP-UX 10.20.
-        * Volunteer to implement, please ...
-        */
-#endif
 
 #if defined(HAVE_UT_UT_ID)
        if (ut_id_encode(id_num, u->ut_id) != 0) {
@@ -583,8 +559,7 @@ static bool sys_utmp_fill(struct utmp *u,
 ****************************************************************************/
 
 void sys_utmp_yield(const char *username, const char *hostname,
-                       const char *ip_addr_str,
-                       const char *id_str, int id_num)
+                   const char *id_str, int id_num)
 {
        struct utmp u;
 
@@ -599,7 +574,7 @@ void sys_utmp_yield(const char *username, const char *hostname,
        u.ut_type = DEAD_PROCESS;
 #endif
 
-       if (!sys_utmp_fill(&u, username, hostname, ip_addr_str, id_str, id_num))
+       if (!sys_utmp_fill(&u, username, hostname, id_str, id_num))
                return;
 
        sys_utmp_update(&u, NULL, False);
@@ -610,8 +585,7 @@ void sys_utmp_yield(const char *username, const char *hostname,
 ****************************************************************************/
 
 void sys_utmp_claim(const char *username, const char *hostname,
-                       const char *ip_addr_str,
-                       const char *id_str, int id_num)
+                   const char *id_str, int id_num)
 {
        struct utmp u;
 
@@ -621,7 +595,7 @@ void sys_utmp_claim(const char *username, const char *hostname,
        u.ut_type = USER_PROCESS;
 #endif
 
-       if (!sys_utmp_fill(&u, username, hostname, ip_addr_str, id_str, id_num))
+       if (!sys_utmp_fill(&u, username, hostname, id_str, id_num))
                return;
 
        sys_utmp_update(&u, hostname, True);