Example #1
0
char* FAST_FUNC uid2uname_utoa(uid_t uid)
{
	char *name = uid2uname(uid);
	return (name) ? name : utoa(uid);
}
Example #2
0
File: id.c Project: nawawi/busybox
static int print_user(uid_t id, const char *prefix)
{
	return print_common(id, uid2uname(id), prefix);
}
Example #3
0
void
svas_layer_init::initialize() 
{
	// for error messages
	char b[200];
	ostrstream msg(b, sizeof(b));

	// Initialize the error codes
	if (! (w_error_t::insert(
		"SVAS",
		svas_error_info, SVAS_ERRMAX - SVAS_ERRMIN + 1))) {
		catastrophic("Cannot initalize SVAS error codes.");
	}

	if (! (w_error_t::insert(
		"SVAS",	 // Unix compatibility service
		os_error_info, OS_ERRMAX - OS_ERRMIN + 1))) {
		catastrophic("Cannot initalize OS error codes.");
	}

	///////////////////////////////////////////////////
	// Create the log so that we can use it for
	// error reporting in the rest of this...
	///////////////////////////////////////////////////
	{
		const char *slf = ShoreVasLayer.opt_log? ShoreVasLayer.opt_log->value():0;
		ShoreVasLayer.log = new 
			ErrLog("shore", log_to_unix_file, (void *)slf);

		if(! ShoreVasLayer.log) {
			w_rc_t tmp_rc = RC(errno);
			catastrophic("Cannot open log file.", tmp_rc);
		}
		ShoreVasLayer.log->setloglevel(_loglevel);
	}
	//////////////////////////////////////////////////////////
	// ShoreVasLayer.log->clog is now a usable ostream-style log
	//////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////
	// Configuration options:
	// "production" mode -- you must have an account
	//     for the shore database administrator, called "shoreadm",
	//     or whatever is defined for SHORE_ADM
	//     If configured thus, it's an error to run the server
	// 	   as any other user.
	//     shoreadm needs r/w perms on log and volumes 
	//
	// "experimental" mode --
	// 	   anyone can run the server, as long as the user has
	//	   r/w perms on the log and volumes
	//     For the duration of a server process, the Shore 
	// 	   database administrator is the user under which the
	//     server is run, thus the privilege goes with the
	//     user running the server.  This could give unexpected
	//     results because a user might sometimes be able to 
	//     do privileged operations, sometimes not, depending
	//     on who's running the server.
	//
	//////////////////////////////////////////////////////////////

	ShoreUid = getuid();
	DBG(<<"ShoreUid=" << ShoreUid);
	ShoreGid = getgid();
	DBG(<<"ShoreGid=" << ShoreGid);

#ifdef SHOREADM
	bool shoreadm_required = true;
#else
	bool shoreadm_required = false;
#define SHOREADM "shoreadm"
#endif

	{
		char 				*uname = NULL;
		int					usernamelen=0;

		if((uname = uid2uname(getuid()))==NULL) {
			perror("uid2uname");
			catastrophic("Cannot initialize ShoreVasLayer.");
		}
		usernamelen = strlen(uname);
		ShoreUser = new char [usernamelen+1];
		if(!ShoreUser) {
			catastrophic("Malloc failure: Cannot initialize ShoreVasLayer.");
		}
		strcpy(ShoreUser, uname);
		dassert(ShoreUser != 0);
	}
	if(strcmp(ShoreUser,SHOREADM)!=0) {
		if(shoreadm_required) {
			catastrophic(
			"This server can be run only by the shore administrator." ); 
		} else {
			msg << "Warning: no database administrator -- "
			<< "running under userid "
			<< ShoreUid << ", groupid " << ShoreGid << ends;

			logmessage(msg.str());
		}
	}
	DBG(<<"ShoreUser="******"getrlimit(z)");\
		}\
		q = buf.rlim_cur;\
		if( q < buf.rlim_max ) {\
			msg << "Warning: " << #z << \
			"(" << q << ") is less than hard limit (" \
			<< buf.rlim_max << ")" << ends;\
			logmessage(msg.str()); \
		}\
	}

	/********* OpenMax ***************************************/

#		if defined(_SC_OPEN_MAX)
		OpenMax = (int) sysconf(_SC_OPEN_MAX);
#		elif defined(RLIMIT_NOFILE)
		GETRLIMIT(RLIMIT_NOFILE, OpenMax);
#		else  
		OpenMax = getdtablesize();
#		endif
#		ifdef notdef
			// could also try:
#			if defined(NOFILE)
			OpenMax = NOFILE;
#			endif
#		endif
		DBG(<<"OpenMax=" << OpenMax);

	/********* FileSizeMax ***************************************/
#		if defined(RLIMIT_FSIZE)
		GETRLIMIT(RLIMIT_FSIZE, FileSizeMax);
#		else
		FileSizeMax = 0x3ffffff; // TODO something more reasonable
#		endif

	/********* LinksMax ***************************************/
#		ifdef _PC_LINK_MAX
		LinksMax = (int)  pathconf("/",_PC_LINK_MAX);
#		elif defined(MAXLINK)
		LinksMax =  MAXLINK;
#		endif
		DBG(<<"LinksMax=" << LinksMax);

	/********* SymlinksMax ***************************************/
#		ifdef  MAXSYMLINKS
		SymlinksMax = MAXSYMLINKS; // max to be expanded in a single namei
#		else
		SymlinksMax = 20; // something's better than nothing
#		endif

		DBG(<<"SymlinksMax = " << SymlinksMax);

	/********* PathMax ***************************************/
#		if defined(_PC_PATH_MAX)
		PathMax = (int)  pathconf("/",_PC_PATH_MAX);
#		elif defined(MAXPATHLEN)
		PathMax = MAXPATHLEN; // max after expanding symlinks
#		else
		PathMax = 1024; 
#		endif
		DBG(<<"PathMax=" << PathMax);

	/********* NameMax ***************************************/
#		if defined(_PC_NAME_MAX)
		NameMax = (int)  pathconf("/",_PC_NAME_MAX);
#		else
		NameMax = (int)  255; // better than nothing
#		endif
		DBG(<<"NameMax=" << NameMax);
	}
}