This commit is contained in:
Manoj Ampalam 2016-05-07 13:20:29 -07:00
parent 3f63888e81
commit b22f7cddb6
5 changed files with 71 additions and 8 deletions

View File

@ -197,6 +197,7 @@
<ClInclude Include="..\..\..\servconf.h" /> <ClInclude Include="..\..\..\servconf.h" />
<ClInclude Include="..\win32compat\ssh-agent\agent-request.h" /> <ClInclude Include="..\win32compat\ssh-agent\agent-request.h" />
<ClInclude Include="..\win32compat\ssh-agent\agent.h" /> <ClInclude Include="..\win32compat\ssh-agent\agent.h" />
<ClInclude Include="..\win32compat\ssh-agent\config.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\..\..\auth.c" /> <ClCompile Include="..\..\..\auth.c" />

View File

@ -29,6 +29,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "agent.h" #include "agent.h"
#include "config.h"
int scm_start_servie(DWORD, LPWSTR*); int scm_start_servie(DWORD, LPWSTR*);
@ -87,12 +88,22 @@ BOOL WINAPI ctrl_c_handler(
return TRUE; return TRUE;
} }
int main() { int main(int argc, char **argv) {
w32posix_initialize();
load_config();
if (!StartServiceCtrlDispatcher(diapatch_table)) { if (!StartServiceCtrlDispatcher(diapatch_table)) {
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
/* console app */ if (argc == 1) {
/* console app - start in debug mode*/
SetConsoleCtrlHandler(ctrl_c_handler, TRUE); SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
return agent_start(); log_init("ssh-agent", 7, 1, 1);
return agent_start(TRUE, FALSE, 0);
}
else {
log_init("ssh-agent", config_log_level(), 1, 0);
return agent_start(FALSE, TRUE, (HANDLE)atoi(*argv));
}
} }
else else
return -1; return -1;
@ -106,6 +117,7 @@ int scm_start_servie(DWORD num, LPWSTR* args) {
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 300); ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 300);
ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0); ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
return agent_start(); log_init("ssh-agent", config_log_level(), 1, 0);
return agent_start(FALSE, FALSE, 0);
} }

View File

@ -153,10 +153,12 @@ DWORD WINAPI iocp_work(LPVOID lpParam) {
} }
} }
int agent_start() { int agent_start(BOOL dbg, BOOL child, HANDLE pipe) {
int i; int i;
HKEY agent_root; HKEY agent_root;
DWORD process_id = GetCurrentProcessId(); DWORD process_id = GetCurrentProcessId();
debug("agent_start pid:%d, dbg:%d, child:%d, pipe:%d", process_id, dbg, child, pipe);
action_queue = 0; action_queue = 0;
list = NULL; list = NULL;
ioc_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)NULL, 0); ioc_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)NULL, 0);

View File

@ -30,7 +30,7 @@ void agent_connection_on_io(struct agent_connection*, DWORD, OVERLAPPED*);
void agent_connection_on_error(struct agent_connection* , DWORD ); void agent_connection_on_error(struct agent_connection* , DWORD );
void agent_connection_disconnect(struct agent_connection*); void agent_connection_disconnect(struct agent_connection*);
int agent_start(); int agent_start(BOOL debug, BOOL child, HANDLE pipe);
void agent_shutdown(); void agent_shutdown();
void agent_listen(); void agent_listen();
void agent_cleanup_connection(struct agent_connection*); void agent_cleanup_connection(struct agent_connection*);

View File

@ -45,11 +45,12 @@
#include "myproposal.h" #include "myproposal.h"
#include "digest.h" #include "digest.h"
int use_privsep = -1; static int use_privsep = -1;
Buffer cfg; Buffer cfg;
ServerOptions options; ServerOptions options;
struct passwd *privsep_pw = NULL; struct passwd *privsep_pw = NULL;
char *forced_command = NULL; char *forced_command = NULL;
static char *config_file_name = _PATH_SERVER_CONFIG_FILE;
int auth2_methods_valid(const char * c, int i) { int auth2_methods_valid(const char * c, int i) {
return 1; return 1;
@ -59,3 +60,50 @@ int
mm_is_monitor(void) { mm_is_monitor(void) {
return 0; return 0;
} }
int kexgex_server(struct ssh * sh) {
return -1;
}
static
int GetCurrentModulePath(char *path, int pathSize)
{
if (GetModuleFileName(NULL, path, pathSize)) {
int i;
int lastSlashPos = 0;
for (i = 0; path[i]; i++) {
if (path[i] == '/' || path[i] == '\\') {
lastSlashPos = i;
}
}
path[lastSlashPos] = 0;
return 0;
}
return -1;
}
int load_config() {
char basePath[MAX_PATH] = { 0 };
char path[MAX_PATH] = { 0 };
/* TODO - account for UNICODE paths*/
if (GetCurrentModulePath(basePath, MAX_PATH) == 0)
{
strncpy(path, basePath, MAX_PATH);
strncat(path, "/sshd_config", MAX_PATH);
config_file_name = path;
}
buffer_init(&cfg);
initialize_server_options(&options);
load_server_config(config_file_name, &cfg);
parse_server_config(&options, config_file_name, &cfg, NULL);
fill_default_server_options(&options);
return 0;
}
int config_log_level() {
return options.log_level;
}