Skip to content

Commit b22f7cd

Browse files
committed
5-7 C1
1 parent 3f63888 commit b22f7cd

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

contrib/win32/openssh/ssh-agent.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@
197197
<ClInclude Include="..\..\..\servconf.h" />
198198
<ClInclude Include="..\win32compat\ssh-agent\agent-request.h" />
199199
<ClInclude Include="..\win32compat\ssh-agent\agent.h" />
200+
<ClInclude Include="..\win32compat\ssh-agent\config.h" />
200201
</ItemGroup>
201202
<ItemGroup>
202203
<ClCompile Include="..\..\..\auth.c" />

contrib/win32/win32compat/ssh-agent/agent-main.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131
#include "agent.h"
32+
#include "config.h"
3233

3334
int scm_start_servie(DWORD, LPWSTR*);
3435

@@ -87,12 +88,22 @@ BOOL WINAPI ctrl_c_handler(
8788
return TRUE;
8889
}
8990

90-
int main() {
91+
int main(int argc, char **argv) {
92+
93+
w32posix_initialize();
94+
load_config();
9195
if (!StartServiceCtrlDispatcher(diapatch_table)) {
9296
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
93-
/* console app */
94-
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
95-
return agent_start();
97+
if (argc == 1) {
98+
/* console app - start in debug mode*/
99+
SetConsoleCtrlHandler(ctrl_c_handler, TRUE);
100+
log_init("ssh-agent", 7, 1, 1);
101+
return agent_start(TRUE, FALSE, 0);
102+
}
103+
else {
104+
log_init("ssh-agent", config_log_level(), 1, 0);
105+
return agent_start(FALSE, TRUE, (HANDLE)atoi(*argv));
106+
}
96107
}
97108
else
98109
return -1;
@@ -106,6 +117,7 @@ int scm_start_servie(DWORD num, LPWSTR* args) {
106117
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
107118
ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 300);
108119
ReportSvcStatus(SERVICE_RUNNING, NO_ERROR, 0);
109-
return agent_start();
120+
log_init("ssh-agent", config_log_level(), 1, 0);
121+
return agent_start(FALSE, FALSE, 0);
110122
}
111123

contrib/win32/win32compat/ssh-agent/agent.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,12 @@ DWORD WINAPI iocp_work(LPVOID lpParam) {
153153
}
154154
}
155155

156-
int agent_start() {
156+
int agent_start(BOOL dbg, BOOL child, HANDLE pipe) {
157157
int i;
158158
HKEY agent_root;
159159
DWORD process_id = GetCurrentProcessId();
160+
161+
debug("agent_start pid:%d, dbg:%d, child:%d, pipe:%d", process_id, dbg, child, pipe);
160162
action_queue = 0;
161163
list = NULL;
162164
ioc_port = CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)NULL, 0);

contrib/win32/win32compat/ssh-agent/agent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void agent_connection_on_io(struct agent_connection*, DWORD, OVERLAPPED*);
3030
void agent_connection_on_error(struct agent_connection* , DWORD );
3131
void agent_connection_disconnect(struct agent_connection*);
3232

33-
int agent_start();
33+
int agent_start(BOOL debug, BOOL child, HANDLE pipe);
3434
void agent_shutdown();
3535
void agent_listen();
3636
void agent_cleanup_connection(struct agent_connection*);

contrib/win32/win32compat/ssh-agent/config.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
#include "myproposal.h"
4646
#include "digest.h"
4747

48-
int use_privsep = -1;
48+
static int use_privsep = -1;
4949
Buffer cfg;
5050
ServerOptions options;
5151
struct passwd *privsep_pw = NULL;
5252
char *forced_command = NULL;
53+
static char *config_file_name = _PATH_SERVER_CONFIG_FILE;
5354

5455
int auth2_methods_valid(const char * c, int i) {
5556
return 1;
@@ -59,3 +60,50 @@ int
5960
mm_is_monitor(void) {
6061
return 0;
6162
}
63+
64+
int kexgex_server(struct ssh * sh) {
65+
return -1;
66+
}
67+
68+
static
69+
int GetCurrentModulePath(char *path, int pathSize)
70+
{
71+
if (GetModuleFileName(NULL, path, pathSize)) {
72+
int i;
73+
int lastSlashPos = 0;
74+
75+
for (i = 0; path[i]; i++) {
76+
if (path[i] == '/' || path[i] == '\\') {
77+
lastSlashPos = i;
78+
}
79+
}
80+
81+
path[lastSlashPos] = 0;
82+
return 0;
83+
}
84+
return -1;
85+
}
86+
87+
int load_config() {
88+
char basePath[MAX_PATH] = { 0 };
89+
char path[MAX_PATH] = { 0 };
90+
91+
/* TODO - account for UNICODE paths*/
92+
if (GetCurrentModulePath(basePath, MAX_PATH) == 0)
93+
{
94+
strncpy(path, basePath, MAX_PATH);
95+
strncat(path, "/sshd_config", MAX_PATH);
96+
config_file_name = path;
97+
}
98+
buffer_init(&cfg);
99+
initialize_server_options(&options);
100+
load_server_config(config_file_name, &cfg);
101+
parse_server_config(&options, config_file_name, &cfg, NULL);
102+
fill_default_server_options(&options);
103+
104+
return 0;
105+
}
106+
107+
int config_log_level() {
108+
return options.log_level;
109+
}

0 commit comments

Comments
 (0)