Skip to content

Commit 9347e07

Browse files
committed
5-8 C4
1 parent 2c7e659 commit 9347e07

File tree

9 files changed

+88
-17
lines changed

9 files changed

+88
-17
lines changed

contrib/win32/openssh/Win32-OpenSSH.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ EndProject
8181
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ssh-agent", "ssh-agent.vcxproj", "{F6644EC5-D6B6-42A1-828C-75E2977470E0}"
8282
ProjectSection(ProjectDependencies) = postProject
8383
{05E1115F-8529-46D0-AAAF-52A404CE79A7} = {05E1115F-8529-46D0-AAAF-52A404CE79A7}
84+
{8F9D3B74-8D33-448E-9762-26E8DCC6B2F4} = {8F9D3B74-8D33-448E-9762-26E8DCC6B2F4}
8485
{DD483F7D-C553-4740-BC1A-903805AD0174} = {DD483F7D-C553-4740-BC1A-903805AD0174}
8586
{0D02F0F0-013B-4EE3-906D-86517F3822C0} = {0D02F0F0-013B-4EE3-906D-86517F3822C0}
8687
{8660C2FE-9874-432D-B047-E042BB41DBE0} = {8660C2FE-9874-432D-B047-E042BB41DBE0}

contrib/win32/openssh/ssh-agent.vcxproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@
198198
<ClInclude Include="..\ssh-pubkey\ssh-pubkeydefs.h" />
199199
<ClInclude Include="..\win32compat\ssh-agent\agent-request.h" />
200200
<ClInclude Include="..\win32compat\ssh-agent\agent.h" />
201-
<ClInclude Include="..\win32compat\ssh-agent\config.h" />
202201
</ItemGroup>
203202
<ItemGroup>
204203
<ClCompile Include="..\..\..\auth.c" />
@@ -208,7 +207,7 @@
208207
<ClCompile Include="..\win32compat\ssh-agent\agent-main.c" />
209208
<ClCompile Include="..\win32compat\ssh-agent\agent.c" />
210209
<ClCompile Include="..\win32compat\ssh-agent\authagent-request.c" />
211-
<ClCompile Include="..\win32compat\ssh-agent\config.c" />
210+
<ClCompile Include="..\win32compat\ssh-agent\agentconfig.c" />
212211
<ClCompile Include="..\win32compat\ssh-agent\connection.c" />
213212
<ClCompile Include="..\win32compat\ssh-agent\keyagent-request.c" />
214213
<ClCompile Include="..\win32compat\ssh-agent\pubkeyagent-request.c" />

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@
2828
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2929
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
31+
3132
#include "agent.h"
32-
#include "config.h"
33+
3334

3435
int scm_start_servie(DWORD, LPWSTR*);
3536

36-
SERVICE_TABLE_ENTRY diapatch_table[] =
37+
SERVICE_TABLE_ENTRYW dispatch_table[] =
3738
{
38-
{ L"ssh-agent", (LPSERVICE_MAIN_FUNCTION)scm_start_servie },
39+
{ L"ssh-agent", (LPSERVICE_MAIN_FUNCTIONW)scm_start_servie },
3940
{ NULL, NULL }
4041
};
4142
static SERVICE_STATUS_HANDLE service_status_handle;
@@ -93,7 +94,7 @@ int main(int argc, char **argv) {
9394

9495
w32posix_initialize();
9596
load_config();
96-
if (!StartServiceCtrlDispatcher(diapatch_table)) {
97+
if (!StartServiceCtrlDispatcherW(dispatch_table)) {
9798
if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
9899
if (argc == 1) {
99100
/* console app - start in debug mode*/
@@ -102,8 +103,10 @@ int main(int argc, char **argv) {
102103
return agent_start(TRUE, FALSE, 0, 0);
103104
}
104105
else {
106+
char* h = 0;
107+
h += atoi(*(argv + 1));
105108
log_init("ssh-agent", config_log_level(), 1, 0);
106-
return agent_start(FALSE, TRUE, (HANDLE)atoi(*(argv+1)), atoi(*(argv+2)));
109+
return agent_start(FALSE, TRUE, h, atoi(*(argv+2)));
107110
}
108111
}
109112
else
@@ -113,7 +116,7 @@ int main(int argc, char **argv) {
113116
}
114117

115118
int scm_start_servie(DWORD num, LPWSTR* args) {
116-
service_status_handle = RegisterServiceCtrlHandler(L"ssh-agent", service_handler);
119+
service_status_handle = RegisterServiceCtrlHandlerW(L"ssh-agent", service_handler);
117120
ZeroMemory(&service_status, sizeof(service_status));
118121
service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
119122
ReportSvcStatus(SERVICE_START_PENDING, NO_ERROR, 300);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <Windows.h>
21
typedef unsigned char u_int8_t;
32
typedef unsigned short u_int16_t;
43
typedef unsigned int u_int32_t;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2929
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
31-
#include "agent.h"s
31+
#include "agent.h"
3232
#define BUFSIZE 5 * 1024
3333

3434
static HANDLE ioc_port = NULL;
@@ -118,7 +118,7 @@ process_connection(HANDLE pipe, int type) {
118118
con->type = type;
119119
CreateIoCompletionPort(pipe, ioc_port, (ULONG_PTR)con, 0);
120120
agent_connection_on_io(con, 0, &con->ol);
121-
iocp_work(NULL);
121+
return iocp_work(NULL);
122122
}
123123

124124
static void
@@ -186,10 +186,10 @@ agent_listen_loop() {
186186
/* todo - spawn a child to take care of this*/
187187
wchar_t path[MAX_PATH], module_path[MAX_PATH];
188188
PROCESS_INFORMATION pi;
189-
STARTUPINFO si;
189+
STARTUPINFOW si;
190190

191-
si.cb = sizeof(STARTUPINFO);
192-
memset(&si, 0, sizeof(STARTUPINFO));
191+
si.cb = sizeof(STARTUPINFOW);
192+
memset(&si, 0, sizeof(STARTUPINFOW));
193193
GetModuleFileNameW(NULL, module_path, MAX_PATH);
194194
swprintf_s(path, MAX_PATH, L"%s %d %d", module_path, con, listeners[r - 1].type);
195195
if (CreateProcessW(NULL, path, NULL, NULL, TRUE,

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ void agent_connection_disconnect(struct agent_connection*);
3939

4040
int agent_start(BOOL, BOOL, HANDLE, enum agent_type);
4141
void agent_shutdown();
42-
void agent_cleanup_connection(struct agent_connection*);
42+
void agent_cleanup_connection(struct agent_connection*);
43+
44+
int load_config();
45+
int config_log_level();

contrib/win32/win32compat/ssh-agent/config.c renamed to contrib/win32/win32compat/ssh-agent/agentconfig.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "auth.h"
4545
#include "myproposal.h"
4646
#include "digest.h"
47+
#include "agent.h"
4748

4849
static int use_privsep = -1;
4950
Buffer cfg;

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,74 @@
2929
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131

32+
#include <Windows.h>
33+
#include <Ntsecapi.h>
34+
//#include <ntstatus.h>
3235
#include "agent.h"
3336
#include "agent-request.h"
3437

38+
3539
int process_authagent_request(struct sshbuf* request, struct sshbuf* response, struct agent_connection* con) {
40+
while (1)
41+
{
42+
HANDLE lsa_handle;
43+
PLSA_OPERATIONAL_MODE mode;
44+
ULONG auth_package_id;
45+
NTSTATUS ret;
46+
KERB_S4U_LOGON *s4u_logon;
47+
size_t logon_info_size;
48+
LSA_STRING logon_process_name, auth_package_name, originName;
49+
InitLsaString(&logon_process_name, "ssh-agent");
50+
//InitLsaString(&auth_package_name, MICROSOFT_KERBEROS_NAME_A);
51+
InitLsaString(&auth_package_name, "Negotiate");
52+
InitLsaString(&originName, "sshd");
53+
if (ret = LsaRegisterLogonProcess(&logon_process_name, &lsa_handle, &mode) != STATUS_SUCCESS)
54+
break;
55+
56+
if (ret = LsaLookupAuthenticationPackage(lsa_handle, &auth_package_name, &auth_package_id) != STATUS_SUCCESS)
57+
break;
58+
#define USER_NAME L"user@domain"
59+
logon_info_size = sizeof(KERB_S4U_LOGON);
60+
logon_info_size += (wcslen(USER_NAME) * 2 + 2);
61+
s4u_logon = malloc(logon_info_size);
62+
s4u_logon->MessageType = KerbS4ULogon;
63+
s4u_logon->Flags = 0;
64+
s4u_logon->ClientUpn.Length = wcslen(USER_NAME) * 2;
65+
s4u_logon->ClientUpn.MaximumLength = s4u_logon->ClientUpn.Length;
66+
s4u_logon->ClientUpn.Buffer = (WCHAR*)(s4u_logon + 1);
67+
memcpy(s4u_logon->ClientUpn.Buffer, USER_NAME, s4u_logon->ClientUpn.Length + 2);
68+
s4u_logon->ClientRealm.Length = 0;
69+
s4u_logon->ClientRealm.MaximumLength = 0;
70+
s4u_logon->ClientRealm.Buffer = 0;
71+
72+
TOKEN_SOURCE sourceContext;
73+
RtlCopyMemory(
74+
sourceContext.SourceName,
75+
".Jobs ",
76+
sizeof(sourceContext.SourceName)
77+
);
78+
79+
if (AllocateLocallyUniqueId(&sourceContext.SourceIdentifier) != TRUE)
80+
break;
81+
82+
PKERB_INTERACTIVE_PROFILE pProfile = NULL;
83+
LUID logonId;
84+
QUOTA_LIMITS quotas;
85+
NTSTATUS subStatus;
86+
DWORD cbProfile;
87+
HANDLE hToken = INVALID_HANDLE_VALUE;
88+
if (ret = LsaLogonUser(lsa_handle, &originName, Network, auth_package_id, s4u_logon, logon_info_size, NULL, &sourceContext,
89+
(PVOID*)&pProfile,
90+
&cbProfile,
91+
&logonId,
92+
&hToken,
93+
&quotas,
94+
&subStatus) != STATUS_SUCCESS)
95+
break;
96+
97+
CloseHandle(hToken);
98+
LsaDeregisterLogonProcess(lsa_handle);
99+
break;
100+
}
36101
return -1;
37102
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ get_user_root(struct agent_connection* con, HKEY *root){
4949
}
5050

5151
static int
52-
convert_blob(struct agent_connection* con, char *blob, DWORD blen, char **eblob, DWORD *eblen, int encrypt) {
52+
convert_blob(struct agent_connection* con, const char *blob, DWORD blen, char **eblob, DWORD *eblen, int encrypt) {
5353
int r = 0;
5454
DATA_BLOB in, out;
5555
if (ImpersonateNamedPipeClient(con->connection) == FALSE)
5656
return ERROR_INTERNAL_ERROR;
5757

5858
in.cbData = blen;
59-
in.pbData = blob;
59+
in.pbData = (char*)blob;
6060
out.cbData = 0;
6161
out.pbData = NULL;
6262

0 commit comments

Comments
 (0)