smbd/utmp.c

ソースコードを見る。

関数

void sys_utmp_claim (const char *username, const char *hostname, struct in_addr *ipaddr, const char *id_str, int id_num)
void sys_utmp_yield (const char *username, const char *hostname, struct in_addr *ipaddr, const char *id_str, int id_num)
static void uw_pathname (pstring fname, const char *uw_name, const char *uw_default)
static void pututline_my (pstring uname, struct utmp *u, BOOL claim)
static void updwtmp_my (pstring wname, struct utmp *u, BOOL claim)
static void utmp_nox_update (struct utmp *u, BOOL claim)
static void utmp_strcpy (char *dest, const char *src, size_t n)
static void sys_utmp_update (struct utmp *u, const char *hostname, BOOL claim)
static int ut_id_encode (int i, char *fourbyte)
static BOOL sys_utmp_fill (struct utmp *u, const char *username, const char *hostname, struct in_addr *ipaddr, const char *id_str, int id_num)

変数

static const char * ux_pathname
 _UTMPX_FILE
 _PATH_UTMPX
static const char * wx_pathname
 _WTMPX_FILE
 _PATH_WTMPX
static const char * ut_pathname
 _UTMP_FILE
 _PATH_UTMP
static const char * wt_pathname
 _WTMP_FILE
 _PATH_WTMP
static const char * ll_pathname


関数

void sys_utmp_claim ( const char *  username,
const char *  hostname,
struct in_addr *  ipaddr,
const char *  id_str,
int  id_num 
)

utmp.c116 行で定義されています。

参照元 session_claim().

00119 {}

void sys_utmp_yield ( const char *  username,
const char *  hostname,
struct in_addr *  ipaddr,
const char *  id_str,
int  id_num 
)

utmp.c121 行で定義されています。

参照元 session_yield().

00124 {}

static void uw_pathname ( pstring  fname,
const char *  uw_name,
const char *  uw_default 
) [static]

utmp.c211 行で定義されています。

参照先 trim_char().

参照元 sys_utmp_update()utmp_nox_update().

00212 {
00213         pstring dirname;
00214 
00215         pstrcpy(dirname, "");
00216 
00217         /* For w-files, first look for explicit "wtmp dir" */
00218         if (uw_name[0] == 'w') {
00219                 pstrcpy(dirname,lp_wtmpdir());
00220                 trim_char(dirname,'\0','/');
00221         }
00222 
00223         /* For u-files and non-explicit w-dir, look for "utmp dir" */
00224         if (strlen(dirname) == 0) {
00225                 pstrcpy(dirname,lp_utmpdir());
00226                 trim_char(dirname,'\0','/');
00227         }
00228 
00229         /* If explicit directory above, use it */
00230         if (strlen(dirname) != 0) {
00231                 pstrcpy(fname, dirname);
00232                 pstrcat(fname, "/");
00233                 pstrcat(fname, uw_name);
00234                 return;
00235         }
00236 
00237         /* No explicit directory: attempt to use default paths */
00238         if (strlen(uw_default) == 0) {
00239                 /* No explicit setting, no known default.
00240                  * Has it yet been ported to this OS?
00241                  */
00242                 DEBUG(2,("uw_pathname: unable to determine pathname\n"));
00243         }
00244         pstrcpy(fname, uw_default);
00245 }

static void pututline_my ( pstring  uname,
struct utmp *  u,
BOOL  claim 
) [static]

utmp.c253 行で定義されています。

参照元 utmp_nox_update().

00254 {
00255         DEBUG(1,("pututline_my: not yet implemented\n"));
00256         /* BSD implementor: may want to consider (or not) adjusting "lastlog" */
00257 }

static void updwtmp_my ( pstring  wname,
struct utmp *  u,
BOOL  claim 
) [static]

utmp.c267 行で定義されています。

参照先 fd.

参照元 utmp_nox_update().

00268 {
00269         int fd;
00270         struct stat buf;
00271 
00272         if (! claim) {
00273                 /*
00274                  * BSD-like systems:
00275                  *      may use empty ut_name to distinguish a logout record.
00276                  *
00277                  * May need "if defined(SUNOS4)" etc. around some of these,
00278                  * but try to avoid if possible.
00279                  *
00280                  * SunOS 4:
00281                  *      man page indicates ut_name and ut_host both NULL
00282                  * FreeBSD 4.0:
00283                  *      man page appears not to specify (hints non-NULL)
00284                  *      A correspondent suggest at least ut_name should be NULL
00285                  */
00286 #if defined(HAVE_UT_UT_NAME)
00287                 memset((char *)&u->ut_name, '\0', sizeof(u->ut_name));
00288 #endif
00289 #if defined(HAVE_UT_UT_HOST)
00290                 memset((char *)&u->ut_host, '\0', sizeof(u->ut_host));
00291 #endif
00292         }
00293         /* Stolen from logwtmp function in libutil.
00294          * May be more locking/blocking is needed?
00295          */
00296         if ((fd = open(wname, O_WRONLY|O_APPEND, 0)) < 0)
00297                 return;
00298         if (fstat(fd, &buf) == 0) {
00299                 if (write(fd, (char *)u, sizeof(struct utmp)) != sizeof(struct utmp))
00300                 (void) ftruncate(fd, buf.st_size);
00301         }
00302         (void) close(fd);
00303 }

static void utmp_nox_update ( struct utmp *  u,
BOOL  claim 
) [static]

utmp.c310 行で定義されています。

参照先 pututline_my()updwtmp_my()ut_pathnameuw_pathname()wt_pathname.

参照元 sys_utmp_update().

00311 {
00312         pstring uname, wname;
00313 #if defined(PUTUTLINE_RETURNS_UTMP)
00314         struct utmp *urc;
00315 #endif /* PUTUTLINE_RETURNS_UTMP */
00316 
00317         uw_pathname(uname, "utmp", ut_pathname);
00318         DEBUG(2,("utmp_nox_update: uname:%s\n", uname));
00319 
00320 #ifdef HAVE_PUTUTLINE
00321         if (strlen(uname) != 0) {
00322                 utmpname(uname);
00323         }
00324 
00325 # if defined(PUTUTLINE_RETURNS_UTMP)
00326         setutent();
00327         urc = pututline(u);
00328         endutent();
00329         if (urc == NULL) {
00330                 DEBUG(2,("utmp_nox_update: pututline() failed\n"));
00331                 return;
00332         }
00333 # else  /* PUTUTLINE_RETURNS_UTMP */
00334         setutent();
00335         pututline(u);
00336         endutent();
00337 # endif /* PUTUTLINE_RETURNS_UTMP */
00338 
00339 #else   /* HAVE_PUTUTLINE */
00340         if (strlen(uname) != 0) {
00341                 pututline_my(uname, u, claim);
00342         }
00343 #endif /* HAVE_PUTUTLINE */
00344 
00345         uw_pathname(wname, "wtmp", wt_pathname);
00346         DEBUG(2,("utmp_nox_update: wname:%s\n", wname));
00347         if (strlen(wname) != 0) {
00348 #ifdef HAVE_UPDWTMP
00349                 updwtmp(wname, u);
00350                 /*
00351                  * updwtmp() and the newer updwtmpx() may be unsymmetrical.
00352                  * At least one OS, Solaris 2.x declares the former in the
00353                  * "utmpx" (latter) file and context.
00354                  * In the Solaris case this is irrelevant: it has both and
00355                  * we always prefer the "x" case, so doesn't come here.
00356                  * But are there other systems, with no "x", which lack
00357                  * updwtmp() perhaps?
00358                  */
00359 #else
00360                 updwtmp_my(wname, u, claim);
00361 #endif /* HAVE_UPDWTMP */
00362         }
00363 }

static void utmp_strcpy ( char *  dest,
const char *  src,
size_t  n 
) [static]

utmp.c369 行で定義されています。

参照先 len.

参照元 sys_utmp_fill()sys_utmp_update().

00370 {
00371         size_t len = 0;
00372 
00373         memset(dest, '\0', n);
00374         if (src)
00375                 len = strlen(src);
00376         if (len >= n) {
00377                 memcpy(dest, src, n);
00378         } else {
00379                 if (len)
00380                         memcpy(dest, src, len);
00381         }
00382 }

static void sys_utmp_update ( struct utmp *  u,
const char *  hostname,
BOOL  claim 
) [static]

utmp.c388 行で定義されています。

参照先 utmp_nox_update()utmp_strcpy()uw_pathname()ux_pathnamewx_pathname.

00389 {
00390 #if !defined(HAVE_UTMPX_H)
00391         /* No utmpx stuff.  Drop to non-x stuff */
00392         utmp_nox_update(u, claim);
00393 #elif !defined(HAVE_PUTUTXLINE)
00394         /* Odd.  Have utmpx.h but no "pututxline()".  Drop to non-x stuff */
00395         DEBUG(1,("utmp_update: have utmpx.h but no pututxline() function\n"));
00396         utmp_nox_update(u, claim);
00397 #elif !defined(HAVE_GETUTMPX)
00398         /* Odd.  Have utmpx.h but no "getutmpx()".  Drop to non-x stuff */
00399         DEBUG(1,("utmp_update: have utmpx.h but no getutmpx() function\n"));
00400         utmp_nox_update(u, claim);
00401 #else
00402         pstring uname, wname;
00403         struct utmpx ux, *uxrc;
00404 
00405         getutmpx(u, &ux);
00406 
00407 #if defined(HAVE_UX_UT_SYSLEN)
00408         if (hostname)
00409                 ux.ut_syslen = strlen(hostname) + 1;    /* include end NULL */
00410         else
00411                 ux.ut_syslen = 0;
00412 #endif
00413 #if defined(HAVE_UT_UT_HOST)
00414         utmp_strcpy(ux.ut_host, hostname, sizeof(ux.ut_host));
00415 #endif
00416 
00417         uw_pathname(uname, "utmpx", ux_pathname);
00418         uw_pathname(wname, "wtmpx", wx_pathname);
00419         DEBUG(2,("utmp_update: uname:%s wname:%s\n", uname, wname));
00420         /*
00421          * Check for either uname or wname being empty.
00422          * Some systems, such as Redhat 6, have a "utmpx.h" which doesn't
00423          * define default filenames.
00424          * Also, our local installation has not provided an override.
00425          * Drop to non-x method.  (E.g. RH6 has good defaults in "utmp.h".)
00426          */
00427         if ((strlen(uname) == 0) || (strlen(wname) == 0)) {
00428                 utmp_nox_update(u, claim);
00429         } else {
00430                 utmpxname(uname);
00431                 setutxent();
00432                 uxrc = pututxline(&ux);
00433                 endutxent();
00434                 if (uxrc == NULL) {
00435                         DEBUG(2,("utmp_update: pututxline() failed\n"));
00436                         return;
00437                 }
00438                 updwtmpx(wname, &ux);
00439         }
00440 #endif /* HAVE_UTMPX_H */
00441 }

static int ut_id_encode ( int  i,
char *  fourbyte 
) [static]

utmp.c448 行で定義されています。

参照元 sys_utmp_fill().

00449 {
00450         int nbase;
00451         const char *ut_id_encstr = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
00452         
00453         fourbyte[0] = 'S';
00454         fourbyte[1] = 'M';
00455 
00456 /*
00457  * Encode remaining 2 bytes from 'i'.
00458  * 'ut_id_encstr' is the character set on which modulo arithmetic is done.
00459  * Example: digits would produce the base-10 numbers from '001'.
00460  */
00461         nbase = strlen(ut_id_encstr);
00462 
00463         fourbyte[3] = ut_id_encstr[i % nbase];
00464         i /= nbase;
00465         fourbyte[2] = ut_id_encstr[i % nbase];
00466         i /= nbase;
00467 
00468         return(i);      /* 0: good; else overflow */
00469 }

static BOOL sys_utmp_fill ( struct utmp *  u,
const char *  username,
const char *  hostname,
struct in_addr *  ipaddr,
const char *  id_str,
int  id_num 
) [static]

utmp.c476 行で定義されています。

参照先 GetTimeOfDay()sys_getpid()ut_id_encode()utmp_strcpy().

00480 {                         
00481         struct timeval timeval;
00482 
00483         /*
00484          * ut_name, ut_user:
00485          *      Several (all?) systems seems to define one as the other.
00486          *      It is easier and clearer simply to let the following take its course,
00487          *      rather than to try to detect and optimise.
00488          */
00489 #if defined(HAVE_UT_UT_USER)
00490         utmp_strcpy(u->ut_user, username, sizeof(u->ut_user));
00491 #elif defined(HAVE_UT_UT_NAME)
00492         utmp_strcpy(u->ut_name, username, sizeof(u->ut_name));
00493 #endif
00494 
00495         /*
00496          * ut_line:
00497          *      If size limit proves troublesome, then perhaps use "ut_id_encode()".
00498          */
00499         if (strlen(id_str) > sizeof(u->ut_line)) {
00500                 DEBUG(1,("id_str [%s] is too long for %lu char utmp field\n",
00501                          id_str, (unsigned long)sizeof(u->ut_line)));
00502                 return False;
00503         }
00504         utmp_strcpy(u->ut_line, id_str, sizeof(u->ut_line));
00505 
00506 #if defined(HAVE_UT_UT_PID)
00507         u->ut_pid = sys_getpid();
00508 #endif
00509 
00510 /*
00511  * ut_time, ut_tv: 
00512  *      Some have one, some the other.  Many have both, but defined (aliased).
00513  *      It is easier and clearer simply to let the following take its course.
00514  *      But note that we do the more precise ut_tv as the final assignment.
00515  */
00516 #if defined(HAVE_UT_UT_TIME)
00517         GetTimeOfDay(&timeval);
00518         u->ut_time = timeval.tv_sec;
00519 #elif defined(HAVE_UT_UT_TV)
00520         GetTimeOfDay(&timeval);
00521         u->ut_tv = timeval;
00522 #else
00523 #error "with-utmp must have UT_TIME or UT_TV"
00524 #endif
00525 
00526 #if defined(HAVE_UT_UT_HOST)
00527         utmp_strcpy(u->ut_host, hostname, sizeof(u->ut_host));
00528 #endif
00529 #if defined(HAVE_UT_UT_ADDR)
00530         if (ipaddr)
00531                 u->ut_addr = ipaddr->s_addr;
00532         /*
00533          * "(unsigned long) ut_addr" apparently exists on at least HP-UX 10.20.
00534          * Volunteer to implement, please ...
00535          */
00536 #endif
00537 
00538 #if defined(HAVE_UT_UT_ID)
00539         if (ut_id_encode(id_num, u->ut_id) != 0) {
00540                 DEBUG(1,("utmp_fill: cannot encode id %d\n", id_num));
00541                 return False;
00542         }
00543 #endif
00544 
00545         return True;
00546 }


変数

const char* ux_pathname [static]

初期値:

# if defined (UTMPX_FILE)
        UTMPX_FILE

utmp.c146 行で定義されています。

参照元 sys_utmp_update().

_UTMPX_FILE

utmp.c150 行で定義されています。

_PATH_UTMPX

utmp.c152 行で定義されています。

const char* wx_pathname [static]

初期値:

# if defined (WTMPX_FILE)
        WTMPX_FILE

utmp.c157 行で定義されています。

参照元 sys_utmp_update().

_WTMPX_FILE

utmp.c161 行で定義されています。

_PATH_WTMPX

utmp.c163 行で定義されています。

const char* ut_pathname [static]

初期値:

# if defined (UTMP_FILE)
        UTMP_FILE

utmp.c170 行で定義されています。

参照元 utmp_nox_update().

_UTMP_FILE

utmp.c174 行で定義されています。

_PATH_UTMP

utmp.c176 行で定義されています。

const char* wt_pathname [static]

初期値:

# if defined (WTMP_FILE)
        WTMP_FILE

utmp.c181 行で定義されています。

参照元 utmp_nox_update().

_WTMP_FILE

utmp.c185 行で定義されています。

_PATH_WTMP

utmp.c187 行で定義されています。

const char* ll_pathname [static]

初期値:

# if defined (_PATH_LASTLOG)    
        _PATH_LASTLOG

utmp.c195 行で定義されています。


Sambaに対してSat Aug 29 21:24:30 2009に生成されました。  doxygen 1.4.7