Commit 8cb3bd41 authored by reggie@fedora.(none)'s avatar reggie@fedora.(none)

alot of formatting changes that came out of JimW's review

parent f3de5d6b
......@@ -25,8 +25,7 @@ void IMService::Run()
ReportStatus((DWORD)SERVICE_START_PENDING);
// init goes here
ReportStatus((DWORD)SERVICE_RUNNING);
ReportStatus((DWORD)SERVICE_RUNNING);
// wait for main loop to terminate
}
......@@ -38,7 +37,7 @@ void IMService::Log(const char *msg)
int HandleServiceOptions(Options options)
{
int ret_val = 0;
int ret_val= 0;
IMService winService;
......@@ -47,23 +46,23 @@ int HandleServiceOptions(Options options)
if (winService.IsInstalled())
log_info("Service is already installed\n");
else if (winService.Install())
log_info("Service installed successfully\n");
log_info("Service installed successfully\n");
else
{
log_info("Service failed to install\n");
ret_val = -1;
log_info("Service failed to install\n");
ret_val= -1;
}
}
else if (options.remove_service)
{
if (! winService.IsInstalled())
log_info("Service is not installed\n");
else if (winService.Remove())
log_info("Service removed successfully\n");
else if (winService.Remove())
log_info("Service removed successfully\n");
else
{
log_info("Service failed to remove\n");
ret_val = -1;
log_info("Service failed to remove\n");
ret_val= -1;
}
}
else
......
......@@ -4,13 +4,15 @@
static WindowsService *gService;
WindowsService::WindowsService(void)
: statusCheckpoint(0), serviceName(NULL), inited(false),
WindowsService::WindowsService(void) :
statusCheckpoint(0),
serviceName(NULL),
inited(false),
dwAcceptedControls(SERVICE_ACCEPT_STOP)
{
gService = this;
status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
status.dwServiceSpecificExitCode = 0;
gService= this;
status.dwServiceType= SERVICE_WIN32_OWN_PROCESS;
status.dwServiceSpecificExitCode= 0;
}
WindowsService::~WindowsService(void)
......@@ -19,83 +21,84 @@ WindowsService::~WindowsService(void)
BOOL WindowsService::Install()
{
bool ret_val=false;
SC_HANDLE newService;
SC_HANDLE scm;
bool ret_val= false;
SC_HANDLE newService;
SC_HANDLE scm;
if (IsInstalled()) return true;
if (IsInstalled()) return true;
// determine the name of the currently executing file
char szFilePath[_MAX_PATH];
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
// determine the name of the currently executing file
char szFilePath[_MAX_PATH];
GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
// open a connection to the SCM
if (!(scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
return false;
// open a connection to the SCM
if (!(scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE)))
return false;
newService = CreateService(scm, serviceName, displayName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START,
SERVICE_ERROR_NORMAL, szFilePath,
NULL, NULL, NULL, username, password);
newService= CreateService(scm, serviceName, displayName,
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
szFilePath, NULL, NULL, NULL, username,
password);
if (newService)
{
CloseServiceHandle(newService);
ret_val = true;
}
if (newService)
{
CloseServiceHandle(newService);
ret_val= true;
}
CloseServiceHandle(scm);
return ret_val;
CloseServiceHandle(scm);
return ret_val;
}
BOOL WindowsService::Init()
{
assert(serviceName != NULL);
if (inited) return true;
if (inited) return true;
SERVICE_TABLE_ENTRY stb[] =
{
{ (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
{ NULL, NULL }
};
inited = true;
return StartServiceCtrlDispatcher(stb); //register with the Service Manager
SERVICE_TABLE_ENTRY stb[] =
{
{ (LPSTR)serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain},
{ NULL, NULL }
};
inited= true;
return StartServiceCtrlDispatcher(stb); //register with the Service Manager
}
BOOL WindowsService::Remove()
{
bool ret_val = false;
if (! IsInstalled())
return true;
// open a connection to the SCM
SC_HANDLE scm = OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);
if (! scm)
return false;
SC_HANDLE service = OpenService(scm, serviceName, DELETE);
if (service)
{
if (DeleteService(service))
ret_val = true;
DWORD dw = ::GetLastError();
CloseServiceHandle(service);
}
CloseServiceHandle(scm);
return ret_val;
bool ret_val= false;
if (! IsInstalled())
return true;
// open a connection to the SCM
SC_HANDLE scm= OpenSCManager(0, 0,SC_MANAGER_CREATE_SERVICE);
if (! scm)
return false;
SC_HANDLE service= OpenService(scm, serviceName, DELETE);
if (service)
{
if (DeleteService(service))
ret_val= true;
DWORD dw= ::GetLastError();
CloseServiceHandle(service);
}
CloseServiceHandle(scm);
return ret_val;
}
BOOL WindowsService::IsInstalled()
{
BOOL ret_val = FALSE;
BOOL ret_val= FALSE;
SC_HANDLE scm = ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
SC_HANDLE serv_handle = ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
SC_HANDLE scm= ::OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT);
SC_HANDLE serv_handle= ::OpenService(scm, serviceName, SERVICE_QUERY_STATUS);
ret_val = serv_handle != NULL;
ret_val= serv_handle != NULL;
::CloseServiceHandle(serv_handle);
::CloseServiceHandle(scm);
......@@ -105,34 +108,36 @@ BOOL WindowsService::IsInstalled()
void WindowsService::SetAcceptedControls(DWORD acceptedControls)
{
dwAcceptedControls = acceptedControls;
dwAcceptedControls= acceptedControls;
}
BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwError)
BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint,
DWORD dwError)
{
if(debugging) return TRUE;
if(debugging) return TRUE;
if(currentState == SERVICE_START_PENDING)
status.dwControlsAccepted = 0;
status.dwControlsAccepted= 0;
else
status.dwControlsAccepted = dwAcceptedControls;
status.dwControlsAccepted= dwAcceptedControls;
status.dwCurrentState = currentState;
status.dwWin32ExitCode = dwError != 0 ? ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
status.dwWaitHint = waitHint;
status.dwServiceSpecificExitCode = dwError;
status.dwCurrentState= currentState;
status.dwWin32ExitCode= dwError != 0 ?
ERROR_SERVICE_SPECIFIC_ERROR : NO_ERROR;
status.dwWaitHint= waitHint;
status.dwServiceSpecificExitCode= dwError;
if(currentState == SERVICE_RUNNING || currentState == SERVICE_STOPPED)
{
status.dwCheckPoint = 0;
statusCheckpoint = 0;
}
else
status.dwCheckPoint = ++statusCheckpoint;
if(currentState == SERVICE_RUNNING || currentState == SERVICE_STOPPED)
{
status.dwCheckPoint= 0;
statusCheckpoint= 0;
}
else
status.dwCheckPoint= ++statusCheckpoint;
// Report the status of the service to the service control manager.
BOOL result = SetServiceStatus(statusHandle, &status);
BOOL result= SetServiceStatus(statusHandle, &status);
if (!result)
Log("ReportStatus failed");
......@@ -141,7 +146,7 @@ BOOL WindowsService::ReportStatus(DWORD currentState, DWORD waitHint, DWORD dwEr
void WindowsService::RegisterAndRun(DWORD argc, LPTSTR *argv)
{
statusHandle = ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
statusHandle= ::RegisterServiceCtrlHandler(serviceName, ControlHandler);
if (statusHandle && ReportStatus(SERVICE_START_PENDING))
Run();
ReportStatus(SERVICE_STOPPED);
......@@ -152,41 +157,41 @@ void WindowsService::HandleControlCode(DWORD opcode)
// Handle the requested control code.
switch(opcode)
{
case SERVICE_CONTROL_STOP:
// Stop the service.
status.dwCurrentState = SERVICE_STOP_PENDING;
case SERVICE_CONTROL_STOP:
// Stop the service.
status.dwCurrentState= SERVICE_STOP_PENDING;
Stop();
break;
break;
case SERVICE_CONTROL_PAUSE:
status.dwCurrentState = SERVICE_PAUSE_PENDING;
case SERVICE_CONTROL_PAUSE:
status.dwCurrentState= SERVICE_PAUSE_PENDING;
Pause();
break;
break;
case SERVICE_CONTROL_CONTINUE:
status.dwCurrentState = SERVICE_CONTINUE_PENDING;
case SERVICE_CONTROL_CONTINUE:
status.dwCurrentState= SERVICE_CONTINUE_PENDING;
Continue();
break;
break;
case SERVICE_CONTROL_SHUTDOWN:
case SERVICE_CONTROL_SHUTDOWN:
Shutdown();
break;
break;
case SERVICE_CONTROL_INTERROGATE:
case SERVICE_CONTROL_INTERROGATE:
ReportStatus(status.dwCurrentState);
break;
break;
default:
// invalid control code
break;
}
default:
// invalid control code
break;
}
}
void WINAPI WindowsService::ServiceMain(DWORD argc, LPTSTR *argv)
{
assert(gService != NULL);
assert(gService != NULL);
// register our service control handler:
// register our service control handler:
gService->RegisterAndRun(argc, argv);
}
......
......@@ -3,7 +3,7 @@
class WindowsService
{
protected:
bool inited;
bool inited;
const char *serviceName;
const char *displayName;
const char *username;
......@@ -15,29 +15,29 @@ protected:
bool debugging;
public:
WindowsService(void);
~WindowsService(void);
WindowsService(void);
~WindowsService(void);
BOOL Install();
BOOL Remove();
BOOL Init();
BOOL Install();
BOOL Remove();
BOOL Init();
BOOL IsInstalled();
void SetAcceptedControls(DWORD acceptedControls);
void Debug(bool debugFlag) { debugging = debugFlag; }
public:
static void WINAPI ServiceMain(DWORD argc, LPTSTR * argv);
static void WINAPI ServiceMain(DWORD argc, LPTSTR *argv);
static void WINAPI ControlHandler(DWORD CtrlType);
protected:
virtual void Run() = 0;
virtual void Run()= 0;
virtual void Stop() {}
virtual void Shutdown() {}
virtual void Pause() {}
virtual void Continue() {}
virtual void Log(const char *msg) {}
BOOL ReportStatus(DWORD currentStatus, DWORD waitHint=3000, DWORD dwError=0);
BOOL ReportStatus(DWORD currentStatus, DWORD waitHint= 3000, DWORD dwError=0);
void HandleControlCode(DWORD opcode);
void RegisterAndRun(DWORD argc, LPTSTR *argv);
};
......
......@@ -691,7 +691,7 @@ int Set_option::correct_file(int skip)
int error;
error= modify_defaults_file(Options::config_file, option,
option_value, instance_name, skip);
option_value, instance_name, skip);
if (error > 0)
return ER_OUT_OF_RESOURCES;
else if (error < 0)
......
......@@ -119,7 +119,7 @@ int Instance::start()
#ifndef __WIN__
int Instance::launch_and_wait()
{
pid_t pid = fork();
pid_t pid= fork();
switch (pid)
{
......@@ -160,21 +160,21 @@ int Instance::launch_and_wait()
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
ZeroMemory(&si, sizeof(si));
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
ZeroMemory(&pi, sizeof(pi));
int cmdlen = 0;
for (int i=1; options.argv[i] != 0; i++)
cmdlen += strlen(options.argv[i]) + 1;
int cmdlen= 0;
for (int i= 1; options.argv[i] != 0; i++)
cmdlen+= strlen(options.argv[i]) + 1;
cmdlen++; // we have to add a single space for CreateProcess (read the docs)
char *cmdline = NULL;
char *cmdline= NULL;
if (cmdlen > 0)
{
cmdline = new char[cmdlen];
cmdline[0] = 0;
for (int i=1; options.argv[i] != 0; i++)
cmdline= new char[cmdlen];
cmdline[0]= 0;
for (int i= 1; options.argv[i] != 0; i++)
{
strcat(cmdline, " ");
strcat(cmdline, options.argv[i]);
......@@ -182,16 +182,16 @@ int Instance::launch_and_wait()
}
// Start the child process.
BOOL result = CreateProcess(options.mysqld_path, // file to execute
cmdline, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ); // Pointer to PROCESS_INFORMATION structure.
BOOL result= CreateProcess(options.mysqld_path, // file to execute
cmdline, // Command line.
NULL, // Process handle not inheritable.
NULL, // Thread handle not inheritable.
FALSE, // Set handle inheritance to FALSE.
0, // No creation flags.
NULL, // Use parent's environment block.
NULL, // Use parent's starting directory.
&si, // Pointer to STARTUPINFO structure.
&pi ); // Pointer to PROCESS_INFORMATION structure.
delete cmdline;
if (! result)
return -1;
......@@ -203,8 +203,8 @@ int Instance::launch_and_wait()
::GetExitCodeProcess(pi.hProcess, &exitcode);
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
return exitcode;
}
......@@ -215,7 +215,7 @@ void Instance::fork_and_monitor()
{
log_info("starting instance %s", options.instance_name);
int result = launch_and_wait();
int result= launch_and_wait();
if (result == -1) return;
/* set instance state to crashed */
......@@ -371,48 +371,48 @@ err:
BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
{
DWORD dwTID, dwCode, dwErr = 0;
HANDLE hProcessDup = INVALID_HANDLE_VALUE;
HANDLE hRT = NULL;
HINSTANCE hKernel = GetModuleHandle("Kernel32");
BOOL bSuccess = FALSE;
HANDLE hProcessDup= INVALID_HANDLE_VALUE;
HANDLE hRT= NULL;
HINSTANCE hKernel= GetModuleHandle("Kernel32");
BOOL bSuccess= FALSE;
BOOL bDup = DuplicateHandle(GetCurrentProcess(),
hProcess, GetCurrentProcess(), &hProcessDup, PROCESS_ALL_ACCESS, FALSE, 0);
BOOL bDup= DuplicateHandle(GetCurrentProcess(),
hProcess, GetCurrentProcess(), &hProcessDup,
PROCESS_ALL_ACCESS, FALSE, 0);
// Detect the special case where the process is
// already dead...
if ( GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
(dwCode == STILL_ACTIVE) )
if (GetExitCodeProcess((bDup) ? hProcessDup : hProcess, &dwCode) &&
(dwCode == STILL_ACTIVE))
{
FARPROC pfnExitProc;
pfnExitProc = GetProcAddress(hKernel, "ExitProcess");
pfnExitProc= GetProcAddress(hKernel, "ExitProcess");
hRT = CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)pfnExitProc, (PVOID)uExitCode, 0, &dwTID);
hRT= CreateRemoteThread((bDup) ? hProcessDup : hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE)pfnExitProc,
(PVOID)uExitCode, 0, &dwTID);
if ( hRT == NULL )
dwErr = GetLastError();
if (hRT == NULL)
dwErr= GetLastError();
}
else
{
dwErr = ERROR_PROCESS_ABORTED;
}
dwErr= ERROR_PROCESS_ABORTED;
if ( hRT )
if (hRT)
{
// Must wait process to terminate to
// guarantee that it has exited...
WaitForSingleObject((bDup) ? hProcessDup : hProcess, INFINITE);
CloseHandle(hRT);
bSuccess = TRUE;
bSuccess= TRUE;
}
if ( bDup )
if (bDup)
CloseHandle(hProcessDup);
if ( !bSuccess )
if (!bSuccess)
SetLastError(dwErr);
return bSuccess;
......@@ -420,7 +420,7 @@ BOOL SafeTerminateProcess(HANDLE hProcess, UINT uExitCode)
int kill(pid_t pid, int signum)
{
HANDLE processhandle = ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
HANDLE processhandle= ::OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (signum == SIGTERM)
::SafeTerminateProcess(processhandle, 0);
else
......
......@@ -256,8 +256,8 @@ int Instance_map::load()
else
argv_options[1]= '\0';
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv, &args_used,
process_option, (void*) this) ||
if (my_search_option_files(Options::config_file, &argc, (char ***) &argv,
&args_used, process_option, (void*) this) ||
complete_initialization())
return 1;
......
......@@ -59,15 +59,15 @@ private:
int create_unix_socket(struct sockaddr_un &unix_socket_address);
};
const int LISTEN_BACK_LOG_SIZE = 5; // standard backlog size
const int LISTEN_BACK_LOG_SIZE= 5; // standard backlog size
Listener_thread::Listener_thread(const Listener_thread_args &args) :
Listener_thread_args(args.thread_registry, args.options, args.user_map,
args.instance_map)
,total_connection_count(0)
,thread_info(pthread_self())
,num_sockets(0)
{
num_sockets= 0;
}
......@@ -116,11 +116,11 @@ void Listener_thread::run()
#endif
/* II. Listen sockets and spawn childs */
for (int i=0; i < num_sockets; i++)
n = max(n, sockets[i]);
for (int i= 0; i < num_sockets; i++)
n= max(n, sockets[i]);
n++;
while (thread_registry.is_shutdown() == false)
while (!thread_registry.is_shutdown())
{
fd_set read_fds_arg= read_fds;
......@@ -140,7 +140,7 @@ void Listener_thread::run()
}
for (int socket_index=0; socket_index < num_sockets; socket_index++)
for (int socket_index= 0; socket_index < num_sockets; socket_index++)
{
/* Assuming that rc > 0 as we asked to wait forever */
if (FD_ISSET(sockets[socket_index], &read_fds_arg))
......@@ -149,8 +149,8 @@ void Listener_thread::run()
/* accept may return -1 (failure or spurious wakeup) */
if (client_fd >= 0) // connection established
{
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:VIO_TYPE_TCPIP,
socket_index==0?1:0);
Vio *vio = vio_new(client_fd, socket_index==0?VIO_TYPE_SOCKET:
VIO_TYPE_TCPIP, socket_index==0?1:0);
if (vio != 0)
handle_new_mysql_connection(vio);
else
......@@ -167,7 +167,7 @@ void Listener_thread::run()
log_info("Listener_thread::run(): shutdown requested, exiting...");
for (int i=0; i < num_sockets; i++)
for (int i= 0; i < num_sockets; i++)
close(sockets[i]);
#ifndef __WIN__
......@@ -179,6 +179,10 @@ void Listener_thread::run()
return;
err:
// we have to close the ip sockets in case of error
for (int i= 0; i < num_sockets; i++)
close(sockets[i]);
thread_registry.unregister_thread(&thread_info);
thread_registry.request_shutdown();
my_thread_end();
......@@ -191,7 +195,7 @@ void set_non_blocking(int socket)
int flags= fcntl(socket, F_GETFL, 0);
fcntl(socket, F_SETFL, flags | O_NONBLOCK);
#else
u_long arg = 1;
u_long arg= 1;
ioctlsocket(socket, FIONBIO, &arg);
#endif
}
......@@ -245,7 +249,7 @@ int Listener_thread::create_tcp_socket()
log_error("Listener_thread::run(): bind(ip socket) failed, '%s'",
strerror(errno));
close(ip_socket);
return -1;
return -1;
}
if (listen(ip_socket, LISTEN_BACK_LOG_SIZE))
......@@ -263,7 +267,7 @@ int Listener_thread::create_tcp_socket()
set_no_inherit(ip_socket);
FD_SET(ip_socket, &read_fds);
sockets[num_sockets++] = ip_socket;
sockets[num_sockets++]= ip_socket;
log_info("accepting connections on ip socket");
return 0;
}
......
......@@ -85,14 +85,14 @@ bool have_signal;
void onsignal(int signo)
{
have_signal = true;
have_signal= true;
}
void set_signals(sigset_t *set)
{
signal(SIGINT, onsignal);
signal(SIGTERM, onsignal);
have_signal = false;
have_signal= false;
}
int my_sigwait(const sigset_t *set, int *sig)
......
......@@ -30,9 +30,9 @@
#define QUOTE2(x) #x
#define QUOTE(x) QUOTE2(x)
const char *default_password_file_name = QUOTE(DEFAULT_PASSWORD_FILE_NAME);
const char *default_log_file_name = QUOTE(DEFAULT_LOG_FILE_NAME);
char default_config_file[FN_REFLEN] = "/etc/my.cnf";
const char *default_password_file_name= QUOTE(DEFAULT_PASSWORD_FILE_NAME);
const char *default_log_file_name= QUOTE(DEFAULT_LOG_FILE_NAME);
char default_config_file[FN_REFLEN]= "/etc/my.cnf";
#ifndef __WIN__
char Options::run_as_service;
......@@ -52,7 +52,7 @@ uint Options::monitoring_interval= DEFAULT_MONITORING_INTERVAL;
uint Options::port_number= DEFAULT_PORT;
/* just to declare */
char **Options::saved_argv;
const char *Options::config_file = NULL;
const char *Options::config_file= NULL;
/*
List of options, accepted by the instance manager.
......@@ -236,33 +236,34 @@ C_MODE_END
int Options::load(int argc, char **argv)
{
int rc;
char** argv_ptr = argv;
char **argv_ptr= argv;
#ifdef __WIN__
setup_windows_defaults(*argv);
#endif
config_file=NULL;
config_file= NULL;
if (argc >= 2)
{
if (is_prefix(argv[1], "--defaults-file="))
config_file=argv[1];
if (is_prefix(argv[1], "--defaults-file="))
config_file=argv[1];
if (is_prefix(argv[1],"--defaults-file=") ||
is_prefix(argv[1],"--defaults-extra-file="))
Options::first_option= argv[1];
}
// we were not given a config file on the command line so we
// set have to construct a new argv array
if (config_file == NULL)
{
/*
we were not given a config file on the command line so we
default to our compiled in default
*/
if (config_file == NULL)
{
#ifdef __WIN__
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file));
char *filename = strstr(default_config_file, "mysqlmanager.exe");
strcpy(filename, "my.ini");
::GetModuleFileName(NULL, default_config_file, sizeof(default_config_file)); char *filename= strrchr(default_config_file, "\\");
strcpy(filename, "\\my.ini");
#endif
config_file = default_config_file;
}
config_file= default_config_file;
}
/* config-file options are prepended to command-line ones */
load_defaults(config_file, default_groups, &argc, &argv);
......@@ -281,7 +282,6 @@ void Options::cleanup()
{
/* free_defaults returns nothing */
free_defaults(Options::saved_argv);
#ifdef __WIN__
free((char*)default_password_file_name);
#endif
......@@ -291,11 +291,11 @@ void Options::cleanup()
char* change_extension(const char *src, const char *newext)
{
char *dot = (char*)strrchr(src, '.');
char *dot= (char*)strrchr(src, '.');
if (!dot) return (char*)src;
int newlen = dot-src+strlen(newext)+1;
char *temp = (char*)malloc(newlen);
int newlen= dot-src+strlen(newext)+1;
char *temp= (char*)malloc(newlen);
bzero(temp, newlen);
strncpy(temp, src, dot-src+1);
strcat(temp, newext);
......@@ -304,8 +304,10 @@ char* change_extension(const char *src, const char *newext)
void Options::setup_windows_defaults(const char *progname)
{
Options::password_file_name = default_password_file_name = change_extension(progname, "passwd");
Options::log_file_name = default_log_file_name = change_extension(progname, "log");
Options::password_file_name= default_password_file_name =
change_extension(progname, "passwd");
Options::log_file_name= default_log_file_name =
change_extension(progname, "log");
}
#endif
......@@ -62,8 +62,8 @@ int User::init(const char *line)
/* assume that newline characater is present */
if (password[strlen(password)-2] == '\r')
{
password[strlen(password)-2] = '\n';
password[strlen(password)-1] = 0;
password[strlen(password)-2]= '\n';
password[strlen(password)-1]= 0;
}
if (strlen(password) != SCRAMBLED_PASSWORD_CHAR_LENGTH + 1)
goto err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment