g_thread_sck set outside of lock fix and g_cfg should always be a pointer to a struct

ulab-original
jsorg71 15 years ago
parent a673a075bd
commit 328649af9b

@ -27,7 +27,7 @@
#include "sesman.h" #include "sesman.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
int DEFAULT_CC int DEFAULT_CC

@ -30,7 +30,7 @@
#include "file.h" #include "file.h"
#include "sesman.h" #include "sesman.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
/** /**

@ -31,7 +31,7 @@
#include "grp.h" #include "grp.h"
extern unsigned char g_fixedkey[8]; /* in sesman.c */ extern unsigned char g_fixedkey[8]; /* in sesman.c */
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
int DEFAULT_CC int DEFAULT_CC

@ -23,7 +23,7 @@
#include "sesman.h" #include "sesman.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
static tbus g_sync_mutex = 0; static tbus g_sync_mutex = 0;
static tbus g_lock_chain = 0; static tbus g_lock_chain = 0;

@ -31,7 +31,7 @@
#include "sesman.h" #include "sesman.h"
extern int g_thread_sck; /* in thread.c */ extern int g_thread_sck; /* in thread.c */
extern struct config_sesman g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
void* DEFAULT_CC void* DEFAULT_CC
@ -43,7 +43,7 @@ scp_process_start(void* sck)
/* making a local copy of the socket (it's on the stack) */ /* making a local copy of the socket (it's on the stack) */
/* probably this is just paranoia */ /* probably this is just paranoia */
scon.in_sck = g_thread_sck; scon.in_sck = g_thread_sck;
LOG_DBG(&(g_cfg.log), "started scp thread on socket %d", scon.in_sck); LOG_DBG(&(g_cfg->log), "started scp thread on socket %d", scon.in_sck);
/* unlocking g_thread_sck */ /* unlocking g_thread_sck */
lock_socket_release(); lock_socket_release();
@ -60,40 +60,40 @@ scp_process_start(void* sck)
if (sdata->version == 0) if (sdata->version == 0)
{ {
/* starts processing an scp v0 connection */ /* starts processing an scp v0 connection */
LOG_DBG(&(g_cfg.log), "accept ok, go on with scp v0\n",0); LOG_DBG(&(g_cfg->log), "accept ok, go on with scp v0\n",0);
scp_v0_process(&scon, sdata); scp_v0_process(&scon, sdata);
} }
else else
{ {
LOG_DBG(&(g_cfg.log), "accept ok, go on with scp v1\n",0); LOG_DBG(&(g_cfg->log), "accept ok, go on with scp v1\n",0);
/*LOG_DBG(&(g_cfg.log), "user: %s\npass: %s",sdata->username, sdata->password);*/ /*LOG_DBG(&(g_cfg->log), "user: %s\npass: %s",sdata->username, sdata->password);*/
scp_v1_process(&scon, sdata); scp_v1_process(&scon, sdata);
} }
break; break;
case SCP_SERVER_STATE_START_MANAGE: case SCP_SERVER_STATE_START_MANAGE:
/* starting a management session */ /* starting a management session */
log_message(&(g_cfg.log), LOG_LEVEL_WARNING, log_message(&(g_cfg->log), LOG_LEVEL_WARNING,
"starting a sesman management session..."); "starting a sesman management session...");
scp_v1_mng_process(&scon, sdata); scp_v1_mng_process(&scon, sdata);
break; break;
case SCP_SERVER_STATE_VERSION_ERR: case SCP_SERVER_STATE_VERSION_ERR:
/* an unknown scp version was requested, so we shut down the */ /* an unknown scp version was requested, so we shut down the */
/* connection (and log the fact) */ /* connection (and log the fact) */
log_message(&(g_cfg.log), LOG_LEVEL_WARNING, log_message(&(g_cfg->log), LOG_LEVEL_WARNING,
"unknown protocol version specified. connection refused."); "unknown protocol version specified. connection refused.");
break; break;
case SCP_SERVER_STATE_NETWORK_ERR: case SCP_SERVER_STATE_NETWORK_ERR:
log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp network error."); log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "libscp network error.");
break; break;
case SCP_SERVER_STATE_SEQUENCE_ERR: case SCP_SERVER_STATE_SEQUENCE_ERR:
log_message(&(g_cfg.log), LOG_LEVEL_WARNING, "libscp sequence error."); log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "libscp sequence error.");
break; break;
case SCP_SERVER_STATE_INTERNAL_ERR: case SCP_SERVER_STATE_INTERNAL_ERR:
/* internal error occurred (eg. malloc() error, ecc.) */ /* internal error occurred (eg. malloc() error, ecc.) */
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "libscp internal error occurred."); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "libscp internal error occurred.");
break; break;
default: default:
log_message(&(g_cfg.log), LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()"); log_message(&(g_cfg->log), LOG_LEVEL_ALWAYS, "unknown return from scp_vXs_accept()");
} }
g_tcp_close(scon.in_sck); g_tcp_close(scon.in_sck);
free_stream(scon.in_s); free_stream(scon.in_s);

@ -27,7 +27,7 @@
#include "sesman.h" #include "sesman.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
/******************************************************************************/ /******************************************************************************/
void DEFAULT_CC void DEFAULT_CC

@ -30,7 +30,7 @@
//#include "libscp_types.h" //#include "libscp_types.h"
#include "libscp.h" #include "libscp.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
static void parseCommonStates(enum SCP_SERVER_STATES_E e, char* f); static void parseCommonStates(enum SCP_SERVER_STATES_E e, char* f);

@ -29,7 +29,7 @@
#include "libscp.h" #include "libscp.h"
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
static void parseCommonStates(enum SCP_SERVER_STATES_E e, char* f); static void parseCommonStates(enum SCP_SERVER_STATES_E e, char* f);

@ -30,7 +30,7 @@
int g_sck; int g_sck;
int g_pid; int g_pid;
unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 }; unsigned char g_fixedkey[8] = { 23, 82, 107, 6, 35, 78, 88, 7 };
struct config_sesman* g_cfg; /* config.h */ struct config_sesman* g_cfg; /* defined in config.h */
tbus g_term_event = 0; tbus g_term_event = 0;
tbus g_sync_event = 0; tbus g_sync_event = 0;
@ -104,7 +104,6 @@ sesman_main_loop(void)
{ {
/* we've got a connection, so we pass it to scp code */ /* we've got a connection, so we pass it to scp code */
LOG_DBG(&(g_cfg->log), "new connection"); LOG_DBG(&(g_cfg->log), "new connection");
g_thread_sck = in_sck;
thread_scp_start(in_sck); thread_scp_start(in_sck);
/* todo, do we have to wait here ? */ /* todo, do we have to wait here ? */
} }

@ -33,7 +33,7 @@
extern tbus g_sync_event; extern tbus g_sync_event;
extern unsigned char g_fixedkey[8]; extern unsigned char g_fixedkey[8];
extern struct config_sesman* g_cfg; /* config.h */ extern struct config_sesman* g_cfg; /* in sesman.c */
struct session_chain* g_sessions; struct session_chain* g_sessions;
int g_session_count; int g_session_count;

@ -31,7 +31,7 @@
extern int g_sck; extern int g_sck;
extern int g_pid; extern int g_pid;
extern struct config_sesman* g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
extern tbus g_term_event; extern tbus g_term_event;
/******************************************************************************/ /******************************************************************************/

@ -31,7 +31,7 @@
#include <signal.h> #include <signal.h>
#include <pthread.h> #include <pthread.h>
extern struct config_sesman g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
static pthread_t g_thread_sighandler; static pthread_t g_thread_sighandler;
//static pthread_t g_thread_updater; //static pthread_t g_thread_updater;
@ -62,14 +62,14 @@ thread_sighandler_start(void)
sigaddset(&waitmask, SIGFPE); sigaddset(&waitmask, SIGFPE);
pthread_sigmask(SIG_UNBLOCK, &waitmask, NULL); pthread_sigmask(SIG_UNBLOCK, &waitmask, NULL);
log_message(&(g_cfg.log), LOG_LEVEL_INFO,"starting signal handling thread..."); log_message(&(g_cfg->log), LOG_LEVEL_INFO,"starting signal handling thread...");
ret = pthread_create(&g_thread_sighandler, NULL, sig_handler_thread, ""); ret = pthread_create(&g_thread_sighandler, NULL, sig_handler_thread, "");
pthread_detach(g_thread_sighandler); pthread_detach(g_thread_sighandler);
if (ret == 0) if (ret == 0)
{ {
log_message(&(g_cfg.log), LOG_LEVEL_INFO, "signal handler thread started successfully"); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "signal handler thread started successfully");
return 0; return 0;
} }
@ -77,16 +77,16 @@ thread_sighandler_start(void)
switch (ret) switch (ret)
{ {
case EINVAL: case EINVAL:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for signal handling thread (creation returned EINVAL)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid attributes for signal handling thread (creation returned EINVAL)");
break; break;
case EAGAIN: case EAGAIN:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start signal handling thread (creation returned EAGAIN)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "not enough resources to start signal handling thread (creation returned EAGAIN)");
break; break;
case EPERM: case EPERM:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for signal handling thread (creation returned EPERM)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid permissions for signal handling thread (creation returned EPERM)");
break; break;
default: default:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting signal handling thread"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "unknown error starting signal handling thread");
} }
return 1; return 1;
@ -108,7 +108,7 @@ thread_session_update_start(void)
if (ret==0) if (ret==0)
{ {
log_message(&(g_cfg.log), LOG_LEVEL_INFO, "session update thread started successfully"); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "session update thread started successfully");
return 0; return 0;
} }
@ -116,16 +116,16 @@ thread_session_update_start(void)
switch (ret) switch (ret)
{ {
case EINVAL: case EINVAL:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for session update thread (creation returned EINVAL)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid attributes for session update thread (creation returned EINVAL)");
break; break;
case EAGAIN: case EAGAIN:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start session update thread (creation returned EAGAIN)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "not enough resources to start session update thread (creation returned EAGAIN)");
break; break;
case EPERM: case EPERM:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for session update thread (creation returned EPERM)"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid permissions for session update thread (creation returned EPERM)");
break; break;
default: default:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting session update thread"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "unknown error starting session update thread");
} }
return 1; return 1;
@ -150,7 +150,7 @@ thread_scp_start(int skt)
if (ret == 0) if (ret == 0)
{ {
log_message(&(g_cfg.log), LOG_LEVEL_INFO, "scp thread on sck %d started successfully", skt); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "scp thread on sck %d started successfully", skt);
return 0; return 0;
} }
@ -158,16 +158,16 @@ thread_scp_start(int skt)
switch (ret) switch (ret)
{ {
case EINVAL: case EINVAL:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid attributes for scp thread on sck %d (creation returned EINVAL)", skt); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid attributes for scp thread on sck %d (creation returned EINVAL)", skt);
break; break;
case EAGAIN: case EAGAIN:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "not enough resources to start scp thread on sck %d (creation returned EAGAIN)", skt); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "not enough resources to start scp thread on sck %d (creation returned EAGAIN)", skt);
break; break;
case EPERM: case EPERM:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "invalid permissions for scp thread on sck %d (creation returned EPERM)", skt); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "invalid permissions for scp thread on sck %d (creation returned EPERM)", skt);
break; break;
default: default:
log_message(&(g_cfg.log), LOG_LEVEL_ERROR, "unknown error starting scp thread on sck %d"); log_message(&(g_cfg->log), LOG_LEVEL_ERROR, "unknown error starting scp thread on sck %d");
} }
return 1; return 1;

@ -38,7 +38,7 @@
#define SECS_PER_DAY (24L*3600L) #define SECS_PER_DAY (24L*3600L)
#endif #endif
extern struct config_sesman g_cfg; extern struct config_sesman* g_cfg; /* in sesman.c */
static int DEFAULT_CC static int DEFAULT_CC
auth_crypt_pwd(char* pwd, char* pln, char* crp); auth_crypt_pwd(char* pwd, char* pln, char* crp);
@ -73,7 +73,7 @@ auth_userpass(char* user, char* pass)
} }
if (1==auth_account_disabled(stp)) if (1==auth_account_disabled(stp))
{ {
log_message(&(g_cfg.log), LOG_LEVEL_INFO, "account %s is disabled", user); log_message(&(g_cfg->log), LOG_LEVEL_INFO, "account %s is disabled", user);
return 0; return 0;
} }
g_strncpy(hash, stp->sp_pwdp, 34); g_strncpy(hash, stp->sp_pwdp, 34);
@ -310,13 +310,13 @@ auth_account_disabled(struct spwd* stp)
today=g_time1()/SECS_PER_DAY; today=g_time1()/SECS_PER_DAY;
LOG_DBG(&(g_cfg.log), "last %d",stp->sp_lstchg); LOG_DBG(&(g_cfg->log), "last %d",stp->sp_lstchg);
LOG_DBG(&(g_cfg.log), "min %d",stp->sp_min); LOG_DBG(&(g_cfg->log), "min %d",stp->sp_min);
LOG_DBG(&(g_cfg.log), "max %d",stp->sp_max); LOG_DBG(&(g_cfg->log), "max %d",stp->sp_max);
LOG_DBG(&(g_cfg.log), "inact %d",stp->sp_inact); LOG_DBG(&(g_cfg->log), "inact %d",stp->sp_inact);
LOG_DBG(&(g_cfg.log), "warn %d",stp->sp_warn); LOG_DBG(&(g_cfg->log), "warn %d",stp->sp_warn);
LOG_DBG(&(g_cfg.log), "expire %d",stp->sp_expire); LOG_DBG(&(g_cfg->log), "expire %d",stp->sp_expire);
LOG_DBG(&(g_cfg.log), "today %d",today); LOG_DBG(&(g_cfg->log), "today %d",today);
if ((stp->sp_expire != -1) && (today >= stp->sp_expire)) if ((stp->sp_expire != -1) && (today >= stp->sp_expire))
{ {

Loading…
Cancel
Save