⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utmp.c

📁 samba-3.0.22.tar.gz 编译smb服务器的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    Unix SMB/CIFS implementation.   utmp routines   Copyright (C) T.D.Lee@durham.ac.uk 1999   Heavily modified by Andrew Bartlett and Tridge, April 2001      This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 2 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.*/#include "includes.h"/****************************************************************************Reflect connection status in utmp/wtmp files.	T.D.Lee@durham.ac.uk  September 1999	With grateful thanks since then to many who have helped port it to	different operating systems.  The variety of OS quirks thereby	uncovered is amazing...Hints for porting:	o  Always attempt to use programmatic interface (pututline() etc.)	   Indeed, at present only programmatic use is supported.	o  The only currently supported programmatic interface to "wtmp{,x}"	   is through "updwtmp*()" routines.	o  The "x" (utmpx/wtmpx; HAVE_UTMPX_H) seems preferable.	o  The HAVE_* items should identify supported features.	o  If at all possible, avoid "if defined(MY-OS)" constructions.OS observations and status:	Almost every OS seems to have its own quirks.	Solaris 2.x:		Tested on 2.6 and 2.7; should be OK on other flavours.	AIX:		Apparently has utmpx.h but doesn't implement.	OSF:		Has utmpx.h, but (e.g.) no "getutmpx()".  (Is this like AIX ?)	Redhat 6:		utmpx.h seems not to set default filenames.  non-x better.	IRIX 6.5:		Not tested.  Appears to have "x".	HP-UX 9.x:		Not tested.  Appears to lack "x".	HP-UX 10.x:		Not tested.		"updwtmp*()" routines seem absent, so no current wtmp* support.		Has "ut_addr": probably trivial to implement (although remember		that IPv6 is coming...).	FreeBSD:		No "putut*()" type of interface.		No "ut_type" and associated defines. 		Write files directly.  Alternatively use its login(3)/logout(3).	SunOS 4:		Not tested.  Resembles FreeBSD, but no login()/logout().lastlog:	Should "lastlog" files, if any, be updated?	BSD systems (SunOS 4, FreeBSD):		o  Prominent mention on man pages.	System-V (e.g. Solaris 2):		o  No mention on man pages, even under "man -k".		o  Has a "/var/adm/lastlog" file, but pututxline() etc. seem		   not to touch it.		o  Despite downplaying (above), nevertheless has <lastlog.h>.	So perhaps UN*X "lastlog" facility is intended for tty/terminal only?Notes:	Each connection requires a small number (starting at 0, working up)	to represent the line.  This must be unique within and across all	smbd processes.  It is the 'id_num' from Samba's session.c code.	The 4 byte 'ut_id' component is vital to distinguish connections,	of which there could be several hundred or even thousand.	Entries seem to be printable characters, with optional NULL pads.	We need to be distinct from other entries in utmp/wtmp.	Observed things: therefore avoid them.  Add to this list please.	From Solaris 2.x (because that's what I have):		'sN'	: run-levels; N: [0-9]		'co'	: console		'CC'	: arbitrary things;  C: [a-z]		'rXNN'	: rlogin;  N: [0-9]; X: [0-9a-z]		'tXNN'	: rlogin;  N: [0-9]; X: [0-9a-z]		'/NNN'	: Solaris CDE		'ftpZ'	: ftp (Z is the number 255, aka 0377, aka 0xff)	Mostly a record uses the same 'ut_id' in both "utmp" and "wtmp",	but differences have been seen.	Arbitrarily I have chosen to use a distinctive 'SM' for the	first two bytes.	The remaining two bytes encode the session 'id_num' (see above).	Our caller (session.c) should note our 16-bit limitation.****************************************************************************/#ifndef WITH_UTMP/* * Not WITH_UTMP?  Simply supply dummy routines. */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){}#else /* WITH_UTMP */#include <utmp.h>#ifdef HAVE_UTMPX_H#include <utmpx.h>#endif/* BSD systems: some may need lastlog.h (SunOS 4), some may not (FreeBSD) *//* Some System-V systems (e.g. Solaris 2) declare this too. */#ifdef HAVE_LASTLOG_H#include <lastlog.h>#endif/**************************************************************************** Default paths to various {u,w}tmp{,x} files.****************************************************************************/#ifdef	HAVE_UTMPX_Hstatic const char *ux_pathname =# if defined (UTMPX_FILE)	UTMPX_FILE ;# elif defined (_UTMPX_FILE)	_UTMPX_FILE ;# elif defined (_PATH_UTMPX)	_PATH_UTMPX ;# else	"" ;# endifstatic const char *wx_pathname =# if defined (WTMPX_FILE)	WTMPX_FILE ;# elif defined (_WTMPX_FILE)	_WTMPX_FILE ;# elif defined (_PATH_WTMPX)	_PATH_WTMPX ;# else	"" ;# endif#endif	/* HAVE_UTMPX_H */static const char *ut_pathname =# if defined (UTMP_FILE)	UTMP_FILE ;# elif defined (_UTMP_FILE)	_UTMP_FILE ;# elif defined (_PATH_UTMP)	_PATH_UTMP ;# else	"" ;# endifstatic const char *wt_pathname =# if defined (WTMP_FILE)	WTMP_FILE ;# elif defined (_WTMP_FILE)	_WTMP_FILE ;# elif defined (_PATH_WTMP)	_PATH_WTMP ;# else	"" ;# endif/* BSD-like systems might want "lastlog" support. *//* *** Not yet implemented */#ifndef HAVE_PUTUTLINE		/* see "pututline_my()" */static const char *ll_pathname =# if defined (_PATH_LASTLOG)	/* what other names (if any?) */	_PATH_LASTLOG ;# else	"" ;# endif	/* _PATH_LASTLOG */#endif	/* HAVE_PUTUTLINE *//* * Get name of {u,w}tmp{,x} file. *	return: fname contains filename *		Possibly empty if this code not yet ported to this system. * * utmp{,x}:  try "utmp dir", then default (a define) * wtmp{,x}:  try "wtmp dir", then "utmp dir", then default (a define) */static void uw_pathname(pstring fname, const char *uw_name, const char *uw_default){	pstring dirname;	pstrcpy(dirname, "");	/* For w-files, first look for explicit "wtmp dir" */	if (uw_name[0] == 'w') {		pstrcpy(dirname,lp_wtmpdir());		trim_char(dirname,'\0','/');	}	/* For u-files and non-explicit w-dir, look for "utmp dir" */	if (dirname == 0 || strlen(dirname) == 0) {		pstrcpy(dirname,lp_utmpdir());		trim_char(dirname,'\0','/');	}	/* If explicit directory above, use it */	if (dirname != 0 && strlen(dirname) != 0) {		pstrcpy(fname, dirname);		pstrcat(fname, "/");		pstrcat(fname, uw_name);		return;	}	/* No explicit directory: attempt to use default paths */	if (strlen(uw_default) == 0) {		/* No explicit setting, no known default.		 * Has it yet been ported to this OS?		 */		DEBUG(2,("uw_pathname: unable to determine pathname\n"));	}	pstrcpy(fname, uw_default);}#ifndef HAVE_PUTUTLINE/**************************************************************************** Update utmp file directly.  No subroutine interface: probably a BSD system.****************************************************************************/static void pututline_my(pstring uname, struct utmp *u, BOOL claim){	DEBUG(1,("pututline_my: not yet implemented\n"));	/* BSD implementor: may want to consider (or not) adjusting "lastlog" */}#endif /* HAVE_PUTUTLINE */#ifndef HAVE_UPDWTMP/**************************************************************************** Update wtmp file directly.  No subroutine interface: probably a BSD system. Credit: Michail Vidiassov <master@iaas.msu.ru>****************************************************************************/static void updwtmp_my(pstring wname, struct utmp *u, BOOL claim){	int fd;	struct stat buf;	if (! claim) {		/*	 	 * BSD-like systems:		 *	may use empty ut_name to distinguish a logout record.		 *		 * May need "if defined(SUNOS4)" etc. around some of these,		 * but try to avoid if possible.		 *		 * SunOS 4:		 *	man page indicates ut_name and ut_host both NULL		 * FreeBSD 4.0:		 *	man page appears not to specify (hints non-NULL)		 *	A correspondent suggest at least ut_name should be NULL		 */#if defined(HAVE_UT_UT_NAME)		memset((char *)&u->ut_name, '\0', sizeof(u->ut_name));#endif#if defined(HAVE_UT_UT_HOST)		memset((char *)&u->ut_host, '\0', sizeof(u->ut_host));#endif	}	/* Stolen from logwtmp function in libutil.	 * May be more locking/blocking is needed?	 */	if ((fd = open(wname, O_WRONLY|O_APPEND, 0)) < 0)		return;	if (fstat(fd, &buf) == 0) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -