<commit_before>/***************************************************************
 *
 * Copyright (C) 1990-2011, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You may
 * obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************/


#include "condor_common.h"
#include "condor_debug.h"
#include "condor_syscall_mode.h"
#include "condor_uid.h"
#include "condor_config.h"
#include "condor_environ.h"
#include "condor_distribution.h"
#include "my_username.h"
#include "daemon.h"
#include "store_cred.h"

/* See condor_uid.h for description. */
static char* CondorUserName = NULL;
static char* RealUserName = NULL;
static int SwitchIds = TRUE;
static int UserIdsInited = FALSE;
static int OwnerIdsInited = FALSE;
#ifdef WIN32
// set this to false to base the result of can_switch_ids() on token privs rather than account name.
static bool only_SYSTEM_can_switch_ids = true;
#endif
/*
   On Unix, the current uid is process wide.  On Win32, it is specific to each
   thread.  So on Win32 only, priv_state is TLS.
*/
#ifdef WIN32
THREAD_LOCAL_STORAGE static priv_state CurrentPrivState = PRIV_UNKNOWN;
#else
static priv_state CurrentPrivState = PRIV_UNKNOWN;
#endif

priv_state
get_priv_state(void)
{
	return CurrentPrivState;
}

#if !defined(WIN32)
/*
   supplementary group used to track process families. if nonzero,
   this group id will be inserted into the group list when we switch
   into USER_PRIV_FINAL
*/
static gid_t TrackingGid = 0;
#endif

/* must be listed in the same order as enum priv_state in condor_uid.h */
static const char *priv_state_name[] = {
	"PRIV_UNKNOWN",
	"PRIV_ROOT",
	"PRIV_CONDOR",
	"PRIV_CONDOR_FINAL",
	"PRIV_USER",
	"PRIV_USER_FINAL",
	"PRIV_FILE_OWNER"
};


/* Start Common Bits */
#define HISTORY_LENGTH 32

static struct {
	time_t		timestamp;
	priv_state	priv;
	const char	*file;
	int			line;
} priv_history[HISTORY_LENGTH];
static int ph_head=0, ph_count=0;

const char*
priv_to_string( priv_state p )
{
	if( p < _priv_state_threshold ) {
		return priv_state_name[p];
	}
	return "PRIV_INVALID";
}

void
log_priv(priv_state prev, priv_state new_priv, const char *file, int line)
{
	dprintf(D_PRIV, "%s --> %s at %s:%d\n",	priv_state_name[prev],
			priv_state_name[new_priv], file, line);
	priv_history[ph_head].timestamp = time(NULL);
	priv_history[ph_head].priv = new_priv;
	priv_history[ph_head].file = file; /* should be a constant - no alloc */
	priv_history[ph_head].line = line;<commit_msg>Shrink space used by priv-switching history. #4206<commit_after>/***************************************************************
 *
 * Copyright (C) 1990-2011, Condor Team, Computer Sciences Department,
 * University of Wisconsin-Madison, WI.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you
 * may not use this file except in compliance with the License.  You may
 * obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ***************************************************************/


#include "condor_common.h"
#include "condor_debug.h"
#include "condor_syscall_mode.h"
#include "condor_uid.h"
#include "condor_config.h"
#include "condor_environ.h"
#include "condor_distribution.h"
#include "my_username.h"
#include "daemon.h"
#include "store_cred.h"

/* See condor_uid.h for description. */
static char* CondorUserName = NULL;
static char* RealUserName = NULL;
static int SwitchIds = TRUE;
static int UserIdsInited = FALSE;
static int OwnerIdsInited = FALSE;
#ifdef WIN32
// set this to false to base the result of can_switch_ids() on token privs rather than account name.
static bool only_SYSTEM_can_switch_ids = true;
#endif
/*
   On Unix, the current uid is process wide.  On Win32, it is specific to each
   thread.  So on Win32 only, priv_state is TLS.
*/
#ifdef WIN32
THREAD_LOCAL_STORAGE static priv_state CurrentPrivState = PRIV_UNKNOWN;
#else
static priv_state CurrentPrivState = PRIV_UNKNOWN;
#endif

priv_state
get_priv_state(void)
{
	return CurrentPrivState;
}

#if !defined(WIN32)
/*
   supplementary group used to track process families. if nonzero,
   this group id will be inserted into the group list when we switch
   into USER_PRIV_FINAL
*/
static gid_t TrackingGid = 0;
#endif

/* must be listed in the same order as enum priv_state in condor_uid.h */
static const char *priv_state_name[] = {
	"PRIV_UNKNOWN",
	"PRIV_ROOT",
	"PRIV_CONDOR",
	"PRIV_CONDOR_FINAL",
	"PRIV_USER",
	"PRIV_USER_FINAL",
	"PRIV_FILE_OWNER"
};


/* Start Common Bits */
#define HISTORY_LENGTH 16

static struct {
	time_t		timestamp;
	priv_state	priv;
	int			line;
	const char	*file;
} priv_history[HISTORY_LENGTH];
static int ph_head=0, ph_count=0;

const char*
priv_to_string( priv_state p )
{
	if( p < _priv_state_threshold ) {
		return priv_state_name[p];
	}
	return "PRIV_INVALID";
}

void
log_priv(priv_state prev, priv_state new_priv, const char *file, int line)
{
	dprintf(D_PRIV, "%s --> %s at %s:%d\n",	priv_state_name[prev],
			priv_state_name[new_priv], file, line);
	priv_history[ph_head].timestamp = time(NULL);
	priv_history[ph_head].priv = new_priv;
	priv_history[ph_head].file = file; /* should be a constant - no alloc */
	priv_history[ph_head].line = line;
{'fraction_non_alphanumeric': 0.1339799441065264, 'fraction_numerical': 0.009534769028439914, 'mean_word_length': 4.844380403458214, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3483909', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1981, 'n_words': 645}