summaryrefslogtreecommitdiffstats
path: root/src/lib/ccapi/windows
diff options
context:
space:
mode:
authorJeffrey Altman <jaltman@secure-endpoints.com>2006-06-05 17:49:34 +0000
committerJeffrey Altman <jaltman@secure-endpoints.com>2006-06-05 17:49:34 +0000
commitf42fa33b985c230736ad5d9080055916de33be8c (patch)
tree0f6cc37148d66dc13ca10bb268679ea4c99677bf /src/lib/ccapi/windows
parent3d6591dd63c23bcc0ae68e94a960c85fd53daad0 (diff)
downloadkrb5-f42fa33b985c230736ad5d9080055916de33be8c.tar.gz
krb5-f42fa33b985c230736ad5d9080055916de33be8c.tar.xz
krb5-f42fa33b985c230736ad5d9080055916de33be8c.zip
improved error handling
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/ccapi@18083 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/ccapi/windows')
-rw-r--r--src/lib/ccapi/windows/client.c33
-rw-r--r--src/lib/ccapi/windows/server.c77
2 files changed, 86 insertions, 24 deletions
diff --git a/src/lib/ccapi/windows/client.c b/src/lib/ccapi/windows/client.c
index db0b63aec..e30801dab 100644
--- a/src/lib/ccapi/windows/client.c
+++ b/src/lib/ccapi/windows/client.c
@@ -78,11 +78,13 @@ int cc_rpc_cleanup(void) {
}
cc_int32 cci_set_thread_session_id(unsigned char * client_name, LUID luid) {
-
+ return 0;
}
void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid) {
-
+ client_name[0] = '\0';
+ pluid->HighPart = 0;
+ pluid->LowPart = 0;
}
@@ -97,14 +99,14 @@ void cci_get_thread_session_id(unsigned char * client_name, int len, LUID *pluid
cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)
{
- __int32 rpc_code;
+ cc_int32 code;
unsigned char client_name[256];
LUID luid;
struct __LUID __luid;
unsigned char out_buf[MAXMSGLEN];
__int32 out_len = MAXMSGLEN;
- if (!cc_rpc_init())
+ if (cc_rpc_init())
return -1;
cci_get_thread_session_id(client_name, sizeof(client_name), &luid);
@@ -112,9 +114,28 @@ cc_int32 cci_perform_rpc(cc_msg_t *request, cc_msg_t **response)
__luid.HighPart = luid.HighPart;
__luid.LowPart = luid.LowPart;
- rpc_code = ccapi_Message(hRpcBinding, client_name, __luid,
+ /* flatten response */
+ code = cci_msg_flatten(request, NULL);
+ if (code)
+ goto cleanup;
+
+ RpcTryExcept {
+ code = ccapi_Message(hRpcBinding, client_name, __luid,
request->flat, request->flat_len,
out_buf, &out_len);
+ }
+ RpcExcept(1) {
+ code = RpcExceptionCode();
+ }
+ RpcEndExcept;
+ if (code)
+ goto cleanup;
+
+ /* unflatten message */
+ code = cci_msg_unflatten(out_buf, out_len, response);
+ if (code)
+ goto cleanup;
- return rpc_code;
+ cleanup:
+ return code;
}
diff --git a/src/lib/ccapi/windows/server.c b/src/lib/ccapi/windows/server.c
index 5ce8e6ebe..34d329902 100644
--- a/src/lib/ccapi/windows/server.c
+++ b/src/lib/ccapi/windows/server.c
@@ -1,5 +1,4 @@
-
#include <windows.h>
#include "msg.h"
#include "marshall.h"
@@ -15,6 +14,9 @@
#define SVCNAME "MIT_CCAPI_NT_Service"
+HANDLE hMainThread = 0;
+HANDLE WaitToTerminate = 0;
+
SERVICE_STATUS_HANDLE h_service_status = NULL;
SERVICE_STATUS service_status;
FILE * logfile = NULL;
@@ -72,7 +74,8 @@ void service_start(DWORD argc, LPTSTR * argv) {
NULL);
if (status != RPC_S_OK) {
- return;
+ if (logfile) fprintf(logfile, "service_start RpcServerUseProtseq = 0x%x\n", status);
+ goto cleanup;
}
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
@@ -80,21 +83,27 @@ void service_start(DWORD argc, LPTSTR * argv) {
status = RpcServerRegisterIf(portable_ccapi_v1_0_s_ifspec,
0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterIf = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
status = RpcServerInqBindings(&bv);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerInqBindings = 0x%x\n", status);
+ goto cleanup;
+ }
status = RpcEpRegister(portable_ccapi_v1_0_s_ifspec,
bv, 0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcEpRegister = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
@@ -102,32 +111,37 @@ void service_start(DWORD argc, LPTSTR * argv) {
RPC_C_AUTHN_WINNT,
0, 0);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerRegisterAuthInfo = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_START_PENDING, NO_ERROR, 3000);
- status = RpcServerListen(1,
+ status = RpcServerListen(2,
RPC_C_LISTEN_MAX_CALLS_DEFAULT,
TRUE);
- if (status != RPC_S_OK)
- return;
+ if (status != RPC_S_OK) {
+ if (logfile) fprintf(logfile, "service_start RpcServerListen = 0x%x\n", status);
+ goto cleanup;
+ }
report_status(SERVICE_RUNNING, NO_ERROR, 0);
- begin_log();
+ if (logfile) fprintf(logfile, "service_start calling RpcMgmtWaitServerListen\n");
status = RpcMgmtWaitServerListen();
+ if (logfile) fprintf(logfile, "service_start RpcMgmtWaitServerListen = 0x%x\n", status);
- end_log();
-
+ cleanup:
RpcEpUnregister(portable_ccapi_v1_0_s_ifspec, bv, 0);
RpcBindingVectorFree(&bv);
}
void service_stop(void) {
+ if (logfile) fprintf(logfile, "service_stop\n");
RpcMgmtStopServerListening(0);
}
@@ -292,6 +306,8 @@ __int32 ccapi_Message(
cc_session_info_t * session_info;
cc_int32 code;
+ if (logfile) fprintf(logfile, "ccapi_Message\n");
+
if ( ccs_serv_initialize() != ccNoError ) {
code = ccErrServerUnavailable;
goto done;
@@ -390,6 +406,8 @@ void WINAPI service_control(DWORD ctrl_code) {
void WINAPI service_main(DWORD argc, LPTSTR * argv) {
+ begin_log();
+
h_service_status = RegisterServiceCtrlHandler( _T(SVCNAME), service_control);
if (!h_service_status)
@@ -412,6 +430,8 @@ void WINAPI service_main(DWORD argc, LPTSTR * argv) {
if (h_service_status) {
report_status(SERVICE_STOPPED, NO_ERROR, 0);
}
+
+ end_log();
}
@@ -620,8 +640,16 @@ ParseStandardArgs(int argc, char* argv[])
return FALSE;
}
-int main(int argc, char ** argv) {
+DWORD __stdcall Main_thread(void* notUsed)
+{
+ char * argv[2] = {SVCNAME, NULL};
+ begin_log();
+ service_start(1, (LPTSTR*)argv);
+ end_log();
+ return(0);
+}
+int main(int argc, char ** argv) {
SERVICE_TABLE_ENTRY dispatch_table[] = {
{ _T(SVCNAME), (LPSERVICE_MAIN_FUNCTION) service_main },
{ NULL, NULL }
@@ -631,8 +659,21 @@ int main(int argc, char ** argv) {
return 0;
if (!StartServiceCtrlDispatcher(dispatch_table)) {
- fprintf(stderr, "Can't start service control dispatcher\n");
+ LONG status = GetLastError();
+ if (status == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)
+ {
+ DWORD tid;
+ hMainThread = CreateThread(NULL, 0, Main_thread, 0, 0, &tid);
+
+ printf("Hit <Enter> to terminate MIT CCAPI Server\n");
+ getchar();
+ service_stop();
+ }
}
+ if ( hMainThread ) {
+ WaitForSingleObject( hMainThread, INFINITE );
+ CloseHandle( hMainThread );
+ }
return 0;
}