aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Raeburn <raeburn@mit.edu>2008-02-15 02:06:37 +0000
committerKen Raeburn <raeburn@mit.edu>2008-02-15 02:06:37 +0000
commita734eeec9b92975366c2d05d68ec362bbe407021 (patch)
tree5b9b6a8e3d7cab754ca8272323097ab711a8e602
parentb5337674c2209ef015d27e1bc6d57de28df36fb9 (diff)
downloadkrb5-a734eeec9b92975366c2d05d68ec362bbe407021.zip
krb5-a734eeec9b92975366c2d05d68ec362bbe407021.tar.gz
krb5-a734eeec9b92975366c2d05d68ec362bbe407021.tar.bz2
merge to trunk rev 20223
git-svn-id: svn://anonsvn.mit.edu/krb5/branches/mt-kdc@20224 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/ccapi/common/cci_cred_union.c442
-rw-r--r--src/ccapi/common/cci_cred_union.h22
-rw-r--r--src/ccapi/common/win/OldCC/autolock.hxx106
-rw-r--r--src/ccapi/common/win/OldCC/ccutil.cxx374
-rw-r--r--src/ccapi/common/win/OldCC/ccutil.def8
-rw-r--r--src/ccapi/common/win/OldCC/ccutils.c270
-rw-r--r--src/ccapi/common/win/OldCC/ccutils.h98
-rw-r--r--src/ccapi/common/win/OldCC/init.cxx374
-rw-r--r--src/ccapi/common/win/OldCC/init.hxx204
-rw-r--r--src/ccapi/common/win/OldCC/name.h74
-rw-r--r--src/ccapi/common/win/OldCC/opts.cxx376
-rw-r--r--src/ccapi/common/win/OldCC/opts.hxx112
-rw-r--r--src/ccapi/common/win/OldCC/secure.cxx320
-rw-r--r--src/ccapi/common/win/OldCC/secure.hxx120
-rw-r--r--src/ccapi/common/win/OldCC/util.cxx1038
-rw-r--r--src/ccapi/common/win/OldCC/util.h178
-rw-r--r--src/ccapi/common/win/cci_os_debugging.c78
-rw-r--r--src/ccapi/common/win/cci_os_identifier.c114
-rw-r--r--src/ccapi/common/win/ccs_reply.Acf62
-rw-r--r--src/ccapi/common/win/ccs_reply.Idl120
-rw-r--r--src/ccapi/common/win/ccs_request.Acf62
-rw-r--r--src/ccapi/common/win/ccs_request.idl116
-rw-r--r--src/ccapi/common/win/tls.c142
-rw-r--r--src/ccapi/common/win/tls.h140
-rw-r--r--src/ccapi/common/win/win-utils.c130
-rw-r--r--src/ccapi/common/win/win-utils.h108
-rw-r--r--src/ccapi/doc/CCAPI-Windows-Design.html296
-rw-r--r--src/ccapi/lib/ccapi_ccache.c55
-rw-r--r--src/ccapi/lib/ccapi_ccache.h7
-rw-r--r--src/ccapi/lib/ccapi_ccache_iterator.c49
-rw-r--r--src/ccapi/lib/ccapi_ccache_iterator.h6
-rw-r--r--src/ccapi/lib/ccapi_context.c3
-rw-r--r--src/ccapi/lib/ccapi_credentials.c6
-rw-r--r--src/ccapi/lib/ccapi_credentials_iterator.c43
-rw-r--r--src/ccapi/lib/ccapi_credentials_iterator.h6
-rw-r--r--src/ccapi/lib/ccapi_v2.c753
-rw-r--r--src/ccapi/lib/mac/ccapi_os_ipc.c27
-rw-r--r--src/ccapi/lib/win/OldCC/ccapi.h568
-rw-r--r--src/ccapi/lib/win/OldCC/client.cxx778
-rw-r--r--src/ccapi/lib/win/OldCC/client.h122
-rw-r--r--src/ccapi/lib/win/OldCC/rpc.cxx156
-rw-r--r--src/ccapi/lib/win/ccapi.def76
-rw-r--r--src/ccapi/lib/win/ccapi_os_ipc.cxx744
-rw-r--r--src/ccapi/lib/win/ccs_reply_proc.c196
-rw-r--r--src/ccapi/lib/win/dllmain.cxx558
-rw-r--r--src/ccapi/lib/win/dllmain.h88
-rw-r--r--src/ccapi/server/ccs_credentials.c6
-rw-r--r--src/ccapi/server/win/WorkQueue.h90
-rw-r--r--src/ccapi/server/win/ccs_os_pipe.c128
-rw-r--r--src/ccapi/server/win/ccs_request_proc.c230
-rw-r--r--src/ccapi/server/win/ccs_win_pipe.c326
-rw-r--r--src/ccapi/server/win/ccs_win_pipe.h136
-rw-r--r--src/ccapi/server/win/workitem.h94
-rw-r--r--src/ccapi/test/Makefile.w32148
-rw-r--r--src/ccapi/test/pingtest.c216
-rw-r--r--src/ccapi/test/simple_lock_test.c166
-rw-r--r--src/plugins/kdb/db2/libdb2/btree/bt_debug.c3
-rw-r--r--src/plugins/kdb/db2/libdb2/btree/bt_split.c4
-rw-r--r--src/plugins/kdb/db2/libdb2/mpool/mpool.c2
-rw-r--r--src/plugins/kdb/db2/libdb2/test/run.test162
-rwxr-xr-xsrc/util/find-missing-eol-prop8
-rwxr-xr-xsrc/util/fix-eol-prop13
-rw-r--r--src/windows/build/bkw-automation.html29
-rw-r--r--src/windows/build/bkw.pl10
-rw-r--r--src/windows/identity/config/Makefile.w2k4
-rw-r--r--src/windows/identity/config/Makefile.w324
66 files changed, 6452 insertions, 5052 deletions
diff --git a/src/ccapi/common/cci_cred_union.c b/src/ccapi/common/cci_cred_union.c
index 55da1e2..902013d 100644
--- a/src/ccapi/common/cci_cred_union.c
+++ b/src/ccapi/common/cci_cred_union.c
@@ -594,7 +594,7 @@ static cc_uint32 cci_credentials_v5_write (cc_credentials_v5_t *in_v5creds,
/* ------------------------------------------------------------------------ */
-cc_uint32 cci_cred_union_release (cc_credentials_union *io_cred_union)
+cc_uint32 cci_credentials_union_release (cc_credentials_union *io_cred_union)
{
cc_int32 err = ccNoError;
@@ -614,31 +614,31 @@ cc_uint32 cci_cred_union_release (cc_credentials_union *io_cred_union)
/* ------------------------------------------------------------------------ */
-cc_uint32 cci_cred_union_read (cc_credentials_union **out_credentials_union,
- cci_stream_t io_stream)
+cc_uint32 cci_credentials_union_read (cc_credentials_union **out_credentials_union,
+ cci_stream_t io_stream)
{
cc_int32 err = ccNoError;
- cc_credentials_union *cred_union = NULL;
+ cc_credentials_union *credentials_union = NULL;
if (!io_stream ) { err = cci_check_error (ccErrBadParam); }
if (!out_credentials_union) { err = cci_check_error (ccErrBadParam); }
if (!err) {
- cred_union = malloc (sizeof (*cred_union));
- if (!cred_union) { err = cci_check_error (ccErrNoMem); }
+ credentials_union = calloc (1, sizeof (*credentials_union));
+ if (!credentials_union) { err = cci_check_error (ccErrNoMem); }
}
if (!err) {
- err = cci_stream_read_uint32 (io_stream, &cred_union->version);
+ err = cci_stream_read_uint32 (io_stream, &credentials_union->version);
}
if (!err) {
- if (cred_union->version == cc_credentials_v4) {
- err = cci_credentials_v4_read (&cred_union->credentials.credentials_v4,
+ if (credentials_union->version == cc_credentials_v4) {
+ err = cci_credentials_v4_read (&credentials_union->credentials.credentials_v4,
io_stream);
- } else if (cred_union->version == cc_credentials_v5) {
- err = cci_credentials_v5_read (&cred_union->credentials.credentials_v5,
+ } else if (credentials_union->version == cc_credentials_v5) {
+ err = cci_credentials_v5_read (&credentials_union->credentials.credentials_v5,
io_stream);
@@ -648,19 +648,19 @@ cc_uint32 cci_cred_union_read (cc_credentials_union **out_credentials_union,
}
if (!err) {
- *out_credentials_union = cred_union;
- cred_union = NULL;
+ *out_credentials_union = credentials_union;
+ credentials_union = NULL;
}
- if (cred_union) { cci_cred_union_release (cred_union); }
+ if (credentials_union) { cci_credentials_union_release (credentials_union); }
return cci_check_error (err);
}
/* ------------------------------------------------------------------------ */
-cc_uint32 cci_cred_union_write (const cc_credentials_union *in_credentials_union,
- cci_stream_t io_stream)
+cc_uint32 cci_credentials_union_write (const cc_credentials_union *in_credentials_union,
+ cci_stream_t io_stream)
{
cc_int32 err = ccNoError;
@@ -687,3 +687,413 @@ cc_uint32 cci_cred_union_write (const cc_credentials_union *in_credentials_union
return cci_check_error (err);
}
+
+#ifdef TARGET_OS_MAC
+#pragma mark -
+#pragma mark -- CCAPI v2 Compat --
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+cc_credentials_v5_compat cci_credentials_v5_compat_initializer = {
+ NULL,
+ NULL,
+ { 0, 0, NULL },
+ 0, 0, 0, 0, 0, 0,
+ NULL,
+ { 0, 0, NULL },
+ { 0, 0, NULL },
+ NULL
+};
+
+/* ------------------------------------------------------------------------ */
+
+cc_uint32 cci_cred_union_release (cred_union *io_cred_union)
+{
+ cc_int32 err = ccNoError;
+
+ if (!io_cred_union) { err = ccErrBadParam; }
+
+ if (!err) {
+ if (io_cred_union->cred_type == CC_CRED_V4) {
+ memset (io_cred_union->cred.pV4Cred, 0, sizeof (cc_credentials_v4_compat));
+ free (io_cred_union->cred.pV4Cred);
+
+ } else if (io_cred_union->cred_type == CC_CRED_V5) {
+ free (io_cred_union->cred.pV5Cred->client);
+ free (io_cred_union->cred.pV5Cred->server);
+ cci_cc_data_contents_release (&io_cred_union->cred.pV5Cred->keyblock);
+ cci_cc_data_array_release (io_cred_union->cred.pV5Cred->addresses);
+ cci_cc_data_contents_release (&io_cred_union->cred.pV5Cred->ticket);
+ cci_cc_data_contents_release (&io_cred_union->cred.pV5Cred->second_ticket);
+ cci_cc_data_array_release (io_cred_union->cred.pV5Cred->authdata);
+ free (io_cred_union->cred.pV5Cred);
+ }
+ free (io_cred_union);
+ }
+
+ return err;
+}
+
+/* ------------------------------------------------------------------------ */
+
+static cc_uint32 cci_cc_data_copy_contents (cc_data *io_ccdata,
+ cc_data *in_ccdata)
+{
+ cc_int32 err = ccNoError;
+ char *data = NULL;
+
+ if (!io_ccdata) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccdata) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err && in_ccdata->length > 0) {
+ data = malloc (in_ccdata->length);
+ if (data) {
+ memcpy (data, in_ccdata->data, in_ccdata->length);
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+ }
+
+ if (!err) {
+ io_ccdata->type = in_ccdata->type;
+ io_ccdata->length = in_ccdata->length;
+ io_ccdata->data = data;
+ data = NULL;
+ }
+
+ free (data);
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+static cc_uint32 cci_cc_data_array_copy (cc_data ***io_ccdata_array,
+ cc_data **in_ccdata_array)
+{
+ cc_int32 err = ccNoError;
+ cc_uint32 count = 0;
+ cc_data **array = NULL;
+ cc_uint32 i;
+
+ if (!io_ccdata_array) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ for (count = 0; in_ccdata_array && in_ccdata_array[count]; count++);
+ }
+
+ if (!err && count > 0) {
+ array = malloc ((count + 1) * sizeof (*array));
+ if (array) {
+ for (i = 0; i <= count; i++) { array[i] = NULL; }
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+ }
+
+ if (!err) {
+ for (i = 0; !err && i < count; i++) {
+ array[i] = malloc (sizeof (cc_data));
+ if (!array[i]) { err = cci_check_error (ccErrNoMem); }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (array[i], in_ccdata_array[i]);
+ }
+ }
+ }
+
+ if (!err) {
+ *io_ccdata_array = array;
+ array = NULL;
+ }
+
+ cci_cc_data_array_release (array);
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_uint32 cci_credentials_union_to_cred_union (const cc_credentials_union *in_credentials_union,
+ cred_union **out_cred_union)
+{
+ cc_int32 err = ccNoError;
+ cred_union *compat_cred_union = NULL;
+
+ if (!in_credentials_union) { err = cci_check_error (ccErrBadParam); }
+ if (!out_cred_union ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ compat_cred_union = calloc (1, sizeof (*compat_cred_union));
+ if (!compat_cred_union) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ if (in_credentials_union->version == cc_credentials_v4) {
+ cc_credentials_v4_compat *compat_v4creds = NULL;
+
+ compat_v4creds = malloc (sizeof (*compat_v4creds));
+ if (!compat_v4creds) { err = cci_check_error (ccErrNoMem); }
+
+ if (!err) {
+ cc_credentials_v4_t *v4creds = in_credentials_union->credentials.credentials_v4;
+
+ compat_cred_union->cred_type = CC_CRED_V4;
+ compat_cred_union->cred.pV4Cred = compat_v4creds;
+
+ compat_v4creds->kversion = v4creds->version;
+ strncpy (compat_v4creds->principal, v4creds->principal, KRB_NAME_SZ+1);
+ strncpy (compat_v4creds->principal_instance, v4creds->principal_instance, KRB_INSTANCE_SZ+1);
+ strncpy (compat_v4creds->service, v4creds->service, KRB_NAME_SZ+1);
+ strncpy (compat_v4creds->service_instance, v4creds->service_instance, KRB_INSTANCE_SZ+1);
+ strncpy (compat_v4creds->realm, v4creds->realm, KRB_REALM_SZ+1);
+ memcpy (compat_v4creds->session_key, v4creds->session_key, 8);
+ compat_v4creds->kvno = v4creds->kvno;
+ compat_v4creds->str_to_key = v4creds->string_to_key_type;
+ compat_v4creds->issue_date = v4creds->issue_date;
+ compat_v4creds->lifetime = v4creds->lifetime;
+ compat_v4creds->address = v4creds->address;
+ compat_v4creds->ticket_sz = v4creds->ticket_size;
+ memcpy (compat_v4creds->ticket, v4creds->ticket, MAX_V4_CRED_LEN);
+ compat_v4creds->oops = 0;
+ }
+
+ } else if (in_credentials_union->version == cc_credentials_v5) {
+ cc_credentials_v5_t *v5creds = in_credentials_union->credentials.credentials_v5;
+ cc_credentials_v5_compat *compat_v5creds = NULL;
+
+ compat_v5creds = malloc (sizeof (*compat_v5creds));
+ if (compat_v5creds) {
+ *compat_v5creds = cci_credentials_v5_compat_initializer;
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+
+ if (!err) {
+ compat_v5creds->client = strdup (v5creds->client);
+ if (!compat_v5creds->client) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ compat_v5creds->server = strdup (v5creds->server);
+ if (!compat_v5creds->server) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&compat_v5creds->keyblock, &v5creds->keyblock);
+ }
+
+ if (!err) {
+ err = cci_cc_data_array_copy (&compat_v5creds->addresses, v5creds->addresses);
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&compat_v5creds->ticket, &v5creds->ticket);
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&compat_v5creds->second_ticket, &v5creds->second_ticket);
+ }
+
+ if (!err) {
+ err = cci_cc_data_array_copy (&compat_v5creds->authdata, v5creds->authdata);
+ }
+
+ if (!err) {
+ compat_cred_union->cred_type = CC_CRED_V5;
+ compat_cred_union->cred.pV5Cred = compat_v5creds;
+
+ compat_v5creds->keyblock = v5creds->keyblock;
+ compat_v5creds->authtime = v5creds->authtime;
+ compat_v5creds->starttime = v5creds->starttime;
+ compat_v5creds->endtime = v5creds->endtime;
+ compat_v5creds->renew_till = v5creds->renew_till;
+ compat_v5creds->is_skey = v5creds->is_skey;
+ compat_v5creds->ticket_flags = v5creds->ticket_flags;
+ }
+ } else {
+ err = cci_check_error (ccErrBadCredentialsVersion);
+ }
+ }
+
+ if (!err) {
+ *out_cred_union = compat_cred_union;
+ compat_cred_union = NULL;
+ }
+
+ if (compat_cred_union) { cci_cred_union_release (compat_cred_union); }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_uint32 cci_cred_union_to_credentials_union (const cred_union *in_cred_union,
+ cc_credentials_union **out_credentials_union)
+{
+ cc_int32 err = ccNoError;
+ cc_credentials_union *creds_union = NULL;
+
+ if (!in_cred_union ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_credentials_union) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ creds_union = calloc (1, sizeof (*creds_union));
+ if (!creds_union) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ if (in_cred_union->cred_type == CC_CRED_V4) {
+ cc_credentials_v4_compat *compat_v4creds = in_cred_union->cred.pV4Cred;
+ cc_credentials_v4_t *v4creds = NULL;
+
+ if (!err) {
+ v4creds = malloc (sizeof (*v4creds));
+ if (!v4creds) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ creds_union->version = cc_credentials_v4;
+ creds_union->credentials.credentials_v4 = v4creds;
+
+ v4creds->version = compat_v4creds->kversion;
+ strncpy (v4creds->principal, compat_v4creds->principal, KRB_NAME_SZ);
+ strncpy (v4creds->principal_instance, compat_v4creds->principal_instance, KRB_INSTANCE_SZ);
+ strncpy (v4creds->service, compat_v4creds->service, KRB_NAME_SZ);
+ strncpy (v4creds->service_instance, compat_v4creds->service_instance, KRB_INSTANCE_SZ);
+ strncpy (v4creds->realm, compat_v4creds->realm, KRB_REALM_SZ);
+ memcpy (v4creds->session_key, compat_v4creds->session_key, 8);
+ v4creds->kvno = compat_v4creds->kvno;
+ v4creds->string_to_key_type = compat_v4creds->str_to_key;
+ v4creds->issue_date = compat_v4creds->issue_date;
+ v4creds->lifetime = compat_v4creds->lifetime;
+ v4creds->address = compat_v4creds->address;
+ v4creds->ticket_size = compat_v4creds->ticket_sz;
+ memcpy (v4creds->ticket, compat_v4creds->ticket, MAX_V4_CRED_LEN);
+ }
+
+ } else if (in_cred_union->cred_type == CC_CRED_V5) {
+ cc_credentials_v5_compat *compat_v5creds = in_cred_union->cred.pV5Cred;
+ cc_credentials_v5_t *v5creds = NULL;
+
+ if (!err) {
+ v5creds = malloc (sizeof (*v5creds));
+ if (v5creds) {
+ *v5creds = cci_credentials_v5_initializer;
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+ }
+
+ if (!err) {
+ v5creds->client = strdup (compat_v5creds->client);
+ if (!v5creds->client) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ v5creds->server = strdup (compat_v5creds->server);
+ if (!v5creds->server) { err = cci_check_error (ccErrNoMem); }
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&v5creds->keyblock, &compat_v5creds->keyblock);
+ }
+
+ if (!err) {
+ err = cci_cc_data_array_copy (&v5creds->addresses, compat_v5creds->addresses);
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&v5creds->ticket, &compat_v5creds->ticket);
+ }
+
+ if (!err) {
+ err = cci_cc_data_copy_contents (&v5creds->second_ticket, &compat_v5creds->second_ticket);
+ }
+
+ if (!err) {
+ err = cci_cc_data_array_copy (&v5creds->authdata, compat_v5creds->authdata);
+ }
+
+ if (!err) {
+ creds_union->version = cc_credentials_v5;
+ creds_union->credentials.credentials_v5 = v5creds;
+
+ v5creds->authtime = compat_v5creds->authtime;
+ v5creds->starttime = compat_v5creds->starttime;
+ v5creds->endtime = compat_v5creds->endtime;
+ v5creds->renew_till = compat_v5creds->renew_till;
+ v5creds->is_skey = compat_v5creds->is_skey;
+ v5creds->ticket_flags = compat_v5creds->ticket_flags;
+ }
+
+ } else {
+ err = cci_check_error (ccErrBadCredentialsVersion);
+ }
+ }
+
+ if (!err) {
+ *out_credentials_union = creds_union;
+ creds_union = NULL;
+ }
+
+ if (creds_union) { cci_credentials_union_release (creds_union); }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_uint32 cci_cred_union_compare_to_credentials_union (const cred_union *in_cred_union_compat,
+ const cc_credentials_union *in_credentials_union,
+ cc_uint32 *out_equal)
+{
+ cc_int32 err = ccNoError;
+ cc_uint32 equal = 0;
+
+ if (!in_cred_union_compat) { err = cci_check_error (ccErrBadParam); }
+ if (!in_credentials_union) { err = cci_check_error (ccErrBadParam); }
+ if (!out_equal ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ if (in_cred_union_compat->cred_type == CC_CRED_V4 &&
+ in_credentials_union->version == cc_credentials_v4) {
+ cc_credentials_v4_compat *old_creds_v4 = in_cred_union_compat->cred.pV4Cred;
+ cc_credentials_v4_t *new_creds_v4 = in_credentials_union->credentials.credentials_v4;
+
+ if (old_creds_v4 && new_creds_v4 &&
+ !strcmp (old_creds_v4->principal,
+ new_creds_v4->principal) &&
+ !strcmp (old_creds_v4->principal_instance,
+ new_creds_v4->principal_instance) &&
+ !strcmp (old_creds_v4->service,
+ new_creds_v4->service) &&
+ !strcmp (old_creds_v4->service_instance,
+ new_creds_v4->service_instance) &&
+ !strcmp (old_creds_v4->realm, new_creds_v4->realm) &&
+ (old_creds_v4->issue_date == (long) new_creds_v4->issue_date)) {
+ equal = 1;
+ }
+
+ } else if (in_cred_union_compat->cred_type == CC_CRED_V5 &&
+ in_credentials_union->version == cc_credentials_v5) {
+ cc_credentials_v5_compat *old_creds_v5 = in_cred_union_compat->cred.pV5Cred;
+ cc_credentials_v5_t *new_creds_v5 = in_credentials_union->credentials.credentials_v5;
+
+ /* Really should use krb5_parse_name and krb5_principal_compare */
+ if (old_creds_v5 && new_creds_v5 &&
+ !strcmp (old_creds_v5->client, new_creds_v5->client) &&
+ !strcmp (old_creds_v5->server, new_creds_v5->server) &&
+ (old_creds_v5->starttime == new_creds_v5->starttime)) {
+ return 1;
+ }
+ }
+ }
+
+ if (!err) {
+ *out_equal = equal;
+ }
+
+ return cci_check_error (err);
+}
diff --git a/src/ccapi/common/cci_cred_union.h b/src/ccapi/common/cci_cred_union.h
index f734d6a..3264d35 100644
--- a/src/ccapi/common/cci_cred_union.h
+++ b/src/ccapi/common/cci_cred_union.h
@@ -28,14 +28,26 @@
#define CCI_CRED_UNION_H
#include "cci_types.h"
+#include <CredentialsCache2.h>
-cc_uint32 cci_cred_union_release (cc_credentials_union *io_credentials);
+cc_uint32 cci_credentials_union_release (cc_credentials_union *io_credentials);
-cc_uint32 cci_cred_union_read (cc_credentials_union **out_credentials_union,
- cci_stream_t io_stream);
+cc_uint32 cci_credentials_union_read (cc_credentials_union **out_credentials_union,
+ cci_stream_t io_stream);
-cc_uint32 cci_cred_union_write (const cc_credentials_union *in_credentials_union,
- cci_stream_t io_stream);
+cc_uint32 cci_credentials_union_write (const cc_credentials_union *in_credentials_union,
+ cci_stream_t io_stream);
+cc_uint32 cci_cred_union_release (cred_union *io_cred_union);
+
+cc_uint32 cci_credentials_union_to_cred_union (const cc_credentials_union *in_credentials_union,
+ cred_union **out_cred_union);
+
+cc_uint32 cci_cred_union_to_credentials_union (const cred_union *in_cred_union,
+ cc_credentials_union **out_credentials_union);
+
+cc_uint32 cci_cred_union_compare_to_credentials_union (const cred_union *in_cred_union_compat,
+ const cc_credentials_union *in_credentials_union,
+ cc_uint32 *out_equal);
#endif /* CCI_CRED_UNION_H */
diff --git a/src/ccapi/common/win/OldCC/autolock.hxx b/src/ccapi/common/win/OldCC/autolock.hxx
index 9fc7595..bbd7734 100644
--- a/src/ccapi/common/win/OldCC/autolock.hxx
+++ b/src/ccapi/common/win/OldCC/autolock.hxx
@@ -1,53 +1,53 @@
-/*
-
- Copyright (C) 1998 Danilo Almeida. All rights reserved.
-
- automatic stack-based locking object
-
- This file is part of FIFS (Framework for Implementing File Systems).
-
- This software is distributed with NO WARRANTY OF ANY KIND. No
- author or distributor accepts any responsibility for the
- consequences of using it, or for whether it serves any particular
- purpose or works at all, unless he or she says so in writing.
- Refer to the included modified Alladin Free Public License (the
- "License") for full details.
-
- Every copy of this software must include a copy of the License, in
- a plain ASCII text file named COPYING. The License grants you the
- right to copy, modify and redistribute this software, but only
- under certain conditions described in the License. Among other
- things, the License requires that the copyright notice and this
- notice be preserved on all copies.
-
-*/
-
-#ifndef __AUTOLOCK_HXX__
-#define __AUTOLOCK_HXX__
-
-#include <windows.h>
-
-class CcOsLock {
- CRITICAL_SECTION cs;
- bool valid;
-public:
- CcOsLock() {InitializeCriticalSection(&cs); valid = true; }
- ~CcOsLock() {DeleteCriticalSection(&cs); valid = false;}
- void lock() {if (valid) EnterCriticalSection(&cs);}
- void unlock() {if (valid) LeaveCriticalSection(&cs);}
-#if 0
- bool trylock() {return valid ? (TryEnterCriticalSection(&cs) ? true : false)
- : false; }
-#endif
-};
-
-class CcAutoLock {
- CcOsLock& m_lock;
-public:
- static void Start(CcAutoLock*& a, CcOsLock& lock) { a = new CcAutoLock(lock); };
- static void Stop (CcAutoLock*& a) { delete a; a = 0; };
- CcAutoLock(CcOsLock& lock):m_lock(lock) { m_lock.lock(); }
- ~CcAutoLock() { m_lock.unlock(); }
-};
-
-#endif /* __AUTOLOCK_HXX */
+/*
+
+ Copyright (C) 1998 Danilo Almeida. All rights reserved.
+
+ automatic stack-based locking object
+
+ This file is part of FIFS (Framework for Implementing File Systems).
+
+ This software is distributed with NO WARRANTY OF ANY KIND. No
+ author or distributor accepts any responsibility for the
+ consequences of using it, or for whether it serves any particular
+ purpose or works at all, unless he or she says so in writing.
+ Refer to the included modified Alladin Free Public License (the
+ "License") for full details.
+
+ Every copy of this software must include a copy of the License, in
+ a plain ASCII text file named COPYING. The License grants you the
+ right to copy, modify and redistribute this software, but only
+ under certain conditions described in the License. Among other
+ things, the License requires that the copyright notice and this
+ notice be preserved on all copies.
+
+*/
+
+#ifndef __AUTOLOCK_HXX__
+#define __AUTOLOCK_HXX__
+
+#include <windows.h>
+
+class CcOsLock {
+ CRITICAL_SECTION cs;
+ bool valid;
+public:
+ CcOsLock() {InitializeCriticalSection(&cs); valid = true; }
+ ~CcOsLock() {DeleteCriticalSection(&cs); valid = false;}
+ void lock() {if (valid) EnterCriticalSection(&cs);}
+ void unlock() {if (valid) LeaveCriticalSection(&cs);}
+#if 0
+ bool trylock() {return valid ? (TryEnterCriticalSection(&cs) ? true : false)
+ : false; }
+#endif
+};
+
+class CcAutoLock {
+ CcOsLock& m_lock;
+public:
+ static void Start(CcAutoLock*& a, CcOsLock& lock) { a = new CcAutoLock(lock); };
+ static void Stop (CcAutoLock*& a) { delete a; a = 0; };
+ CcAutoLock(CcOsLock& lock):m_lock(lock) { m_lock.lock(); }
+ ~CcAutoLock() { m_lock.unlock(); }
+};
+
+#endif /* __AUTOLOCK_HXX */
diff --git a/src/ccapi/common/win/OldCC/ccutil.cxx b/src/ccapi/common/win/OldCC/ccutil.cxx
index e5e5bae..729104d 100644
--- a/src/ccapi/common/win/OldCC/ccutil.cxx
+++ b/src/ccapi/common/win/OldCC/ccutil.cxx
@@ -1,187 +1,187 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include "init.hxx"
-#include "secure.hxx"
-
-extern "C" {
-#include "cci_debugging.h"
- }
-
-
-CcOsLock Init::s_lock;
-DWORD Init::s_refcount = 0;
-DWORD Init::s_error = ERROR_INVALID_HANDLE;
-bool Init::s_init = false;
-Init::InitInfo Init::s_info = { 0 };
-HINSTANCE Init::s_hRpcDll = 0;
-
-#define INIT "INIT: "
-
-static
-void
-ShowInfo(
- Init::InitInfo& info
- );
-
-DWORD
-Init::Info(
- InitInfo& info
- )
-{
- // This funciton will not do automatic initialization.
- CcAutoLock AL(s_lock);
- if (!s_init) {
- memset(&info, 0, sizeof(info));
- return s_error ? s_error : ERROR_INVALID_HANDLE;
- } else {
- info = s_info;
- return 0;
- }
-}
-
-DWORD
-Init::Initialize() {
- CcAutoLock AL(s_lock);
- cci_debug_printf("%s s_init:%d", __FUNCTION__, s_init);
- if (s_init) {
- s_refcount++;
- return 0;
- }
- SecureClient s;
- DWORD status = 0;
- OSVERSIONINFO osvi;
- BOOL isSupportedVersion = FALSE;
- memset(&s_info, 0, sizeof(s_info));
- memset(&osvi, 0, sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
-
- if (!status) {
- switch(osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_WINDOWS:
- s_info.isNT = FALSE;
- isSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32_NT:
- s_info.isNT = TRUE;
- isSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32s:
- default:
- s_info.isNT = FALSE;
- break;
- }
-
- if (!isSupportedVersion) {
- cci_debug_printf("%s Trying to run on an unsupported version of Windows", __FUNCTION__);
- status = 1;
- }
- }
-
- if (!status) {status = !s_info.isNT;}
-
- if (!status) {status = !(s_hRpcDll = LoadLibrary(TEXT("rpcrt4.dll")));}
-
- if (!status) {
- s_info.fRpcBindingSetAuthInfoEx = (FP_RpcBindingSetAuthInfoEx)
- GetProcAddress(s_hRpcDll, TEXT(FN_RpcBindingSetAuthInfoEx));
- if (!s_info.fRpcBindingSetAuthInfoEx) {
- cci_debug_printf(" Running on NT but could not find RpcBindinSetAuthInfoEx");
- status = 1;
- }
- }
-
- if (!status) {
- s_info.fRpcServerRegisterIfEx = (FP_RpcServerRegisterIfEx)
- GetProcAddress(s_hRpcDll, TEXT(FN_RpcServerRegisterIfEx));
- if (!s_info.fRpcServerRegisterIfEx) {
- cci_debug_printf(" Running on NT but could not find RpcServerRegisterIfEx");
- status = 1;
- }
- }
-
- if (!status) {
- status = SecureClient::Attach();
- if (status) {
- cci_debug_printf(" SecureClient::Attach() failed (%u)", status);
- }
- }
-
- if (status) {
- memset(&s_info, 0, sizeof(s_info));
- if (s_hRpcDll) {
- FreeLibrary(s_hRpcDll);
- s_hRpcDll = 0;
- }
- cci_debug_printf(" Init::Attach() failed (%u)", status);
- } else {
- s_refcount++;
- s_init = true;
- ShowInfo(s_info);
- }
- s_error = status;
- return status;
-}
-
-DWORD
-Init::Cleanup(
- )
-{
- CcAutoLock AL(s_lock);
- s_refcount--;
- if (s_refcount) return 0;
- if (!s_init) return 0;
- DWORD error = 0;
- if (s_hRpcDll) {
- FreeLibrary(s_hRpcDll);
- s_hRpcDll = 0;
- }
- error = SecureClient::Detach();
- memset(&s_info, 0, sizeof(s_info));
- s_init = false;
- s_error = 0;
- if (error) {
- cci_debug_printf(" Init::Detach() had an error (%u)", error);
- }
- return error;
-}
-
-static
-void
-ShowInfo(
- Init::InitInfo& info
- )
-{
- if (info.isNT) {
- cci_debug_printf(" Running on Windows NT using secure mode");
- } else {
- cci_debug_printf(" Running insecurely on non-NT Windows");
- }
- return;
-}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include "init.hxx"
+#include "secure.hxx"
+
+extern "C" {
+#include "cci_debugging.h"
+ }
+
+
+CcOsLock Init::s_lock;
+DWORD Init::s_refcount = 0;
+DWORD Init::s_error = ERROR_INVALID_HANDLE;
+bool Init::s_init = false;
+Init::InitInfo Init::s_info = { 0 };
+HINSTANCE Init::s_hRpcDll = 0;
+
+#define INIT "INIT: "
+
+static
+void
+ShowInfo(
+ Init::InitInfo& info
+ );
+
+DWORD
+Init::Info(
+ InitInfo& info
+ )
+{
+ // This funciton will not do automatic initialization.
+ CcAutoLock AL(s_lock);
+ if (!s_init) {
+ memset(&info, 0, sizeof(info));
+ return s_error ? s_error : ERROR_INVALID_HANDLE;
+ } else {
+ info = s_info;
+ return 0;
+ }
+}
+
+DWORD
+Init::Initialize() {
+ CcAutoLock AL(s_lock);
+ cci_debug_printf("%s s_init:%d", __FUNCTION__, s_init);
+ if (s_init) {
+ s_refcount++;
+ return 0;
+ }
+ SecureClient s;
+ DWORD status = 0;
+ OSVERSIONINFO osvi;
+ BOOL isSupportedVersion = FALSE;
+ memset(&s_info, 0, sizeof(s_info));
+ memset(&osvi, 0, sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
+
+ if (!status) {
+ switch(osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ s_info.isNT = FALSE;
+ isSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32_NT:
+ s_info.isNT = TRUE;
+ isSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32s:
+ default:
+ s_info.isNT = FALSE;
+ break;
+ }
+
+ if (!isSupportedVersion) {
+ cci_debug_printf("%s Trying to run on an unsupported version of Windows", __FUNCTION__);
+ status = 1;
+ }
+ }
+
+ if (!status) {status = !s_info.isNT;}
+
+ if (!status) {status = !(s_hRpcDll = LoadLibrary(TEXT("rpcrt4.dll")));}
+
+ if (!status) {
+ s_info.fRpcBindingSetAuthInfoEx = (FP_RpcBindingSetAuthInfoEx)
+ GetProcAddress(s_hRpcDll, TEXT(FN_RpcBindingSetAuthInfoEx));
+ if (!s_info.fRpcBindingSetAuthInfoEx) {
+ cci_debug_printf(" Running on NT but could not find RpcBindinSetAuthInfoEx");
+ status = 1;
+ }
+ }
+
+ if (!status) {
+ s_info.fRpcServerRegisterIfEx = (FP_RpcServerRegisterIfEx)
+ GetProcAddress(s_hRpcDll, TEXT(FN_RpcServerRegisterIfEx));
+ if (!s_info.fRpcServerRegisterIfEx) {
+ cci_debug_printf(" Running on NT but could not find RpcServerRegisterIfEx");
+ status = 1;
+ }
+ }
+
+ if (!status) {
+ status = SecureClient::Attach();
+ if (status) {
+ cci_debug_printf(" SecureClient::Attach() failed (%u)", status);
+ }
+ }
+
+ if (status) {
+ memset(&s_info, 0, sizeof(s_info));
+ if (s_hRpcDll) {
+ FreeLibrary(s_hRpcDll);
+ s_hRpcDll = 0;
+ }
+ cci_debug_printf(" Init::Attach() failed (%u)", status);
+ } else {
+ s_refcount++;
+ s_init = true;
+ ShowInfo(s_info);
+ }
+ s_error = status;
+ return status;
+}
+
+DWORD
+Init::Cleanup(
+ )
+{
+ CcAutoLock AL(s_lock);
+ s_refcount--;
+ if (s_refcount) return 0;
+ if (!s_init) return 0;
+ DWORD error = 0;
+ if (s_hRpcDll) {
+ FreeLibrary(s_hRpcDll);
+ s_hRpcDll = 0;
+ }
+ error = SecureClient::Detach();
+ memset(&s_info, 0, sizeof(s_info));
+ s_init = false;
+ s_error = 0;
+ if (error) {
+ cci_debug_printf(" Init::Detach() had an error (%u)", error);
+ }
+ return error;
+}
+
+static
+void
+ShowInfo(
+ Init::InitInfo& info
+ )
+{
+ if (info.isNT) {
+ cci_debug_printf(" Running on Windows NT using secure mode");
+ } else {
+ cci_debug_printf(" Running insecurely on non-NT Windows");
+ }
+ return;
+}
diff --git a/src/ccapi/common/win/OldCC/ccutil.def b/src/ccapi/common/win/OldCC/ccutil.def
index a187c80..57113f0 100644
--- a/src/ccapi/common/win/OldCC/ccutil.def
+++ b/src/ccapi/common/win/OldCC/ccutil.def
@@ -1,5 +1,5 @@
-;LIBRARY COMERR32
-HEAPSIZE 8192
-
-EXPORTS
+;LIBRARY COMERR32
+HEAPSIZE 8192
+
+EXPORTS
\ No newline at end of file
diff --git a/src/ccapi/common/win/OldCC/ccutils.c b/src/ccapi/common/win/OldCC/ccutils.c
index 1db00b4..bfe1389 100644
--- a/src/ccapi/common/win/OldCC/ccutils.c
+++ b/src/ccapi/common/win/OldCC/ccutils.c
@@ -1,136 +1,136 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-
-#include "cci_debugging.h"
-#include "util.h"
-
-BOOL isNT() {
- OSVERSIONINFO osvi;
- DWORD status = 0;
- BOOL bSupportedVersion = FALSE;
- BOOL bIsNT = FALSE;
-
- memset(&osvi, 0, sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
-
- if (!status) {
- switch(osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_WINDOWS:
- bIsNT = FALSE;
- bSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32_NT:
- bIsNT = TRUE;
- bSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32s:
- default:
- bIsNT = FALSE;
- break;
- }
-
- if (!bSupportedVersion) {
- cci_debug_printf("%s Running on an unsupported version of Windows", __FUNCTION__);
- status = 1;
- }
- }
-
- return (!status && bIsNT && bSupportedVersion);
- }
-
-char* allocEventName(char* uuid_string, char* suffix) {
- LPSTR event_name = NULL;
- cc_int32 err = ccNoError;
-
- event_name = malloc(strlen(uuid_string) + strlen(suffix) + 3);
- if (!event_name) err = cci_check_error(ccErrNoMem);
-
- if (!err) {
- strcpy(event_name, uuid_string);
- strcat(event_name, "_");
- strcat(event_name, suffix);
- }
-
- return event_name;
- }
-
-HANDLE createThreadEvent(char* uuid, char* suffix) {
- LPSTR event_name = NULL;
- HANDLE hEvent = NULL;
- PSECURITY_ATTRIBUTES psa = 0; // Everything having to do with
- SECURITY_ATTRIBUTES sa = { 0 }; // sa, psa, security is copied
- DWORD status = 0; // from the previous implementation.
-
- psa = isNT() ? &sa : 0;
-
- if (isNT()) {
- sa.nLength = sizeof(sa);
- status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
- cci_check_error(status);
- }
-
- if (!status) {
- event_name = allocEventName(uuid, suffix);
- if (!event_name) status = cci_check_error(ccErrNoMem);
- }
- cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
-
- if (!status) {
- hEvent = CreateEvent(psa, FALSE, FALSE, event_name);
- if (!hEvent) status = cci_check_error(GetLastError());
- }
-
- if (!status) ResetEvent(hEvent);
-
-
- if (event_name) free(event_name);
- if (isNT()) free(sa.lpSecurityDescriptor);
-
- return hEvent;
- }
-
-HANDLE openThreadEvent(char* uuid, char* suffix) {
- LPSTR event_name = NULL;
- HANDLE hEvent = NULL;
- DWORD status = 0;
-
- event_name = allocEventName(uuid, suffix);
- if (!event_name) status = cci_check_error(ccErrNoMem);
- cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
-
- if (!status) {
- hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name);
- if (!hEvent) status = cci_check_error(GetLastError());
- }
-
- if (event_name) free(event_name);
-
- return hEvent;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+
+#include "cci_debugging.h"
+#include "util.h"
+
+BOOL isNT() {
+ OSVERSIONINFO osvi;
+ DWORD status = 0;
+ BOOL bSupportedVersion = FALSE;
+ BOOL bIsNT = FALSE;
+
+ memset(&osvi, 0, sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
+
+ if (!status) {
+ switch(osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ bIsNT = FALSE;
+ bSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32_NT:
+ bIsNT = TRUE;
+ bSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32s:
+ default:
+ bIsNT = FALSE;
+ break;
+ }
+
+ if (!bSupportedVersion) {
+ cci_debug_printf("%s Running on an unsupported version of Windows", __FUNCTION__);
+ status = 1;
+ }
+ }
+
+ return (!status && bIsNT && bSupportedVersion);
+ }
+
+char* allocEventName(char* uuid_string, char* suffix) {
+ LPSTR event_name = NULL;
+ cc_int32 err = ccNoError;
+
+ event_name = malloc(strlen(uuid_string) + strlen(suffix) + 3);
+ if (!event_name) err = cci_check_error(ccErrNoMem);
+
+ if (!err) {
+ strcpy(event_name, uuid_string);
+ strcat(event_name, "_");
+ strcat(event_name, suffix);
+ }
+
+ return event_name;
+ }
+
+HANDLE createThreadEvent(char* uuid, char* suffix) {
+ LPSTR event_name = NULL;
+ HANDLE hEvent = NULL;
+ PSECURITY_ATTRIBUTES psa = 0; // Everything having to do with
+ SECURITY_ATTRIBUTES sa = { 0 }; // sa, psa, security is copied
+ DWORD status = 0; // from the previous implementation.
+
+ psa = isNT() ? &sa : 0;
+
+ if (isNT()) {
+ sa.nLength = sizeof(sa);
+ status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ event_name = allocEventName(uuid, suffix);
+ if (!event_name) status = cci_check_error(ccErrNoMem);
+ }
+ cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
+
+ if (!status) {
+ hEvent = CreateEvent(psa, FALSE, FALSE, event_name);
+ if (!hEvent) status = cci_check_error(GetLastError());
+ }
+
+ if (!status) ResetEvent(hEvent);
+
+
+ if (event_name) free(event_name);
+ if (isNT()) free(sa.lpSecurityDescriptor);
+
+ return hEvent;
+ }
+
+HANDLE openThreadEvent(char* uuid, char* suffix) {
+ LPSTR event_name = NULL;
+ HANDLE hEvent = NULL;
+ DWORD status = 0;
+
+ event_name = allocEventName(uuid, suffix);
+ if (!event_name) status = cci_check_error(ccErrNoMem);
+ cci_debug_printf("%s event_name:%s", __FUNCTION__, event_name);
+
+ if (!status) {
+ hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name);
+ if (!hEvent) status = cci_check_error(GetLastError());
+ }
+
+ if (event_name) free(event_name);
+
+ return hEvent;
} \ No newline at end of file
diff --git a/src/ccapi/common/win/OldCC/ccutils.h b/src/ccapi/common/win/OldCC/ccutils.h
index 77cafb1..0734128 100644
--- a/src/ccapi/common/win/OldCC/ccutils.h
+++ b/src/ccapi/common/win/OldCC/ccutils.h
@@ -1,49 +1,49 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __CCUTILS_H__
-#define __CCUTILS_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
-#define REPLY_SUFFIX (char*)"reply"
-#define LISTEN_SUFFIX (char*)"listen"
-
-BOOL isNT();
-char* allocEventName (char* uuid, char* suffix);
-HANDLE createThreadEvent(char* uuid, char* suffix);
-HANDLE openThreadEvent (char* uuid, char* suffix);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __CCUTILS_H__ */
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef __CCUTILS_H__
+#define __CCUTILS_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#if 0
+}
+#endif
+
+#define REPLY_SUFFIX (char*)"reply"
+#define LISTEN_SUFFIX (char*)"listen"
+
+BOOL isNT();
+char* allocEventName (char* uuid, char* suffix);
+HANDLE createThreadEvent(char* uuid, char* suffix);
+HANDLE openThreadEvent (char* uuid, char* suffix);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CCUTILS_H__ */
diff --git a/src/ccapi/common/win/OldCC/init.cxx b/src/ccapi/common/win/OldCC/init.cxx
index af93722..feb7ad3 100644
--- a/src/ccapi/common/win/OldCC/init.cxx
+++ b/src/ccapi/common/win/OldCC/init.cxx
@@ -1,187 +1,187 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include "init.hxx"
-#include "secure.hxx"
-
-extern "C" {
-#include "cci_debugging.h"
- }
-
-
-CcOsLock Init::s_lock;
-DWORD Init::s_refcount = 0;
-DWORD Init::s_error = ERROR_INVALID_HANDLE;
-bool Init::s_init = false;
-Init::InitInfo Init::s_info = { 0 };
-HINSTANCE Init::s_hRpcDll = 0;
-
-#define INIT "INIT: "
-
-static
-void
-ShowInfo(
- Init::InitInfo& info
- );
-
-DWORD
-Init::Info(
- InitInfo& info
- )
-{
- // This funciton will not do automatic initialization.
- CcAutoLock AL(s_lock);
- if (!s_init) {
- memset(&info, 0, sizeof(info));
- return s_error ? s_error : ERROR_INVALID_HANDLE;
- } else {
- info = s_info;
- return 0;
- }
-}
-
-DWORD
-Init::Initialize() {
- CcAutoLock AL(s_lock);
-// cci_debug_printf("%s s_init:%d", __FUNCTION__, s_init);
- if (s_init) {
- s_refcount++;
- return 0;
- }
- SecureClient s;
- DWORD status = 0;
- OSVERSIONINFO osvi;
- BOOL isSupportedVersion = FALSE;
- memset(&s_info, 0, sizeof(s_info));
- memset(&osvi, 0, sizeof(osvi));
- osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-
- status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
-
- if (!status) {
- switch(osvi.dwPlatformId) {
- case VER_PLATFORM_WIN32_WINDOWS:
- s_info.isNT = FALSE;
- isSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32_NT:
- s_info.isNT = TRUE;
- isSupportedVersion = TRUE;
- break;
- case VER_PLATFORM_WIN32s:
- default:
- s_info.isNT = FALSE;
- break;
- }
-
- if (!isSupportedVersion) {
- cci_debug_printf("%s Trying to run on an unsupported version of Windows", __FUNCTION__);
- status = 1;
- }
- }
-
- if (!status) {status = !s_info.isNT;}
-
- if (!status) {status = !(s_hRpcDll = LoadLibrary(TEXT("rpcrt4.dll")));}
-
- if (!status) {
- s_info.fRpcBindingSetAuthInfoEx = (FP_RpcBindingSetAuthInfoEx)
- GetProcAddress(s_hRpcDll, TEXT(FN_RpcBindingSetAuthInfoEx));
- if (!s_info.fRpcBindingSetAuthInfoEx) {
- cci_debug_printf(" Running on NT but could not find RpcBindinSetAuthInfoEx");
- status = 1;
- }
- }
-
- if (!status) {
- s_info.fRpcServerRegisterIfEx = (FP_RpcServerRegisterIfEx)
- GetProcAddress(s_hRpcDll, TEXT(FN_RpcServerRegisterIfEx));
- if (!s_info.fRpcServerRegisterIfEx) {
- cci_debug_printf(" Running on NT but could not find RpcServerRegisterIfEx");
- status = 1;
- }
- }
-
- if (!status) {
- status = SecureClient::Attach();
- if (status) {
- cci_debug_printf(" SecureClient::Attach() failed (%u)", status);
- }
- }
-
- if (status) {
- memset(&s_info, 0, sizeof(s_info));
- if (s_hRpcDll) {
- FreeLibrary(s_hRpcDll);
- s_hRpcDll = 0;
- }
- cci_debug_printf(" Init::Attach() failed (%u)", status);
- } else {
- s_refcount++;
- s_init = true;
- ShowInfo(s_info);
- }
- s_error = status;
- return status;
-}
-
-DWORD
-Init::Cleanup(
- )
-{
- CcAutoLock AL(s_lock);
- s_refcount--;
- if (s_refcount) return 0;
- if (!s_init) return 0;
- DWORD error = 0;
- if (s_hRpcDll) {
- FreeLibrary(s_hRpcDll);
- s_hRpcDll = 0;
- }
- error = SecureClient::Detach();
- memset(&s_info, 0, sizeof(s_info));
- s_init = false;
- s_error = 0;
- if (error) {
- cci_debug_printf(" Init::Detach() had an error (%u)", error);
- }
- return error;
-}
-
-static
-void
-ShowInfo(
- Init::InitInfo& info
- )
-{
- if (info.isNT) {
- cci_debug_printf(" Running on Windows NT using secure mode");
- } else {
- cci_debug_printf(" Running insecurely on non-NT Windows");
- }
- return;
-}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include "init.hxx"
+#include "secure.hxx"
+
+extern "C" {
+#include "cci_debugging.h"
+ }
+
+
+CcOsLock Init::s_lock;
+DWORD Init::s_refcount = 0;
+DWORD Init::s_error = ERROR_INVALID_HANDLE;
+bool Init::s_init = false;
+Init::InitInfo Init::s_info = { 0 };
+HINSTANCE Init::s_hRpcDll = 0;
+
+#define INIT "INIT: "
+
+static
+void
+ShowInfo(
+ Init::InitInfo& info
+ );
+
+DWORD
+Init::Info(
+ InitInfo& info
+ )
+{
+ // This funciton will not do automatic initialization.
+ CcAutoLock AL(s_lock);
+ if (!s_init) {
+ memset(&info, 0, sizeof(info));
+ return s_error ? s_error : ERROR_INVALID_HANDLE;
+ } else {
+ info = s_info;
+ return 0;
+ }
+}
+
+DWORD
+Init::Initialize() {
+ CcAutoLock AL(s_lock);
+// cci_debug_printf("%s s_init:%d", __FUNCTION__, s_init);
+ if (s_init) {
+ s_refcount++;
+ return 0;
+ }
+ SecureClient s;
+ DWORD status = 0;
+ OSVERSIONINFO osvi;
+ BOOL isSupportedVersion = FALSE;
+ memset(&s_info, 0, sizeof(s_info));
+ memset(&osvi, 0, sizeof(osvi));
+ osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
+
+ status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.
+
+ if (!status) {
+ switch(osvi.dwPlatformId) {
+ case VER_PLATFORM_WIN32_WINDOWS:
+ s_info.isNT = FALSE;
+ isSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32_NT:
+ s_info.isNT = TRUE;
+ isSupportedVersion = TRUE;
+ break;
+ case VER_PLATFORM_WIN32s:
+ default:
+ s_info.isNT = FALSE;
+ break;
+ }
+
+ if (!isSupportedVersion) {
+ cci_debug_printf("%s Trying to run on an unsupported version of Windows", __FUNCTION__);
+ status = 1;
+ }
+ }
+
+ if (!status) {status = !s_info.isNT;}
+
+ if (!status) {status = !(s_hRpcDll = LoadLibrary(TEXT("rpcrt4.dll")));}
+
+ if (!status) {
+ s_info.fRpcBindingSetAuthInfoEx = (FP_RpcBindingSetAuthInfoEx)
+ GetProcAddress(s_hRpcDll, TEXT(FN_RpcBindingSetAuthInfoEx));
+ if (!s_info.fRpcBindingSetAuthInfoEx) {
+ cci_debug_printf(" Running on NT but could not find RpcBindinSetAuthInfoEx");
+ status = 1;
+ }
+ }
+
+ if (!status) {
+ s_info.fRpcServerRegisterIfEx = (FP_RpcServerRegisterIfEx)
+ GetProcAddress(s_hRpcDll, TEXT(FN_RpcServerRegisterIfEx));
+ if (!s_info.fRpcServerRegisterIfEx) {
+ cci_debug_printf(" Running on NT but could not find RpcServerRegisterIfEx");
+ status = 1;
+ }
+ }
+
+ if (!status) {
+ status = SecureClient::Attach();
+ if (status) {
+ cci_debug_printf(" SecureClient::Attach() failed (%u)", status);
+ }
+ }
+
+ if (status) {
+ memset(&s_info, 0, sizeof(s_info));
+ if (s_hRpcDll) {
+ FreeLibrary(s_hRpcDll);
+ s_hRpcDll = 0;
+ }
+ cci_debug_printf(" Init::Attach() failed (%u)", status);
+ } else {
+ s_refcount++;
+ s_init = true;
+ ShowInfo(s_info);
+ }
+ s_error = status;
+ return status;
+}
+
+DWORD
+Init::Cleanup(
+ )
+{
+ CcAutoLock AL(s_lock);
+ s_refcount--;
+ if (s_refcount) return 0;
+ if (!s_init) return 0;
+ DWORD error = 0;
+ if (s_hRpcDll) {
+ FreeLibrary(s_hRpcDll);
+ s_hRpcDll = 0;
+ }
+ error = SecureClient::Detach();
+ memset(&s_info, 0, sizeof(s_info));
+ s_init = false;
+ s_error = 0;
+ if (error) {
+ cci_debug_printf(" Init::Detach() had an error (%u)", error);
+ }
+ return error;
+}
+
+static
+void
+ShowInfo(
+ Init::InitInfo& info
+ )
+{
+ if (info.isNT) {
+ cci_debug_printf(" Running on Windows NT using secure mode");
+ } else {
+ cci_debug_printf(" Running insecurely on non-NT Windows");
+ }
+ return;
+}
diff --git a/src/ccapi/common/win/OldCC/init.hxx b/src/ccapi/common/win/OldCC/init.hxx
index f50db77..9bac7f8 100644
--- a/src/ccapi/common/win/OldCC/init.hxx
+++ b/src/ccapi/common/win/OldCC/init.hxx
@@ -1,102 +1,102 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#pragma once
-#include "autolock.hxx"
-#include <rpc.h>
-
-typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExA)(
- IN RPC_BINDING_HANDLE Binding,
- IN unsigned char __RPC_FAR * ServerPrincName,
- IN unsigned long AuthnLevel,
- IN unsigned long AuthnSvc,
- IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
- IN unsigned long AuthzSvc,
- IN RPC_SECURITY_QOS *SecurityQos OPTIONAL
- );
-
-typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExW)(
- IN RPC_BINDING_HANDLE Binding,
- IN unsigned short __RPC_FAR * ServerPrincName,
- IN unsigned long AuthnLevel,
- IN unsigned long AuthnSvc,
- IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
- IN unsigned long AuthzSvc, OPTIONAL
- IN RPC_SECURITY_QOS *SecurityQOS
- );
-
-typedef RPC_STATUS (RPC_ENTRY *FP_RpcServerRegisterIfEx)(
- IN RPC_IF_HANDLE IfSpec,
- IN UUID __RPC_FAR * MgrTypeUuid,
- IN RPC_MGR_EPV __RPC_FAR * MgrEpv,
- IN unsigned int Flags,
- IN unsigned int MaxCalls,
- IN RPC_IF_CALLBACK_FN __RPC_FAR *IfCallback
- );
-
-#ifdef UNICODE
-#define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExW
-#define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExW"
-#else
-#define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExA
-#define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExA"
-#endif
-
-#define FN_RpcServerRegisterIfEx "RpcServerRegisterIfEx"
-
-class Init
-{
-public:
- struct InitInfo {
- BOOL isNT;
- FP_RpcBindingSetAuthInfoEx fRpcBindingSetAuthInfoEx;
- FP_RpcServerRegisterIfEx fRpcServerRegisterIfEx;
- };
-
- static DWORD Initialize();
- static DWORD Cleanup();
- static DWORD Info(InitInfo& info);
-
- static bool Initialized() { return s_init; }
-
-private:
- static CcOsLock s_lock;
- static DWORD s_refcount;
- static DWORD s_error;
- static bool s_init;
- static InitInfo s_info;
- static HINSTANCE s_hRpcDll;
-};
-
-#define INIT_INIT_EX(trap, error) \
-do \
-{ \
- if (!Init::Initialized()) \
- { \
- DWORD rc = Init::Initialize(); \
- if (rc) return (trap) ? (error) : rc; \
- } \
-} while(0)
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#pragma once
+#include "autolock.hxx"
+#include <rpc.h>
+
+typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExA)(
+ IN RPC_BINDING_HANDLE Binding,
+ IN unsigned char __RPC_FAR * ServerPrincName,
+ IN unsigned long AuthnLevel,
+ IN unsigned long AuthnSvc,
+ IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
+ IN unsigned long AuthzSvc,
+ IN RPC_SECURITY_QOS *SecurityQos OPTIONAL
+ );
+
+typedef RPC_STATUS (RPC_ENTRY *FP_RpcBindingSetAuthInfoExW)(
+ IN RPC_BINDING_HANDLE Binding,
+ IN unsigned short __RPC_FAR * ServerPrincName,
+ IN unsigned long AuthnLevel,
+ IN unsigned long AuthnSvc,
+ IN RPC_AUTH_IDENTITY_HANDLE AuthIdentity, OPTIONAL
+ IN unsigned long AuthzSvc, OPTIONAL
+ IN RPC_SECURITY_QOS *SecurityQOS
+ );
+
+typedef RPC_STATUS (RPC_ENTRY *FP_RpcServerRegisterIfEx)(
+ IN RPC_IF_HANDLE IfSpec,
+ IN UUID __RPC_FAR * MgrTypeUuid,
+ IN RPC_MGR_EPV __RPC_FAR * MgrEpv,
+ IN unsigned int Flags,
+ IN unsigned int MaxCalls,
+ IN RPC_IF_CALLBACK_FN __RPC_FAR *IfCallback
+ );
+
+#ifdef UNICODE
+#define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExW
+#define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExW"
+#else
+#define FP_RpcBindingSetAuthInfoEx FP_RpcBindingSetAuthInfoExA
+#define FN_RpcBindingSetAuthInfoEx "RpcBindingSetAuthInfoExA"
+#endif
+
+#define FN_RpcServerRegisterIfEx "RpcServerRegisterIfEx"
+
+class Init
+{
+public:
+ struct InitInfo {
+ BOOL isNT;
+ FP_RpcBindingSetAuthInfoEx fRpcBindingSetAuthInfoEx;
+ FP_RpcServerRegisterIfEx fRpcServerRegisterIfEx;
+ };
+
+ static DWORD Initialize();
+ static DWORD Cleanup();
+ static DWORD Info(InitInfo& info);
+
+ static bool Initialized() { return s_init; }
+
+private:
+ static CcOsLock s_lock;
+ static DWORD s_refcount;
+ static DWORD s_error;
+ static bool s_init;
+ static InitInfo s_info;
+ static HINSTANCE s_hRpcDll;
+};
+
+#define INIT_INIT_EX(trap, error) \
+do \
+{ \
+ if (!Init::Initialized()) \
+ { \
+ DWORD rc = Init::Initialize(); \
+ if (rc) return (trap) ? (error) : rc; \
+ } \
+} while(0)
diff --git a/src/ccapi/common/win/OldCC/name.h b/src/ccapi/common/win/OldCC/name.h
index e0172d6..7b442e0 100644
--- a/src/ccapi/common/win/OldCC/name.h
+++ b/src/ccapi/common/win/OldCC/name.h
@@ -1,38 +1,38 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#pragma once
-
-#ifdef _WIN64
-#define CCAPI_MODULE "krbcc64"
-#else
-#define CCAPI_MODULE "krbcc32"
-#endif
-#define CCAPI_DLL CCAPI_MODULE ".dll"
-#define CCAPI_EXE CCAPI_MODULE "s.exe"
-
-#define CCAPI_DLL "ccapi.dll"
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#pragma once
+
+#ifdef _WIN64
+#define CCAPI_MODULE "krbcc64"
+#else
+#define CCAPI_MODULE "krbcc32"
+#endif
+#define CCAPI_DLL CCAPI_MODULE ".dll"
+#define CCAPI_EXE CCAPI_MODULE "s.exe"
+
+#define CCAPI_DLL "ccapi.dll"
#define CCAPI_EXE "ccapiserver.exe" \ No newline at end of file
diff --git a/src/ccapi/common/win/OldCC/opts.cxx b/src/ccapi/common/win/OldCC/opts.cxx
index c6a40d6..bd5f503 100644
--- a/src/ccapi/common/win/OldCC/opts.cxx
+++ b/src/ccapi/common/win/OldCC/opts.cxx
@@ -1,188 +1,188 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <opts.hxx>
-
-#if 0
-const struct Opts*
-GetOpts(
- )
-{
- bool done = false;
- struct Opts* o;
- if (!(o = new Opts))
- goto cleanup;
- if (!(o->pszString = new char[lstrlenA(opts.pszString) + 1]))
- goto cleanup;
- if (!(o->pszEndpoint = new char[lstrlenA(opts.pszEndpoint) + 1]))
- goto cleanup;
- strcpy(o->pszString, opts.pszString);
- strcpy(o->pszEndpoint, opts.pszEndpoint);
- done = true;
- cleanup:
- if (!done) {
- FreeOpts(o);
- o = 0;
- }
- return o;
-}
-
-void
-FreeOpts(
- struct Opts* o
- )
-{
- if (o) {
- if (o->pszString)
- delete [] o->pszString;
- if (o->pszEndpoint)
- delete [] o->pszEndpoint;
- delete o;
- }
-}
-#endif
-
-bool
-ParseOpts::IsValidOpt(
- char ch
- )
-{
- return (m_ValidOpts[ch % 256] != 0);
-}
-
-void
-ParseOpts::PrintOpt(
- char ch,
- char* text
- )
-{
- if (IsValidOpt(ch))
- fprintf(stderr, " -%c %s\n", ch, text);
-}
-
-void
-ParseOpts::UsageOpts(
- char * program,
- int code
- )
-{
- fprintf(stderr, "Usage: %s [options]\n", program);
- PrintOpt('k', "stop server");
-#ifdef CCAPI_TEST_OPTIONS
- PrintOpt('s', "string");
- PrintOpt('e', "endpoint");
- PrintOpt('m', "maxcalls");
- PrintOpt('n', "mincalls");
- PrintOpt('f', "flag_wait_op");
- PrintOpt('u', "unprotected");
- PrintOpt('b', "use security callback");
-#endif
- PrintOpt('c', "output debug info to console");
- exit(code);
-}
-
-void
-ParseOpts::SetValidOpts(
- char* valid_opts
- )
-{
- memset(m_ValidOpts, 0, sizeof(m_ValidOpts));
- char *p = valid_opts;
- for (p = valid_opts; *p; p++) {
- m_ValidOpts[*p % sizeof(m_ValidOpts)] = 1;
- }
-}
-
-void
-ParseOpts::Parse(
- Opts& opts,
- int argc,
- char **argv
- )
-{
- int i;
- for (i = 1; i < argc; i++) {
- if ((*argv[i] == '-') || (*argv[i] == '/')) {
- char ch = tolower(*(argv[i]+1));
- if (!IsValidOpt(ch))
- UsageOpts(argv[0]);
- switch (ch) {
- case 'k':
- opts.bShutdown = TRUE;
- break;
-#ifdef CCAPI_TEST_OPTIONS
- case 's':
- opts.pszString = argv[++i];
- break;
- case 'e':
- opts.pszEndpoint = argv[++i];
- break;
- case 'm':
- opts.cMaxCalls = (unsigned int) atoi(argv[++i]);
- break;
- case 'n':
- opts.cMinCalls = (unsigned int) atoi(argv[++i]);
- break;
- case 'f':
- opts.fDontWait = (unsigned int) atoi(argv[++i]);
- break;
- case 'u':
- opts.bDontProtect = TRUE;
- break;
- case 'b':
- opts.bSecCallback = TRUE;
- break;
-#endif
- case 'c':
- opts.bConsole = TRUE;
- break;
- case 'h':
- case '?':
- default:
- UsageOpts(argv[0]);
- }
- }
- else
- UsageOpts(argv[0]);
- }
-
-}
-
-ParseOpts::ParseOpts(char* valid_opts)
-{
- SetValidOpts(valid_opts);
-}
-
-ParseOpts::ParseOpts()
-{
-}
-
-ParseOpts::~ParseOpts()
-{
-}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <opts.hxx>
+
+#if 0
+const struct Opts*
+GetOpts(
+ )
+{
+ bool done = false;
+ struct Opts* o;
+ if (!(o = new Opts))
+ goto cleanup;
+ if (!(o->pszString = new char[lstrlenA(opts.pszString) + 1]))
+ goto cleanup;
+ if (!(o->pszEndpoint = new char[lstrlenA(opts.pszEndpoint) + 1]))
+ goto cleanup;
+ strcpy(o->pszString, opts.pszString);
+ strcpy(o->pszEndpoint, opts.pszEndpoint);
+ done = true;
+ cleanup:
+ if (!done) {
+ FreeOpts(o);
+ o = 0;
+ }
+ return o;
+}
+
+void
+FreeOpts(
+ struct Opts* o
+ )
+{
+ if (o) {
+ if (o->pszString)
+ delete [] o->pszString;
+ if (o->pszEndpoint)
+ delete [] o->pszEndpoint;
+ delete o;
+ }
+}
+#endif
+
+bool
+ParseOpts::IsValidOpt(
+ char ch
+ )
+{
+ return (m_ValidOpts[ch % 256] != 0);
+}
+
+void
+ParseOpts::PrintOpt(
+ char ch,
+ char* text
+ )
+{
+ if (IsValidOpt(ch))
+ fprintf(stderr, " -%c %s\n", ch, text);
+}
+
+void
+ParseOpts::UsageOpts(
+ char * program,
+ int code
+ )
+{
+ fprintf(stderr, "Usage: %s [options]\n", program);
+ PrintOpt('k', "stop server");
+#ifdef CCAPI_TEST_OPTIONS
+ PrintOpt('s', "string");
+ PrintOpt('e', "endpoint");
+ PrintOpt('m', "maxcalls");
+ PrintOpt('n', "mincalls");
+ PrintOpt('f', "flag_wait_op");
+ PrintOpt('u', "unprotected");
+ PrintOpt('b', "use security callback");
+#endif
+ PrintOpt('c', "output debug info to console");
+ exit(code);
+}
+
+void
+ParseOpts::SetValidOpts(
+ char* valid_opts
+ )
+{
+ memset(m_ValidOpts, 0, sizeof(m_ValidOpts));
+ char *p = valid_opts;
+ for (p = valid_opts; *p; p++) {
+ m_ValidOpts[*p % sizeof(m_ValidOpts)] = 1;
+ }
+}
+
+void
+ParseOpts::Parse(
+ Opts& opts,
+ int argc,
+ char **argv
+ )
+{
+ int i;
+ for (i = 1; i < argc; i++) {
+ if ((*argv[i] == '-') || (*argv[i] == '/')) {
+ char ch = tolower(*(argv[i]+1));
+ if (!IsValidOpt(ch))
+ UsageOpts(argv[0]);
+ switch (ch) {
+ case 'k':
+ opts.bShutdown = TRUE;
+ break;
+#ifdef CCAPI_TEST_OPTIONS
+ case 's':
+ opts.pszString = argv[++i];
+ break;
+ case 'e':
+ opts.pszEndpoint = argv[++i];
+ break;
+ case 'm':
+ opts.cMaxCalls = (unsigned int) atoi(argv[++i]);
+ break;
+ case 'n':
+ opts.cMinCalls = (unsigned int) atoi(argv[++i]);
+ break;
+ case 'f':
+ opts.fDontWait = (unsigned int) atoi(argv[++i]);
+ break;
+ case 'u':
+ opts.bDontProtect = TRUE;
+ break;
+ case 'b':
+ opts.bSecCallback = TRUE;
+ break;
+#endif
+ case 'c':
+ opts.bConsole = TRUE;
+ break;
+ case 'h':
+ case '?':
+ default:
+ UsageOpts(argv[0]);
+ }
+ }
+ else
+ UsageOpts(argv[0]);
+ }
+
+}
+
+ParseOpts::ParseOpts(char* valid_opts)
+{
+ SetValidOpts(valid_opts);
+}
+
+ParseOpts::ParseOpts()
+{
+}
+
+ParseOpts::~ParseOpts()
+{
+}
diff --git a/src/ccapi/common/win/OldCC/opts.hxx b/src/ccapi/common/win/OldCC/opts.hxx
index 1732ceb..755ce4a 100644
--- a/src/ccapi/common/win/OldCC/opts.hxx
+++ b/src/ccapi/common/win/OldCC/opts.hxx
@@ -1,56 +1,56 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#pragma once
-
-class ParseOpts
-{
-public:
- struct Opts {
- char* pszString;
- char* pszEndpoint;
- unsigned int cMinCalls;
- unsigned int cMaxCalls;
- unsigned int fDontWait;
- bool bDontProtect;
- bool bShutdown;
- bool bSecCallback;
- bool bConsole;
- };
-
- ParseOpts(char* valid_opts);
- ParseOpts();
- ~ParseOpts();
- void SetValidOpts(char* valid_opts);
- void Parse(Opts& opts, int argc, char **argv);
-
-private:
- bool IsValidOpt(char ch);
- void PrintOpt(char ch, char* text);
- void UsageOpts(char* program, int code = 0);
-
- char m_ValidOpts[256];
-};
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#pragma once
+
+class ParseOpts
+{
+public:
+ struct Opts {
+ char* pszString;
+ char* pszEndpoint;
+ unsigned int cMinCalls;
+ unsigned int cMaxCalls;
+ unsigned int fDontWait;
+ bool bDontProtect;
+ bool bShutdown;
+ bool bSecCallback;
+ bool bConsole;
+ };
+
+ ParseOpts(char* valid_opts);
+ ParseOpts();
+ ~ParseOpts();
+ void SetValidOpts(char* valid_opts);
+ void Parse(Opts& opts, int argc, char **argv);
+
+private:
+ bool IsValidOpt(char ch);
+ void PrintOpt(char ch, char* text);
+ void UsageOpts(char* program, int code = 0);
+
+ char m_ValidOpts[256];
+};
diff --git a/src/ccapi/common/win/OldCC/secure.cxx b/src/ccapi/common/win/OldCC/secure.cxx
index a32235f..99ba08a 100644
--- a/src/ccapi/common/win/OldCC/secure.cxx
+++ b/src/ccapi/common/win/OldCC/secure.cxx
@@ -1,161 +1,161 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include "secure.hxx"
-
-extern "C" {
-#include "cci_debugging.h"
- }
-
-CcOsLock SecureClient::s_lock;
-DWORD SecureClient::s_refcount = 0;
-DWORD SecureClient::s_error = 0;
-HANDLE SecureClient::s_hToken = 0;
-
-#include "util.h"
-
-#define SC "SecureClient::"
-
-DWORD
-SecureClient::Attach(
- )
-{
- CcAutoLock AL(s_lock);
- if (s_hToken) {
- s_refcount++;
- return 0;
- }
- if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY,
- &s_hToken)) {
- s_refcount++;
- s_error = 0;
- } else {
- s_hToken = 0;
- s_error = GetLastError();
- }
- return s_error;
-}
-
-DWORD
-SecureClient::Detach(
- )
-{
- CcAutoLock AL(s_lock);
- s_refcount--;
- if (s_refcount) return 0;
- if (!s_hToken) return 0;
- DWORD error = 0;
- if (!CloseHandle(s_hToken))
- error = GetLastError();
- s_hToken = 0;
- s_error = 0;
- return error;
-}
-
-DWORD SecureClient::Token(HANDLE& hToken) {
- // This function will not do automatic initialization.
- CcAutoLock AL(s_lock);
- hToken = 0;
- if (!s_hToken) {
- cci_debug_printf("%s no process token initialized (%u)", __FUNCTION__, s_error);
- return s_error ? s_error : ERROR_INVALID_HANDLE;
- }
- else {
- DWORD status = 0;
- if (!DuplicateHandle(GetCurrentProcess(), s_hToken,
- GetCurrentProcess(), &hToken, 0, FALSE,
- DUPLICATE_SAME_ACCESS)) {
- status = GetLastError();
- cci_debug_printf(" Could not duplicate handle (%u)", status);
- }
- return status;
- }
- }
-
-void
-SecureClient::Start(SecureClient*& s) {
- s = new SecureClient;
-}
-
-void
-SecureClient::Stop(SecureClient*& s) {
- delete s;
- s = 0;
-}
-
-///////////////////////////////////////////////////////////////////////////////
-
-/* This constructor turns off impersonation.
- * It is OK for OpenThreadToken to return an error -- that just means impersonation
- * is off.
- */
-SecureClient::SecureClient():
- m_Error(0),
- m_hToken(0),
- m_NeedRestore(false) {
-
- HANDLE hThread = GetCurrentThread();
- HANDLE hThDuplicate;
-
- int status = DuplicateHandle( GetCurrentProcess(),
- hThread,
- GetCurrentProcess(),
- &hThDuplicate,
- TOKEN_ALL_ACCESS,
- FALSE,
- 0);
- if (!status) return;
-
- if (!OpenThreadToken(hThDuplicate, TOKEN_ALL_ACCESS, FALSE, &m_hToken)) {
- m_Error = GetLastError();
- return;
- }
- if (SetThreadToken(&hThDuplicate, NULL)) {
- m_NeedRestore = true;
- } else {
- m_Error = GetLastError();
- }
- CloseHandle(hThDuplicate);
- }
-
-SecureClient::~SecureClient() {
- if (m_NeedRestore) {
- HANDLE hThread = GetCurrentThread();
- if (!SetThreadToken(&hThread, m_hToken)) {
- m_Error = cci_check_error(GetLastError());
- }
- }
- if (m_hToken) {
- if (!CloseHandle(m_hToken)) {
- m_Error = cci_check_error(GetLastError());
- }
- }
- }
-
-DWORD SecureClient::Error() {
- return m_Error;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include "secure.hxx"
+
+extern "C" {
+#include "cci_debugging.h"
+ }
+
+CcOsLock SecureClient::s_lock;
+DWORD SecureClient::s_refcount = 0;
+DWORD SecureClient::s_error = 0;
+HANDLE SecureClient::s_hToken = 0;
+
+#include "util.h"
+
+#define SC "SecureClient::"
+
+DWORD
+SecureClient::Attach(
+ )
+{
+ CcAutoLock AL(s_lock);
+ if (s_hToken) {
+ s_refcount++;
+ return 0;
+ }
+ if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY,
+ &s_hToken)) {
+ s_refcount++;
+ s_error = 0;
+ } else {
+ s_hToken = 0;
+ s_error = GetLastError();
+ }
+ return s_error;
+}
+
+DWORD
+SecureClient::Detach(
+ )
+{
+ CcAutoLock AL(s_lock);
+ s_refcount--;
+ if (s_refcount) return 0;
+ if (!s_hToken) return 0;
+ DWORD error = 0;
+ if (!CloseHandle(s_hToken))
+ error = GetLastError();
+ s_hToken = 0;
+ s_error = 0;
+ return error;
+}
+
+DWORD SecureClient::Token(HANDLE& hToken) {
+ // This function will not do automatic initialization.
+ CcAutoLock AL(s_lock);
+ hToken = 0;
+ if (!s_hToken) {
+ cci_debug_printf("%s no process token initialized (%u)", __FUNCTION__, s_error);
+ return s_error ? s_error : ERROR_INVALID_HANDLE;
+ }
+ else {
+ DWORD status = 0;
+ if (!DuplicateHandle(GetCurrentProcess(), s_hToken,
+ GetCurrentProcess(), &hToken, 0, FALSE,
+ DUPLICATE_SAME_ACCESS)) {
+ status = GetLastError();
+ cci_debug_printf(" Could not duplicate handle (%u)", status);
+ }
+ return status;
+ }
+ }
+
+void
+SecureClient::Start(SecureClient*& s) {
+ s = new SecureClient;
+}
+
+void
+SecureClient::Stop(SecureClient*& s) {
+ delete s;
+ s = 0;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+/* This constructor turns off impersonation.
+ * It is OK for OpenThreadToken to return an error -- that just means impersonation
+ * is off.
+ */
+SecureClient::SecureClient():
+ m_Error(0),
+ m_hToken(0),
+ m_NeedRestore(false) {
+
+ HANDLE hThread = GetCurrentThread();
+ HANDLE hThDuplicate;
+
+ int status = DuplicateHandle( GetCurrentProcess(),
+ hThread,
+ GetCurrentProcess(),
+ &hThDuplicate,
+ TOKEN_ALL_ACCESS,
+ FALSE,
+ 0);
+ if (!status) return;
+
+ if (!OpenThreadToken(hThDuplicate, TOKEN_ALL_ACCESS, FALSE, &m_hToken)) {
+ m_Error = GetLastError();
+ return;
+ }
+ if (SetThreadToken(&hThDuplicate, NULL)) {
+ m_NeedRestore = true;
+ } else {
+ m_Error = GetLastError();
+ }
+ CloseHandle(hThDuplicate);
+ }
+
+SecureClient::~SecureClient() {
+ if (m_NeedRestore) {
+ HANDLE hThread = GetCurrentThread();
+ if (!SetThreadToken(&hThread, m_hToken)) {
+ m_Error = cci_check_error(GetLastError());
+ }
+ }
+ if (m_hToken) {
+ if (!CloseHandle(m_hToken)) {
+ m_Error = cci_check_error(GetLastError());
+ }
+ }
+ }
+
+DWORD SecureClient::Error() {
+ return m_Error;
} \ No newline at end of file
diff --git a/src/ccapi/common/win/OldCC/secure.hxx b/src/ccapi/common/win/OldCC/secure.hxx
index 009e36c..3714c6f 100644
--- a/src/ccapi/common/win/OldCC/secure.hxx
+++ b/src/ccapi/common/win/OldCC/secure.hxx
@@ -1,60 +1,60 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#pragma once
-
-#include <windows.h>
-#include "autolock.hxx"
-
-class SecureClient
-{
-public:
- static DWORD Attach();
- static DWORD Detach();
- static DWORD Token(HANDLE& hToken);
- static void Start(SecureClient*& s);
- static void Stop(SecureClient*& s);
-
-#if 0
- static DWORD CheckImpersonation();
- static bool IsImp();
- static DWORD DuplicateImpAsPrimary(HANDLE& hPrimary);
-#endif
-
- SecureClient();
- ~SecureClient();
- DWORD Error();
-
-private:
- static CcOsLock s_lock;
- static DWORD s_refcount;
- static DWORD s_error;
- static HANDLE s_hToken;
-
- DWORD m_Error;
- HANDLE m_hToken;
- bool m_NeedRestore;
-};
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#pragma once
+
+#include <windows.h>
+#include "autolock.hxx"
+
+class SecureClient
+{
+public:
+ static DWORD Attach();
+ static DWORD Detach();
+ static DWORD Token(HANDLE& hToken);
+ static void Start(SecureClient*& s);
+ static void Stop(SecureClient*& s);
+
+#if 0
+ static DWORD CheckImpersonation();
+ static bool IsImp();
+ static DWORD DuplicateImpAsPrimary(HANDLE& hPrimary);
+#endif
+
+ SecureClient();
+ ~SecureClient();
+ DWORD Error();
+
+private:
+ static CcOsLock s_lock;
+ static DWORD s_refcount;
+ static DWORD s_error;
+ static HANDLE s_hToken;
+
+ DWORD m_Error;
+ HANDLE m_hToken;
+ bool m_NeedRestore;
+};
diff --git a/src/ccapi/common/win/OldCC/util.cxx b/src/ccapi/common/win/OldCC/util.cxx
index 62b204b..8694c37 100644
--- a/src/ccapi/common/win/OldCC/util.cxx
+++ b/src/ccapi/common/win/OldCC/util.cxx
@@ -1,519 +1,519 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include <stdio.h> // for _snprintf
-
-#include "util.h"
-#include "secure.hxx"
-
-extern "C" {
-#include "cci_debugging.h"
-#include "ccutils.h"
- }
-
-
-
-void* malloc_alloc_p(size_t size) {
- return malloc(size);
- }
-
-void free_alloc_p(void *pptr) {
- void **real_pptr = (void**)pptr;
- if (*real_pptr) {
- free(*real_pptr);
- *real_pptr = 0;
- }
- }
-
-extern "C" DWORD alloc_textual_sid(
- PSID pSid, // binary Sid
- LPSTR *pTextualSid // buffer for Textual representaion of Sid
- ) {
- PSID_IDENTIFIER_AUTHORITY psia;
- DWORD dwSubAuthorities;
- DWORD dwSidRev = SID_REVISION;
- DWORD dwCounter;
- DWORD dwSidSize;
-
- *pTextualSid = 0;
-
- //
- // test if Sid passed in is valid
- //
- if(!IsValidSid(pSid)) return ERROR_INVALID_PARAMETER;
-
- // obtain SidIdentifierAuthority
- psia = GetSidIdentifierAuthority(pSid);
-
- // obtain sidsubauthority count
- dwSubAuthorities =* GetSidSubAuthorityCount(pSid);
-
- //
- // compute buffer length
- // S-SID_REVISION- + identifierauthority- + subauthorities- + NULL
- //
- dwSidSize = (15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
- *pTextualSid = (LPSTR)malloc_alloc_p(dwSidSize);
- if (!*pTextualSid)
- return GetLastError();
-
- LPSTR TextualSid = *pTextualSid;
-
- //
- // prepare S-SID_REVISION-
- //
- wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev );
-
- //
- // prepare SidIdentifierAuthority
- //
- if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
- {
- wsprintf(TextualSid + lstrlen(TextualSid),
- TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
- (USHORT)psia->Value[0],
- (USHORT)psia->Value[1],
- (USHORT)psia->Value[2],
- (USHORT)psia->Value[3],
- (USHORT)psia->Value[4],
- (USHORT)psia->Value[5]);
- }
- else
- {
- wsprintf(TextualSid + lstrlen(TextualSid), TEXT("%lu"),
- (ULONG)(psia->Value[5] ) +
- (ULONG)(psia->Value[4] << 8) +
- (ULONG)(psia->Value[3] << 16) +
- (ULONG)(psia->Value[2] << 24) );
- }
-
- //
- // loop through SidSubAuthorities
- //
- for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
- {
- wsprintf(TextualSid + lstrlen(TextualSid), TEXT("-%lu"),
- *GetSidSubAuthority(pSid, dwCounter) );
- }
- return 0;
-}
-
-DWORD alloc_token_user(HANDLE hToken, PTOKEN_USER *pptu) {
- DWORD status = 0;
- DWORD size = 0;
- *pptu = 0;
-
- GetTokenInformation(hToken, TokenUser, *pptu, 0, &size);
- if (size == 0) status = GetLastError();
-
- if (!status) {
- if (!(*pptu = (PTOKEN_USER)malloc_alloc_p(size)))
- status = GetLastError();
- }
-
- if (!status) {
- if (!GetTokenInformation(hToken, TokenUser, *pptu, size, &size))
- status = GetLastError();
- }
-
- if (status && *pptu) {
- free_alloc_p(pptu);
- }
- return status;
- }
-
-DWORD
-alloc_username(
- PSID Sid,
- LPSTR* pname,
- LPSTR* pdomain = 0
- )
-{
- DWORD status = 0;
- DWORD name_len = 0;
- DWORD domain_len = 0;
- SID_NAME_USE snu;
- LPSTR name = 0;
- LPSTR domain = 0;
-
- *pname = 0;
- if (pdomain) *pdomain = 0;
-
- LookupAccountSidA(NULL, Sid, 0, &name_len, 0, &domain_len, &snu);
- if ((name_len == 0) || (domain_len == 0)) status = GetLastError();
-
- if (!status) {
- if (!(name = (LPSTR)malloc_alloc_p(name_len))) status = GetLastError();
- }
-
- if (!status) {
- if (!(domain = (LPSTR)malloc_alloc_p(domain_len))) status = GetLastError();
- }
-
- if (!status) {
- if (!LookupAccountSidA(NULL, Sid, name, &name_len, domain, &domain_len, &snu)) status = GetLastError();
- }
-
- if (status) {
- if (name) free_alloc_p(&name);
- if (domain) free_alloc_p(&domain);
- }
- else {
- if (pdomain) {
- *pname = name;
- *pdomain = domain;
- }
- else {
- DWORD size = name_len + domain_len + 1;
- *pname = (LPSTR)malloc_alloc_p(size);
- if (!*pname) status = GetLastError();
- else _snprintf(*pname, size, "%s\\%s", name, domain);
- }
- }
- return status;
- }
-
-DWORD get_authentication_id(HANDLE hToken, LUID* pAuthId) {
- TOKEN_STATISTICS ts;
- DWORD len;
-
- if (!GetTokenInformation(hToken, TokenStatistics, &ts, sizeof(ts), &len))
- return GetLastError();
- *pAuthId = ts.AuthenticationId;
- return 0;
- }
-
-DWORD
-alloc_name_9x(
- LPSTR* pname,
- LPSTR postfix
- )
-{
- char prefix[] = "krbcc";
- DWORD len = (sizeof(prefix) - 1) + 1 + strlen(postfix) + 1;
-
- *pname = (LPSTR)malloc_alloc_p(len);
- if (!*pname) return GetLastError();
- _snprintf(*pname, len, "%s.%s", prefix, postfix);
- return 0;
-}
-
-DWORD alloc_name_NT(LPSTR* pname, LPSTR postfix) {
- DWORD status = 0;
- HANDLE hToken = 0;
- LUID auth_id;
-#ifdef _DEBUG
- PTOKEN_USER ptu = 0;
- LPSTR name = 0;
- LPSTR domain = 0;
- LPSTR sid = 0;
-#endif
- char prefix[] = "krbcc";
- // Play it safe and say 3 characters are needed per 8 bits (byte).
- // Note that 20 characters are needed for a 64-bit number in
- // decimal (plus one for the string termination.
- // and include room for sessionId.
- char lid[3*sizeof(LUID)+1+5];
- DWORD sessionId;
- DWORD len = 0;
-
- *pname = 0;
-
- status = SecureClient::Token(hToken);
-
- if (!status) {
- status = get_authentication_id(hToken, &auth_id);
- }
-
- if (!status) {
- if (!ProcessIdToSessionId(GetCurrentProcessId(), &sessionId))
- sessionId = 0;
- }
-
-#ifdef _DEBUG
- if (!status) {status = alloc_token_user(hToken, &ptu);}
- if (!status) {status = alloc_username(ptu->User.Sid, &name, &domain);}
- if (!status) {status = alloc_textual_sid(ptu->User.Sid, &sid);}
-#endif
-
- if (!status) {
- _snprintf(lid, sizeof(lid), "%I64u.%u", auth_id, sessionId);
- lid[sizeof(lid)-1] = 0; // be safe
-
- len = (sizeof(prefix) - 1) + 1 + strlen(lid) + 1 + strlen(postfix) + 1;
- *pname = (LPSTR)malloc_alloc_p(len);
- if (!*pname) status = GetLastError();
- }
-
- //
- // We used to allocate a name of the form:
- // "prefix.domain.name.sid.lid.postfix" (usually under 80
- // characters, depending on username). However, XP thought this
- // was "invalid" (too long?) for some reason.
- //
- // Therefore, we now use "prefix.lid.postfix"
- // and for Terminal server we use "prefix.lid.sessionId.postfix"
- //
-
- if (!status) {
- _snprintf(*pname, len, "%s.%s.%s", prefix, lid, postfix);
- }
-
-#ifdef _DEBUG
- if (sid)
- free_alloc_p(&sid);
- if (name)
- free_alloc_p(&name);
- if (domain)
- free_alloc_p(&domain);
- if (ptu)
- free_alloc_p(&ptu);
-#endif
- if (hToken && hToken != INVALID_HANDLE_VALUE)
- CloseHandle(hToken);
- if (status && *pname)
- free_alloc_p(pname);
- return status;
-}
-
-extern "C" DWORD alloc_name(LPSTR* pname, LPSTR postfix, BOOL isNT) {
- return isNT ? alloc_name_NT(pname, postfix) :
- alloc_name_9x(pname, postfix);
- }
-
-extern "C" DWORD alloc_own_security_descriptor_NT(PSECURITY_DESCRIPTOR* ppsd) {
- DWORD status = 0;
- HANDLE hToken = 0;
- PTOKEN_USER ptu = 0;
- PSID pSid = 0;
- PACL pAcl = 0;
- DWORD size = 0;
- SECURITY_DESCRIPTOR sd;
-
- *ppsd = 0;
-
- if (!status) {status = SecureClient::Token(hToken);}
-
- // Get SID:
- if (!status) {status = alloc_token_user(hToken, &ptu);}
-
- if (!status) {
- size = GetLengthSid(ptu->User.Sid);
- pSid = (PSID) malloc_alloc_p(size);
- if (!pSid) status = GetLastError();
- }
- if (!status) {
- if (!CopySid(size, pSid, ptu->User.Sid)) status = GetLastError();
- }
-
- if (!status) {
- // Prepare ACL:
- size = sizeof(ACL);
- // Add an ACE:
- size += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + GetLengthSid(pSid);
- pAcl = (PACL) malloc_alloc_p(size);
- if (!pAcl) status = GetLastError();
- }
-
- if (!status) {
- if (!InitializeAcl(pAcl, size, ACL_REVISION)) status = GetLastError();
- }
-
- if (!status) {
- if (!AddAccessAllowedAce(pAcl, ACL_REVISION, GENERIC_ALL, pSid)) status = GetLastError();
- }
-
- if (!status) {
- // Prepare SD itself:
- if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) status = GetLastError();
- }
-
- if (!status) {
- if (!SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) status = GetLastError();
- }
-
- if (!status) {
- if (!SetSecurityDescriptorOwner(&sd, pSid, FALSE)) status = GetLastError();
- }
-
- if (!status) {
- if (!IsValidSecurityDescriptor(&sd)) status = ERROR_INVALID_PARAMETER;
- }
-
- if (!status) {
- // We now have a SD. Let's copy it.
- {
- // This should not succeed. Instead it should give us the size.
- BOOL ok = MakeSelfRelativeSD(&sd, 0, &size);
- }
- if (size == 0) status = GetLastError();
- }
-
- if (!status) {
- *ppsd = (PSECURITY_DESCRIPTOR) malloc_alloc_p(size);
- if (!*ppsd) status = GetLastError();
- }
-
- if (!status) {
- if (!MakeSelfRelativeSD(&sd, *ppsd, &size)) status = GetLastError();
- }
-
- if (ptu) free_alloc_p(&ptu);
- if (pSid) free_alloc_p(&pSid);
- if (pAcl) free_alloc_p(&pAcl);
- if (hToken && hToken != INVALID_HANDLE_VALUE) CloseHandle(hToken);
- if (status && *ppsd) free_alloc_p(ppsd);
- return status;
-}
-
-DWORD
-alloc_module_file_name(
- char* module,
- char** pname
- )
-{
- const DWORD max = 8192;
- DWORD status = 0;
- DWORD got = 0;
- DWORD size = 512; // use low number to test...
- HMODULE h = 0;
- BOOL ok = FALSE;
- char* name = 0;
-
- if (!pname)
- return ERROR_INVALID_PARAMETER;
- *pname = 0;
-
- h = GetModuleHandle(module);
-
- if (!h) return GetLastError();
-
- // We assume size < max and size > 0
- while (!status && !ok) {
- if (size > max) {
- // XXX - Assert?
- status = ERROR_INVALID_DATA;
- continue;
- }
- if (name) free_alloc_p(&name);
- name = (char*)malloc_alloc_p(size + 1);
- if (!name) {
- status = ERROR_NOT_ENOUGH_MEMORY;
- continue;
- }
- name[size] = 0;
- got = GetModuleFileName(h, name, size);
- if (!got) {
- status = GetLastError();
- // sanity check:
- if (!status) {
- // XXX - print nasty message...assert?
- status = ERROR_INVALID_DATA;
- }
- continue;
- }
- // To know we're ok, we need to verify that what we got
- // was bigger than GetModuleSize thought it got.
- ok = got && (got < size) && !name[got];
- size *= 2;
- }
- if (status && name)
- free_alloc_p(&name);
- else
- *pname = name;
- return status;
-}
-
-DWORD
-alloc_module_dir_name(
- char* module,
- char** pname
- )
-{
- DWORD status = alloc_module_file_name(module, pname);
- if (!status) {
- char* name = *pname;
- char* p = name + strlen(name);
- while ((p >= name) && (*p != '\\') && (*p != '/')) p--;
- if (p < name) {
- free_alloc_p(pname);
- status = ERROR_INVALID_DATA;
- } else {
- *p = 0;
- }
- }
- return status;
-}
-
-DWORD
-alloc_module_dir_name_with_file(
- char* module,
- char* file,
- char** pname
- )
-{
- DWORD status = alloc_module_dir_name(module, pname);
- if (!status) {
- char* name = *pname;
- size_t name_size = strlen(name);
- size_t size = name_size + 1 + strlen(file) + 1;
- char* result = (char*)malloc_alloc_p(size);
- if (!result) {
- status = ERROR_NOT_ENOUGH_MEMORY;
- free_alloc_p(pname);
- } else {
- strcpy(result, name);
- result[name_size] = '\\';
- strcpy(result + name_size + 1, file);
- free_alloc_p(pname);
- *pname = result;
- }
- }
- return status;
-}
-
-DWORD alloc_cmdline_2_args(char* prog,
- char* arg1,
- char* arg2,
- char** pname) {
- DWORD status = 0;
- size_t size = strlen(prog) + strlen(arg1) + strlen(arg2) + 4;
- char* result = (char*)malloc_alloc_p(size);
- if (!result) {
- status = ERROR_NOT_ENOUGH_MEMORY;
- }
- else {
- strcpy(result, prog);
- strcat(result, " ");
- strcat(result, arg1);
- strcat(result, " ");
- strcat(result, arg2);
- *pname = result;
- }
- cci_debug_printf("%s made <%s>", __FUNCTION__, result);
- return status;
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include <stdio.h> // for _snprintf
+
+#include "util.h"
+#include "secure.hxx"
+
+extern "C" {
+#include "cci_debugging.h"
+#include "ccutils.h"
+ }
+
+
+
+void* malloc_alloc_p(size_t size) {
+ return malloc(size);
+ }
+
+void free_alloc_p(void *pptr) {
+ void **real_pptr = (void**)pptr;
+ if (*real_pptr) {
+ free(*real_pptr);
+ *real_pptr = 0;
+ }
+ }
+
+extern "C" DWORD alloc_textual_sid(
+ PSID pSid, // binary Sid
+ LPSTR *pTextualSid // buffer for Textual representaion of Sid
+ ) {
+ PSID_IDENTIFIER_AUTHORITY psia;
+ DWORD dwSubAuthorities;
+ DWORD dwSidRev = SID_REVISION;
+ DWORD dwCounter;
+ DWORD dwSidSize;
+
+ *pTextualSid = 0;
+
+ //
+ // test if Sid passed in is valid
+ //
+ if(!IsValidSid(pSid)) return ERROR_INVALID_PARAMETER;
+
+ // obtain SidIdentifierAuthority
+ psia = GetSidIdentifierAuthority(pSid);
+
+ // obtain sidsubauthority count
+ dwSubAuthorities =* GetSidSubAuthorityCount(pSid);
+
+ //
+ // compute buffer length
+ // S-SID_REVISION- + identifierauthority- + subauthorities- + NULL
+ //
+ dwSidSize = (15 + 12 + (12 * dwSubAuthorities) + 1) * sizeof(TCHAR);
+ *pTextualSid = (LPSTR)malloc_alloc_p(dwSidSize);
+ if (!*pTextualSid)
+ return GetLastError();
+
+ LPSTR TextualSid = *pTextualSid;
+
+ //
+ // prepare S-SID_REVISION-
+ //
+ wsprintf(TextualSid, TEXT("S-%lu-"), dwSidRev );
+
+ //
+ // prepare SidIdentifierAuthority
+ //
+ if ( (psia->Value[0] != 0) || (psia->Value[1] != 0) )
+ {
+ wsprintf(TextualSid + lstrlen(TextualSid),
+ TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"),
+ (USHORT)psia->Value[0],
+ (USHORT)psia->Value[1],
+ (USHORT)psia->Value[2],
+ (USHORT)psia->Value[3],
+ (USHORT)psia->Value[4],
+ (USHORT)psia->Value[5]);
+ }
+ else
+ {
+ wsprintf(TextualSid + lstrlen(TextualSid), TEXT("%lu"),
+ (ULONG)(psia->Value[5] ) +
+ (ULONG)(psia->Value[4] << 8) +
+ (ULONG)(psia->Value[3] << 16) +
+ (ULONG)(psia->Value[2] << 24) );
+ }
+
+ //
+ // loop through SidSubAuthorities
+ //
+ for (dwCounter=0 ; dwCounter < dwSubAuthorities ; dwCounter++)
+ {
+ wsprintf(TextualSid + lstrlen(TextualSid), TEXT("-%lu"),
+ *GetSidSubAuthority(pSid, dwCounter) );
+ }
+ return 0;
+}
+
+DWORD alloc_token_user(HANDLE hToken, PTOKEN_USER *pptu) {
+ DWORD status = 0;
+ DWORD size = 0;
+ *pptu = 0;
+
+ GetTokenInformation(hToken, TokenUser, *pptu, 0, &size);
+ if (size == 0) status = GetLastError();
+
+ if (!status) {
+ if (!(*pptu = (PTOKEN_USER)malloc_alloc_p(size)))
+ status = GetLastError();
+ }
+
+ if (!status) {
+ if (!GetTokenInformation(hToken, TokenUser, *pptu, size, &size))
+ status = GetLastError();
+ }
+
+ if (status && *pptu) {
+ free_alloc_p(pptu);
+ }
+ return status;
+ }
+
+DWORD
+alloc_username(
+ PSID Sid,
+ LPSTR* pname,
+ LPSTR* pdomain = 0
+ )
+{
+ DWORD status = 0;
+ DWORD name_len = 0;
+ DWORD domain_len = 0;
+ SID_NAME_USE snu;
+ LPSTR name = 0;
+ LPSTR domain = 0;
+
+ *pname = 0;
+ if (pdomain) *pdomain = 0;
+
+ LookupAccountSidA(NULL, Sid, 0, &name_len, 0, &domain_len, &snu);
+ if ((name_len == 0) || (domain_len == 0)) status = GetLastError();
+
+ if (!status) {
+ if (!(name = (LPSTR)malloc_alloc_p(name_len))) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!(domain = (LPSTR)malloc_alloc_p(domain_len))) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!LookupAccountSidA(NULL, Sid, name, &name_len, domain, &domain_len, &snu)) status = GetLastError();
+ }
+
+ if (status) {
+ if (name) free_alloc_p(&name);
+ if (domain) free_alloc_p(&domain);
+ }
+ else {
+ if (pdomain) {
+ *pname = name;
+ *pdomain = domain;
+ }
+ else {
+ DWORD size = name_len + domain_len + 1;
+ *pname = (LPSTR)malloc_alloc_p(size);
+ if (!*pname) status = GetLastError();
+ else _snprintf(*pname, size, "%s\\%s", name, domain);
+ }
+ }
+ return status;
+ }
+
+DWORD get_authentication_id(HANDLE hToken, LUID* pAuthId) {
+ TOKEN_STATISTICS ts;
+ DWORD len;
+
+ if (!GetTokenInformation(hToken, TokenStatistics, &ts, sizeof(ts), &len))
+ return GetLastError();
+ *pAuthId = ts.AuthenticationId;
+ return 0;
+ }
+
+DWORD
+alloc_name_9x(
+ LPSTR* pname,
+ LPSTR postfix
+ )
+{
+ char prefix[] = "krbcc";
+ DWORD len = (sizeof(prefix) - 1) + 1 + strlen(postfix) + 1;
+
+ *pname = (LPSTR)malloc_alloc_p(len);
+ if (!*pname) return GetLastError();
+ _snprintf(*pname, len, "%s.%s", prefix, postfix);
+ return 0;
+}
+
+DWORD alloc_name_NT(LPSTR* pname, LPSTR postfix) {
+ DWORD status = 0;
+ HANDLE hToken = 0;
+ LUID auth_id;
+#ifdef _DEBUG
+ PTOKEN_USER ptu = 0;
+ LPSTR name = 0;
+ LPSTR domain = 0;
+ LPSTR sid = 0;
+#endif
+ char prefix[] = "krbcc";
+ // Play it safe and say 3 characters are needed per 8 bits (byte).
+ // Note that 20 characters are needed for a 64-bit number in
+ // decimal (plus one for the string termination.
+ // and include room for sessionId.
+ char lid[3*sizeof(LUID)+1+5];
+ DWORD sessionId;
+ DWORD len = 0;
+
+ *pname = 0;
+
+ status = SecureClient::Token(hToken);
+
+ if (!status) {
+ status = get_authentication_id(hToken, &auth_id);
+ }
+
+ if (!status) {
+ if (!ProcessIdToSessionId(GetCurrentProcessId(), &sessionId))
+ sessionId = 0;
+ }
+
+#ifdef _DEBUG
+ if (!status) {status = alloc_token_user(hToken, &ptu);}
+ if (!status) {status = alloc_username(ptu->User.Sid, &name, &domain);}
+ if (!status) {status = alloc_textual_sid(ptu->User.Sid, &sid);}
+#endif
+
+ if (!status) {
+ _snprintf(lid, sizeof(lid), "%I64u.%u", auth_id, sessionId);
+ lid[sizeof(lid)-1] = 0; // be safe
+
+ len = (sizeof(prefix) - 1) + 1 + strlen(lid) + 1 + strlen(postfix) + 1;
+ *pname = (LPSTR)malloc_alloc_p(len);
+ if (!*pname) status = GetLastError();
+ }
+
+ //
+ // We used to allocate a name of the form:
+ // "prefix.domain.name.sid.lid.postfix" (usually under 80
+ // characters, depending on username). However, XP thought this
+ // was "invalid" (too long?) for some reason.
+ //
+ // Therefore, we now use "prefix.lid.postfix"
+ // and for Terminal server we use "prefix.lid.sessionId.postfix"
+ //
+
+ if (!status) {
+ _snprintf(*pname, len, "%s.%s.%s", prefix, lid, postfix);
+ }
+
+#ifdef _DEBUG
+ if (sid)
+ free_alloc_p(&sid);
+ if (name)
+ free_alloc_p(&name);
+ if (domain)
+ free_alloc_p(&domain);
+ if (ptu)
+ free_alloc_p(&ptu);
+#endif
+ if (hToken && hToken != INVALID_HANDLE_VALUE)
+ CloseHandle(hToken);
+ if (status && *pname)
+ free_alloc_p(pname);
+ return status;
+}
+
+extern "C" DWORD alloc_name(LPSTR* pname, LPSTR postfix, BOOL isNT) {
+ return isNT ? alloc_name_NT(pname, postfix) :
+ alloc_name_9x(pname, postfix);
+ }
+
+extern "C" DWORD alloc_own_security_descriptor_NT(PSECURITY_DESCRIPTOR* ppsd) {
+ DWORD status = 0;
+ HANDLE hToken = 0;
+ PTOKEN_USER ptu = 0;
+ PSID pSid = 0;
+ PACL pAcl = 0;
+ DWORD size = 0;
+ SECURITY_DESCRIPTOR sd;
+
+ *ppsd = 0;
+
+ if (!status) {status = SecureClient::Token(hToken);}
+
+ // Get SID:
+ if (!status) {status = alloc_token_user(hToken, &ptu);}
+
+ if (!status) {
+ size = GetLengthSid(ptu->User.Sid);
+ pSid = (PSID) malloc_alloc_p(size);
+ if (!pSid) status = GetLastError();
+ }
+ if (!status) {
+ if (!CopySid(size, pSid, ptu->User.Sid)) status = GetLastError();
+ }
+
+ if (!status) {
+ // Prepare ACL:
+ size = sizeof(ACL);
+ // Add an ACE:
+ size += sizeof(ACCESS_ALLOWED_ACE) - sizeof(DWORD) + GetLengthSid(pSid);
+ pAcl = (PACL) malloc_alloc_p(size);
+ if (!pAcl) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!InitializeAcl(pAcl, size, ACL_REVISION)) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!AddAccessAllowedAce(pAcl, ACL_REVISION, GENERIC_ALL, pSid)) status = GetLastError();
+ }
+
+ if (!status) {
+ // Prepare SD itself:
+ if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!SetSecurityDescriptorDacl(&sd, TRUE, pAcl, FALSE)) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!SetSecurityDescriptorOwner(&sd, pSid, FALSE)) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!IsValidSecurityDescriptor(&sd)) status = ERROR_INVALID_PARAMETER;
+ }
+
+ if (!status) {
+ // We now have a SD. Let's copy it.
+ {
+ // This should not succeed. Instead it should give us the size.
+ BOOL ok = MakeSelfRelativeSD(&sd, 0, &size);
+ }
+ if (size == 0) status = GetLastError();
+ }
+
+ if (!status) {
+ *ppsd = (PSECURITY_DESCRIPTOR) malloc_alloc_p(size);
+ if (!*ppsd) status = GetLastError();
+ }
+
+ if (!status) {
+ if (!MakeSelfRelativeSD(&sd, *ppsd, &size)) status = GetLastError();
+ }
+
+ if (ptu) free_alloc_p(&ptu);
+ if (pSid) free_alloc_p(&pSid);
+ if (pAcl) free_alloc_p(&pAcl);
+ if (hToken && hToken != INVALID_HANDLE_VALUE) CloseHandle(hToken);
+ if (status && *ppsd) free_alloc_p(ppsd);
+ return status;
+}
+
+DWORD
+alloc_module_file_name(
+ char* module,
+ char** pname
+ )
+{
+ const DWORD max = 8192;
+ DWORD status = 0;
+ DWORD got = 0;
+ DWORD size = 512; // use low number to test...
+ HMODULE h = 0;
+ BOOL ok = FALSE;
+ char* name = 0;
+
+ if (!pname)
+ return ERROR_INVALID_PARAMETER;
+ *pname = 0;
+
+ h = GetModuleHandle(module);
+
+ if (!h) return GetLastError();
+
+ // We assume size < max and size > 0
+ while (!status && !ok) {
+ if (size > max) {
+ // XXX - Assert?
+ status = ERROR_INVALID_DATA;
+ continue;
+ }
+ if (name) free_alloc_p(&name);
+ name = (char*)malloc_alloc_p(size + 1);
+ if (!name) {
+ status = ERROR_NOT_ENOUGH_MEMORY;
+ continue;
+ }
+ name[size] = 0;
+ got = GetModuleFileName(h, name, size);
+ if (!got) {
+ status = GetLastError();
+ // sanity check:
+ if (!status) {
+ // XXX - print nasty message...assert?
+ status = ERROR_INVALID_DATA;
+ }
+ continue;
+ }
+ // To know we're ok, we need to verify that what we got
+ // was bigger than GetModuleSize thought it got.
+ ok = got && (got < size) && !name[got];
+ size *= 2;
+ }
+ if (status && name)
+ free_alloc_p(&name);
+ else
+ *pname = name;
+ return status;
+}
+
+DWORD
+alloc_module_dir_name(
+ char* module,
+ char** pname
+ )
+{
+ DWORD status = alloc_module_file_name(module, pname);
+ if (!status) {
+ char* name = *pname;
+ char* p = name + strlen(name);
+ while ((p >= name) && (*p != '\\') && (*p != '/')) p--;
+ if (p < name) {
+ free_alloc_p(pname);
+ status = ERROR_INVALID_DATA;
+ } else {
+ *p = 0;
+ }
+ }
+ return status;
+}
+
+DWORD
+alloc_module_dir_name_with_file(
+ char* module,
+ char* file,
+ char** pname
+ )
+{
+ DWORD status = alloc_module_dir_name(module, pname);
+ if (!status) {
+ char* name = *pname;
+ size_t name_size = strlen(name);
+ size_t size = name_size + 1 + strlen(file) + 1;
+ char* result = (char*)malloc_alloc_p(size);
+ if (!result) {
+ status = ERROR_NOT_ENOUGH_MEMORY;
+ free_alloc_p(pname);
+ } else {
+ strcpy(result, name);
+ result[name_size] = '\\';
+ strcpy(result + name_size + 1, file);
+ free_alloc_p(pname);
+ *pname = result;
+ }
+ }
+ return status;
+}
+
+DWORD alloc_cmdline_2_args(char* prog,
+ char* arg1,
+ char* arg2,
+ char** pname) {
+ DWORD status = 0;
+ size_t size = strlen(prog) + strlen(arg1) + strlen(arg2) + 4;
+ char* result = (char*)malloc_alloc_p(size);
+ if (!result) {
+ status = ERROR_NOT_ENOUGH_MEMORY;
+ }
+ else {
+ strcpy(result, prog);
+ strcat(result, " ");
+ strcat(result, arg1);
+ strcat(result, " ");
+ strcat(result, arg2);
+ *pname = result;
+ }
+ cci_debug_printf("%s made <%s>", __FUNCTION__, result);
+ return status;
+ }
diff --git a/src/ccapi/common/win/OldCC/util.h b/src/ccapi/common/win/OldCC/util.h
index a51858c..4a83c64 100644
--- a/src/ccapi/common/win/OldCC/util.h
+++ b/src/ccapi/common/win/OldCC/util.h
@@ -1,89 +1,89 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __UTIL_H__
-#define __UTIL_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-#if 0
-}
-#endif
-
-BOOL isNT();
-
-void*
-user_allocate(
- size_t size
- );
-
-void
-user_free(
- void* ptr
- );
-
-void
-free_alloc_p(
- void* pptr
- );
-
-DWORD
-alloc_name(
- LPSTR* pname,
- LPSTR postfix,
- BOOL isNT
- );
-
-DWORD
-alloc_own_security_descriptor_NT(
- PSECURITY_DESCRIPTOR* ppsd
- );
-
-DWORD
-alloc_module_dir_name(
- char* module,
- char** pname
- );
-
-DWORD
-alloc_module_dir_name_with_file(
- char* module,
- char* file,
- char** pname
- );
-
-DWORD alloc_cmdline_2_args(
- char* prog,
- char* arg1,
- char* arg2,
- char** pname);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __UTIL_H__ */
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef __UTIL_H__
+#define __UTIL_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#if 0
+}
+#endif
+
+BOOL isNT();
+
+void*
+user_allocate(
+ size_t size
+ );
+
+void
+user_free(
+ void* ptr
+ );
+
+void
+free_alloc_p(
+ void* pptr
+ );
+
+DWORD
+alloc_name(
+ LPSTR* pname,
+ LPSTR postfix,
+ BOOL isNT
+ );
+
+DWORD
+alloc_own_security_descriptor_NT(
+ PSECURITY_DESCRIPTOR* ppsd
+ );
+
+DWORD
+alloc_module_dir_name(
+ char* module,
+ char** pname
+ );
+
+DWORD
+alloc_module_dir_name_with_file(
+ char* module,
+ char* file,
+ char** pname
+ );
+
+DWORD alloc_cmdline_2_args(
+ char* prog,
+ char* arg1,
+ char* arg2,
+ char** pname);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __UTIL_H__ */
diff --git a/src/ccapi/common/win/cci_os_debugging.c b/src/ccapi/common/win/cci_os_debugging.c
index f1fbb28..6e6a715 100644
--- a/src/ccapi/common/win/cci_os_debugging.c
+++ b/src/ccapi/common/win/cci_os_debugging.c
@@ -1,39 +1,39 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "cci_os_debugging.h"
-#include "win-utils.h"
-
-/* ------------------------------------------------------------------------ */
-
-void cci_os_debug_vprintf (const char *in_format, va_list in_args) {
- printf ( "%s %ld ", timestamp(), GetCurrentThreadId() );
- vprintf ( in_format, in_args );
- printf ( "\n" );
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "cci_os_debugging.h"
+#include "win-utils.h"
+
+/* ------------------------------------------------------------------------ */
+
+void cci_os_debug_vprintf (const char *in_format, va_list in_args) {
+ printf ( "%s %ld ", timestamp(), GetCurrentThreadId() );
+ vprintf ( in_format, in_args );
+ printf ( "\n" );
+ }
diff --git a/src/ccapi/common/win/cci_os_identifier.c b/src/ccapi/common/win/cci_os_identifier.c
index 7b44fe3..34659e0 100644
--- a/src/ccapi/common/win/cci_os_identifier.c
+++ b/src/ccapi/common/win/cci_os_identifier.c
@@ -1,58 +1,58 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "cci_common.h"
-#include "cci_os_identifier.h"
-
-#include <rpc.h>
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 cci_os_identifier_new_uuid (cci_uuid_string_t *out_uuid_string) {
- cc_int32 err = ccNoError;
- UUID uuid;
- char* uuidStringTemp;
-
- err = UuidCreate(&uuid);
-
- if (!err) {
- err = UuidToString(&uuid, &uuidStringTemp);
- }
-
- if (!err) {
- *out_uuid_string = malloc(1+strlen(uuidStringTemp));
-
- if (*out_uuid_string) {
- strcpy(*out_uuid_string, uuidStringTemp);
- }
-
- RpcStringFree(&uuidStringTemp);
- }
-
- cci_debug_printf("cci_os_identifier_new_uuid returning %s", *out_uuid_string);
-
- return cci_check_error (err);
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "cci_common.h"
+#include "cci_os_identifier.h"
+
+#include <rpc.h>
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_os_identifier_new_uuid (cci_uuid_string_t *out_uuid_string) {
+ cc_int32 err = ccNoError;
+ UUID uuid;
+ char* uuidStringTemp;
+
+ err = UuidCreate(&uuid);
+
+ if (!err) {
+ err = UuidToString(&uuid, &uuidStringTemp);
+ }
+
+ if (!err) {
+ *out_uuid_string = malloc(1+strlen(uuidStringTemp));
+
+ if (*out_uuid_string) {
+ strcpy(*out_uuid_string, uuidStringTemp);
+ }
+
+ RpcStringFree(&uuidStringTemp);
+ }
+
+ cci_debug_printf("cci_os_identifier_new_uuid returning %s", *out_uuid_string);
+
+ return cci_check_error (err);
} \ No newline at end of file
diff --git a/src/ccapi/common/win/ccs_reply.Acf b/src/ccapi/common/win/ccs_reply.Acf
index 89e8abe..aea44d7 100644
--- a/src/ccapi/common/win/ccs_reply.Acf
+++ b/src/ccapi/common/win/ccs_reply.Acf
@@ -1,31 +1,31 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-[implicit_handle(handle_t ccs_reply_IfHandle)]
-
-interface ccs_reply {
- [async] ccapi_listen();
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+[implicit_handle(handle_t ccs_reply_IfHandle)]
+
+interface ccs_reply {
+ [async] ccapi_listen();
+ }
diff --git a/src/ccapi/common/win/ccs_reply.Idl b/src/ccapi/common/win/ccs_reply.Idl
index 4c6f6f3..9035a4d 100644
--- a/src/ccapi/common/win/ccs_reply.Idl
+++ b/src/ccapi/common/win/ccs_reply.Idl
@@ -1,60 +1,60 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-[ uuid (6E3B5060-CA46-1067-B31A-00DD010662DA),
- version(1.0),
- pointer_default(unique)
-]
-
-/* This interface sends a cci_stream via rpc.
- */
-
-interface ccs_reply {
- const long HSIZE = sizeof(void*);
-
-/* The reply from the server to a request from the client: */
-void ccs_rpc_request_reply(
- [in] const long rpcmsg, /* Message type */
- [in, size_is(HSIZE)] const char tsphandle[],
- [in, string] const char* uuid,
- [in] const long srvStartTime, /* Server Start Time */
- [in] const long cbIn, /* Length of buffer */
- [in, size_is(cbIn)] const unsigned char chIn[], /* Data buffer */
- [out] long* status ); /* Return code */
-
-void ccs_rpc_connect_reply(
- [in] const long rpcmsg, /* Message type */
- [in, size_is(HSIZE)] const char tsphandle[],
- [in, string] const char* uuid,
- [in] const long srvStartTime, /* Server Start Time */
- [out] long* status ); /* Return code */
-
-void ccapi_listen(
- handle_t hBinding,
- [in] const long rpcmsg, /* Message type */
- [out] long* status ); /* Return code */
-
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+[ uuid (6E3B5060-CA46-1067-B31A-00DD010662DA),
+ version(1.0),
+ pointer_default(unique)
+]
+
+/* This interface sends a cci_stream via rpc.
+ */
+
+interface ccs_reply {
+ const long HSIZE = sizeof(void*);
+
+/* The reply from the server to a request from the client: */
+void ccs_rpc_request_reply(
+ [in] const long rpcmsg, /* Message type */
+ [in, size_is(HSIZE)] const char tsphandle[],
+ [in, string] const char* uuid,
+ [in] const long srvStartTime, /* Server Start Time */
+ [in] const long cbIn, /* Length of buffer */
+ [in, size_is(cbIn)] const unsigned char chIn[], /* Data buffer */
+ [out] long* status ); /* Return code */
+
+void ccs_rpc_connect_reply(
+ [in] const long rpcmsg, /* Message type */
+ [in, size_is(HSIZE)] const char tsphandle[],
+ [in, string] const char* uuid,
+ [in] const long srvStartTime, /* Server Start Time */
+ [out] long* status ); /* Return code */
+
+void ccapi_listen(
+ handle_t hBinding,
+ [in] const long rpcmsg, /* Message type */
+ [out] long* status ); /* Return code */
+
+ }
diff --git a/src/ccapi/common/win/ccs_request.Acf b/src/ccapi/common/win/ccs_request.Acf
index 853a152..625bcce 100644
--- a/src/ccapi/common/win/ccs_request.Acf
+++ b/src/ccapi/common/win/ccs_request.Acf
@@ -1,31 +1,31 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-[implicit_handle(handle_t ccs_request_IfHandle)]
-interface ccs_request
-{
-
-}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+[implicit_handle(handle_t ccs_request_IfHandle)]
+interface ccs_request
+{
+
+}
diff --git a/src/ccapi/common/win/ccs_request.idl b/src/ccapi/common/win/ccs_request.idl
index bd69314..8c68fd8 100644
--- a/src/ccapi/common/win/ccs_request.idl
+++ b/src/ccapi/common/win/ccs_request.idl
@@ -1,58 +1,58 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-[ uuid (906B0CE0-C70B-1067-B317-00DD010662DA),
- version(1.0),
- pointer_default(unique)
-]
-
-interface ccs_request {
-
-typedef char CC_CHAR;
-typedef unsigned char CC_UCHAR;
-typedef int CC_INT32;
-typedef unsigned int CC_UINT32;
-
-const long HSIZE = sizeof(void*);
-
-void ccs_rpc_request(
- [in] const long rpcmsg, /* Message type */
- [in, size_is(HSIZE)] const char tsphandle[],
- [in, string] const char* pszUUID, /* Requestor's UUID */
- [in] const long lenRequest, /* Length of buffer */
- [in, size_is(lenRequest)] const char* pszRequest, /* Data buffer */
- [in] const long serverStartTime,/* Which server session we're talking to */
- [out] long* status ); /* Return code */
-
-void ccs_rpc_connect(
- [in] const long rpcmsg, /* Message type */
- [in, size_is(HSIZE)] const char tsphandle[],
- [in, string] const char* pszUUID, /* Requestor's UUID */
- [out] long* status ); /* Return code */
-
-CC_UINT32 ccs_authenticate(
- [in, string] const CC_CHAR* name );
-}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+[ uuid (906B0CE0-C70B-1067-B317-00DD010662DA),
+ version(1.0),
+ pointer_default(unique)
+]
+
+interface ccs_request {
+
+typedef char CC_CHAR;
+typedef unsigned char CC_UCHAR;
+typedef int CC_INT32;
+typedef unsigned int CC_UINT32;
+
+const long HSIZE = sizeof(void*);
+
+void ccs_rpc_request(
+ [in] const long rpcmsg, /* Message type */
+ [in, size_is(HSIZE)] const char tsphandle[],
+ [in, string] const char* pszUUID, /* Requestor's UUID */
+ [in] const long lenRequest, /* Length of buffer */
+ [in, size_is(lenRequest)] const char* pszRequest, /* Data buffer */
+ [in] const long serverStartTime,/* Which server session we're talking to */
+ [out] long* status ); /* Return code */
+
+void ccs_rpc_connect(
+ [in] const long rpcmsg, /* Message type */
+ [in, size_is(HSIZE)] const char tsphandle[],
+ [in, string] const char* pszUUID, /* Requestor's UUID */
+ [out] long* status ); /* Return code */
+
+CC_UINT32 ccs_authenticate(
+ [in, string] const CC_CHAR* name );
+}
diff --git a/src/ccapi/common/win/tls.c b/src/ccapi/common/win/tls.c
index 411d709..cf8daa3 100644
--- a/src/ccapi/common/win/tls.c
+++ b/src/ccapi/common/win/tls.c
@@ -1,71 +1,71 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "string.h"
-
-#include "tls.h"
-
-struct tspdata* new_tspdata(char* uuid, time_t sst) {
- struct tspdata* p = (struct tspdata*)malloc(sizeof(struct tspdata));
- if (p) {
- memset(p, 0, sizeof(struct tspdata));
- p->_sst = sst;
- if (uuid) {strncpy(p->_uuid, uuid, UUID_SIZE-1);}
- }
- return p;
- }
-
-void delete_tspdata(struct tspdata* p) {
- if (p) free(p);
- }
-
-void tspdata_setUUID(struct tspdata* p, unsigned char __RPC_FAR* uuidString) {
- strncpy(p->_uuid, uuidString, UUID_SIZE-1);
- };
-
-void tspdata_setConnected (struct tspdata* p, BOOL b) {p->_CCAPI_Connected = b;}
-
-void tspdata_setReplyEvent(struct tspdata* p, HANDLE h) {p->_replyEvent = h;}
-
-void tspdata_setRpcAState (struct tspdata* p, RPC_ASYNC_STATE* rpcState) {
- p->_rpcState = rpcState;}
-
-void tspdata_setSST (struct tspdata* p, time_t t) {p->_sst = t;}
-
-void tspdata_setStream (struct tspdata* p, cci_stream_t s) {p->_stream = s;}
-
-
-BOOL tspdata_getConnected (struct tspdata* p) {return p->_CCAPI_Connected;}
-
-HANDLE tspdata_getReplyEvent(struct tspdata* p) {return p->_replyEvent;}
-
-time_t tspdata_getSST (const struct tspdata* p) {return p->_sst;}
-
-cci_stream_t tspdata_getStream (const struct tspdata* p) {return p->_stream;}
-
-char* tspdata_getUUID (const struct tspdata* p) {return p->_uuid;}
-
-RPC_ASYNC_STATE* tspdata_getRpcAState (const struct tspdata* p) {return p->_rpcState;}
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "string.h"
+
+#include "tls.h"
+
+struct tspdata* new_tspdata(char* uuid, time_t sst) {
+ struct tspdata* p = (struct tspdata*)malloc(sizeof(struct tspdata));
+ if (p) {
+ memset(p, 0, sizeof(struct tspdata));
+ p->_sst = sst;
+ if (uuid) {strncpy(p->_uuid, uuid, UUID_SIZE-1);}
+ }
+ return p;
+ }
+
+void delete_tspdata(struct tspdata* p) {
+ if (p) free(p);
+ }
+
+void tspdata_setUUID(struct tspdata* p, unsigned char __RPC_FAR* uuidString) {
+ strncpy(p->_uuid, uuidString, UUID_SIZE-1);
+ };
+
+void tspdata_setConnected (struct tspdata* p, BOOL b) {p->_CCAPI_Connected = b;}
+
+void tspdata_setReplyEvent(struct tspdata* p, HANDLE h) {p->_replyEvent = h;}
+
+void tspdata_setRpcAState (struct tspdata* p, RPC_ASYNC_STATE* rpcState) {
+ p->_rpcState = rpcState;}
+
+void tspdata_setSST (struct tspdata* p, time_t t) {p->_sst = t;}
+
+void tspdata_setStream (struct tspdata* p, cci_stream_t s) {p->_stream = s;}
+
+
+BOOL tspdata_getConnected (struct tspdata* p) {return p->_CCAPI_Connected;}
+
+HANDLE tspdata_getReplyEvent(struct tspdata* p) {return p->_replyEvent;}
+
+time_t tspdata_getSST (const struct tspdata* p) {return p->_sst;}
+
+cci_stream_t tspdata_getStream (const struct tspdata* p) {return p->_stream;}
+
+char* tspdata_getUUID (const struct tspdata* p) {return p->_uuid;}
+
+RPC_ASYNC_STATE* tspdata_getRpcAState (const struct tspdata* p) {return p->_rpcState;}
diff --git a/src/ccapi/common/win/tls.h b/src/ccapi/common/win/tls.h
index b18705e..3d988cd 100644
--- a/src/ccapi/common/win/tls.h
+++ b/src/ccapi/common/win/tls.h
@@ -1,70 +1,70 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-/* Thread local storage for client threads. */
-
-#ifndef _tls_h
-#define _tls_h
-
-#include "windows.h"
-#include "time.h"
-
-#include "cci_stream.h"
-
-#define UUID_SIZE 128
-
-/* The client code can be run in any client thread. The thread-specific data
- is defined here.
- */
-
-struct tspdata {
- BOOL _CCAPI_Connected;
- RPC_ASYNC_STATE* _rpcState;
- HANDLE _replyEvent;
- time_t _sst;
- cci_stream_t _stream;
- char _uuid[UUID_SIZE];
- };
-
-struct tspdata* new_tspdata (char* uuid, time_t sst);
-void delete_tspdata (struct tspdata* p);
-
-void tspdata_setConnected (struct tspdata* p, BOOL b);
-void tspdata_setReplyEvent(struct tspdata* p, HANDLE h);
-void tspdata_setRpcAState (struct tspdata* p, RPC_ASYNC_STATE* rpcState);
-void tspdata_setSST (struct tspdata* p, time_t t);
-void tspdata_setStream (struct tspdata* p, cci_stream_t s);
-void tspdata_setUUID (struct tspdata* p, unsigned char __RPC_FAR* uuidString);
-HANDLE tspdata_getReplyEvent(const struct tspdata* p);
-
-BOOL tspdata_getConnected(const struct tspdata* p);
-RPC_ASYNC_STATE* tspdata_getRpcAState(const struct tspdata* p);
-time_t tspdata_getSST (const struct tspdata* p);
-cci_stream_t tspdata_getStream (const struct tspdata* p);
-char* tspdata_getUUID (const struct tspdata* p);
-
-
-#endif _tls_h
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+/* Thread local storage for client threads. */
+
+#ifndef _tls_h
+#define _tls_h
+
+#include "windows.h"
+#include "time.h"
+
+#include "cci_stream.h"
+
+#define UUID_SIZE 128
+
+/* The client code can be run in any client thread. The thread-specific data
+ is defined here.
+ */
+
+struct tspdata {
+ BOOL _CCAPI_Connected;
+ RPC_ASYNC_STATE* _rpcState;
+ HANDLE _replyEvent;
+ time_t _sst;
+ cci_stream_t _stream;
+ char _uuid[UUID_SIZE];
+ };
+
+struct tspdata* new_tspdata (char* uuid, time_t sst);
+void delete_tspdata (struct tspdata* p);
+
+void tspdata_setConnected (struct tspdata* p, BOOL b);
+void tspdata_setReplyEvent(struct tspdata* p, HANDLE h);
+void tspdata_setRpcAState (struct tspdata* p, RPC_ASYNC_STATE* rpcState);
+void tspdata_setSST (struct tspdata* p, time_t t);
+void tspdata_setStream (struct tspdata* p, cci_stream_t s);
+void tspdata_setUUID (struct tspdata* p, unsigned char __RPC_FAR* uuidString);
+HANDLE tspdata_getReplyEvent(const struct tspdata* p);
+
+BOOL tspdata_getConnected(const struct tspdata* p);
+RPC_ASYNC_STATE* tspdata_getRpcAState(const struct tspdata* p);
+time_t tspdata_getSST (const struct tspdata* p);
+cci_stream_t tspdata_getStream (const struct tspdata* p);
+char* tspdata_getUUID (const struct tspdata* p);
+
+
+#endif _tls_h
diff --git a/src/ccapi/common/win/win-utils.c b/src/ccapi/common/win/win-utils.c
index c082142..4cba153 100644
--- a/src/ccapi/common/win/win-utils.c
+++ b/src/ccapi/common/win/win-utils.c
@@ -1,66 +1,66 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
-#include "windows.h"
-
-#include "win-utils.h"
-#include "cci_debugging.h"
-
-#pragma warning (disable : 4996)
-
-#define UUID_SIZE 128
-
-char* clientPrefix = "CCAPI_CLIENT_";
-char* serverPrefix = "CCS_LISTEN_";
-unsigned char* pszProtocolSequence = "ncalrpc";
-
-#define MAX_TIMESTAMP 40
-char _ts[MAX_TIMESTAMP];
-
-char* clientEndpoint(const char* UUID) {
- char* _clientEndpoint = (char*)malloc(strlen(UUID) + strlen(clientPrefix) + 2);
- strcpy(_clientEndpoint, clientPrefix);
- strncat(_clientEndpoint, UUID, UUID_SIZE);
-// cci_debug_printf("%s returning %s", __FUNCTION__, _clientEndpoint);
- return _clientEndpoint;
- }
-
-char* serverEndpoint(const char* user) {
- char* _serverEndpoint = (char*)malloc(strlen(user) + strlen(serverPrefix) + 2);
- strcpy(_serverEndpoint, serverPrefix);
- strncat(_serverEndpoint, user, UUID_SIZE);
- return _serverEndpoint;
- }
-
-char* timestamp() {
- SYSTEMTIME _stime;
- GetSystemTime(&_stime);
- GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &_stime, "HH:mm:ss", _ts, sizeof(_ts)-1);
- return _ts;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include "windows.h"
+
+#include "win-utils.h"
+#include "cci_debugging.h"
+
+#pragma warning (disable : 4996)
+
+#define UUID_SIZE 128
+
+char* clientPrefix = "CCAPI_CLIENT_";
+char* serverPrefix = "CCS_LISTEN_";
+unsigned char* pszProtocolSequence = "ncalrpc";
+
+#define MAX_TIMESTAMP 40
+char _ts[MAX_TIMESTAMP];
+
+char* clientEndpoint(const char* UUID) {
+ char* _clientEndpoint = (char*)malloc(strlen(UUID) + strlen(clientPrefix) + 2);
+ strcpy(_clientEndpoint, clientPrefix);
+ strncat(_clientEndpoint, UUID, UUID_SIZE);
+// cci_debug_printf("%s returning %s", __FUNCTION__, _clientEndpoint);
+ return _clientEndpoint;
+ }
+
+char* serverEndpoint(const char* user) {
+ char* _serverEndpoint = (char*)malloc(strlen(user) + strlen(serverPrefix) + 2);
+ strcpy(_serverEndpoint, serverPrefix);
+ strncat(_serverEndpoint, user, UUID_SIZE);
+ return _serverEndpoint;
+ }
+
+char* timestamp() {
+ SYSTEMTIME _stime;
+ GetSystemTime(&_stime);
+ GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &_stime, "HH:mm:ss", _ts, sizeof(_ts)-1);
+ return _ts;
} \ No newline at end of file
diff --git a/src/ccapi/common/win/win-utils.h b/src/ccapi/common/win/win-utils.h
index 97226e9..5dbb192 100644
--- a/src/ccapi/common/win/win-utils.h
+++ b/src/ccapi/common/win/win-utils.h
@@ -1,55 +1,55 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef _win_utils_h
-#define _win_utils_h
-
-#ifndef TRUE
-#define TRUE (1==1)
-#endif
-
-#ifndef FALSE
-#define FALSE (1==0)
-#endif
-
-static enum ccapiMsgType {
- CCMSG_INVALID = 0,
- CCMSG_CONNECT,
- CCMSG_REQUEST,
- CCMSG_CONNECT_REPLY,
- CCMSG_REQUEST_REPLY,
- CCMSG_DISCONNECT,
- CCMSG_LISTEN,
- CCMSG_PING
- };
-
-char* clientEndpoint(const char* UUID);
-char* serverEndpoint(const char* UUID);
-extern unsigned char* pszProtocolSequence;
-
-char* timestamp();
-
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef _win_utils_h
+#define _win_utils_h
+
+#ifndef TRUE
+#define TRUE (1==1)
+#endif
+
+#ifndef FALSE
+#define FALSE (1==0)
+#endif
+
+static enum ccapiMsgType {
+ CCMSG_INVALID = 0,
+ CCMSG_CONNECT,
+ CCMSG_REQUEST,
+ CCMSG_CONNECT_REPLY,
+ CCMSG_REQUEST_REPLY,
+ CCMSG_DISCONNECT,
+ CCMSG_LISTEN,
+ CCMSG_PING
+ };
+
+char* clientEndpoint(const char* UUID);
+char* serverEndpoint(const char* UUID);
+extern unsigned char* pszProtocolSequence;
+
+char* timestamp();
+
#endif // _win_utils_h \ No newline at end of file
diff --git a/src/ccapi/doc/CCAPI-Windows-Design.html b/src/ccapi/doc/CCAPI-Windows-Design.html
index 8be1614..72af7e9 100644
--- a/src/ccapi/doc/CCAPI-Windows-Design.html
+++ b/src/ccapi/doc/CCAPI-Windows-Design.html
@@ -1,148 +1,148 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-<title>Windows CCAPI RPC design</title>
-<style type="text/css">
-<!--
-.style2 {color: 0}
-.style3 {font-family: "Courier New", Courier, monospace}
-.style5 {color: #CC3300}
-.style6 {color: #999999}
-.style7 {color: #000099}
--->
-</style>
-</head>
-
-<body>
-<h2 class="style5">Proposed RPC design for Windows CCAPI clients and server</h2>
-<p>The proposal is for a single user; the solution is replicated for each user logged onto the PC.</p>
-<h2>Conventions &amp; clarifications </h2>
-<p>&quot;Client&quot; and &quot;server&quot; refer to the CCAPI client and server. </p>
-<p>The CCAPI client acts as both an RPC client and RPC server and the CCAPI server acts as both an RPC client and RPC server. </p>
-<ul>
- <li class="style2">The RPC call from the CCAPI client to the CCAPI server is called the &quot;request.&quot; In this mode, the CCAPI client is the RPC client and the CCAPI server is the RPC server.</li>
- <li class="style2">The RPC call from the CCAPI server to the CCAPI client is called the &quot;reply.&quot; In this mode, the CCAPI client is the RPC server and the CCAPI server is the RPC client. </li>
-</ul>
-<p>The Windows username is referred to below as &quot;&lt;USER&gt;.&quot; </p>
-<p>The Windows Logon Security Identifier is referred to as &quot;&lt;LSID&gt;.&quot; </p>
-<p>&lt;UUID&gt; means a thread-specific UUID.</p>
-<p>&lt;SST&gt; means <strong>s</strong>erver <strong>s</strong>tart <strong>t</strong>ime, a time_t. </p>
-<p>A description of client and server authentication has not been added yet.</p>
-<h2>Design Requirements </h2>
-<ul>
- <li>The server's OS-independent code is single threaded, because it must operate on platforms that do not allow multiple threads. </li>
- <li>The client and server must be able to maintain connections, where state is maintained between individual messages.</li>
- <li>Individual messages must be handled in a single threaded server. </li>
- <li>The server must be able to detect when a client dies, so that any connection state can be cleaned up. </li>
-</ul>
-<h2>Design</h2>
-<p>The server and each client create an RPC endpoint. The server's endpoint is CCS_&lt;LSID&gt; and the client's endpoint is CCAPI_&lt;UUID&gt;, where each client geta a UUID. </p>
-<p>On Windows, the server's ccs_pipe_t type is a char* and is set to the client UUID.</p>
-<h3>How is the request handled in the server and the reply sent to the client? </h3>
-<p>One straightforward way is for the reply to be the returned data in the request RPC call (an [out] parameter). That is, data passed from the RPC server to the RPC client. The request handler calls <span class="style3">ccs_server_handle_request</span>. Eventually, the server code calls <span class="style3">ccs_os_server_send_reply, </span>which saves the reply somewhere. When the server eventually returns to the request handler, the handler returns the saved reply to the client.</p>
-<p>But this doesn't work. If two clients A and B ask for the same lock, A will acquire the lock and B will have to wait. But if the single threaded server waits for B's lock, it will never handle A's unlock message. Therefore the server must return to B's request handler and <em>not </em>send a reply to B. So this method will not work. </p>
-<p>Instead, there are listener and worker threads in Windows-specific code. </p>
-<p>The client's <span class="style3">cci_os_ipc </span>function waits for <span class="style3">ccs_reply</span>. The client sends the request, including <em>it's UUID, </em>from which the server can construct the endpoint on which to call <span class="style3">ccs_reply</span>. </p>
-<p>The server's listener thread listens for RPC requests. The request handler puts each request/<em>reply</em> endpoint in a queue and returns to the client.</p>
-<p>The server's worker thread removes items from the queue, calls <span class="style3">ccs_server_handle_request</span>. <span class="style3">ccs_server_handle_request</span> takes both the request data and the client UUID . Eventually <span class="style3">ccs_os_server_send_reply</span> is called, with the reply data and client UUID in the reply_pipe. <span class="style3">ccs_os_server_send_reply</span> calls <span class="style3">ccs_reply </span>on the client's endpoint, which sends the reply to the client. </p>
-<p>Is there any security issue with the client listening for RPC calls from the server?</p>
-<h3>Connections</h3>
-<p>If the client wants state to be maintained on the server, the client creates a connection. When the connection is closed, the server cleans up any state associated with the connection. </p>
-<p>Any given thread in an application process could want to create a connection. When cci_ipc_thread_init is called, the connection thread-local variables are initialized. New connections are created when cci_os_ipc() (via _cci_ipc_send) is called and no connection was previously established. Basically we lazily establish connections so the client doesn't talk to the server until it has to.</p>
-<h3>Detecting client exit</h3>
-<p>The server must be able to detect when clients disappear, so the server can free any resources that had been held for the client. </p>
-<p>The Windows RPC API does not appear to provide a notification for an endpoint disappearing. It does provide a way to ask if an endpoint is listening. This is useful for polling, but we want a better performing solution than that. </p>
-<p>The client has an <em>isAlive </em>function on its endpoint. </p>
-<p>To detect the client disappearing without using polling, the server makes an asynchronous call to the <em>isAlive </em>function on the client's endpoint. The <em>isAlive </em>function never returns. When the client exits for any reason, it's <em></em>endpoint will be closed and the server's function call will return an error. The asynchronous call on the server means no additional threads are used. </p>
-<p>Windows provides a number of notification methods to signal I/O completion. Among them are I/O completion ports and callback functions. I chose callback functions because they appear to consume fewer resources. </p>
-<h3>RPC Endpoint / Function summary</h3>
-<ul>
- <li>The server creates one CCS_&lt;LSID&gt; endpoint to listen for connection requests and client requests.
- It has the functions
- <ul>
- <li>ccs_rpc_connect(msgtype, UUIDlen, &lt;UUID&gt;, status)</li>
- <li>ccs_rpc_request(msgtype, UUIDlen, &lt;UUID&gt;, msglen, msg, SST, status) called by client. NB: The windows server sets the <span class="style3">in_client_pipe </span>to the <span class="style3">in_reply_pipe</span>.<br />
- </li>
- </ul>
- </li>
- <li>Each client thread creates a CCAPI_&lt;UUID&gt; endpoint. It has the functions
- <ul>
- <li>isAlive [function never returns.] </li>
- <li>ccs_rpc_request_reply(msgtype, SST, replylen, reply, status)</li>
- <li>ccs_rpc_connect_reply(msgtype, SST, status</li>
- </ul>
- </li>
-</ul>
-<h2>Windows-specific implementation details </h2>
-<h3>Client CCAPI library initialization:</h3>
-<p>This code runs when the CCAPI DLL is loaded. </p>
-<ul>
- <li>?</li>
-</ul>
-<h3>Client initialization: </h3>
-<p>This code runs when cci_os_ipc_thread_init is called: </p>
-<ul>
- <li>Generate &lt;UUID&gt; and save in thread-specific storage. This serves as the client ID / ccs_pipe_t. </li>
- <li>Create client endpoint.</li>
- <li>Listen on client <em></em>endpoint.</li>
- <li>Create canonical server connection endpoint from the &lt;LSID&gt;, which the client and server should have in common. </li>
- <li>Test if server is listening to the CCS_&lt;LSID&gt; endpoint.
- <ul>
- <li>If not, quit. (! Start it?) </li>
- </ul>
- </li>
- <li>Call ccs_connect(&lt;UUID&gt;) on the CCS_&lt;LSID&gt; endpoint.</li>
- <li>Save SST in thread-specific storage. </li>
-</ul>
-<h3>Server initialization:</h3>
-<p class="style6">[old]</p>
-<ul>
- <li class="style6">Server is initialized by client starting a new process. There should be only one server process per Windows username. </li>
-</ul>
-<p class="style7">[new]</p>
-<ul>
- <li class="style7">Server is started by kfwlogon (as is done currently). </li>
- <li>Capture <strong>s</strong>erver <strong>s</strong>tart <strong>t</strong>ime (SST). </li>
- <li>Start listener thread, create listener endpoint, listen on CCS_&lt;LSID&gt; endpoint. </li>
-</ul>
-<h3>Establishing a connection: </h3>
-<ul>
- <li>Client calls ccs_connect(&lt;UUID&gt;) on server's CCS_&lt;LSID&gt; endpoint.</li>
- <li>Client gets back and stores SST in thread-specific storage.</li>
- <li>If new connection, server ...
- <ul>
- <li>adds connection to connection table</li>
- <li>calls isAlive on CCAPI_&lt;UUID&gt;.
- <ul>
- <li>NB: isAlive never returns. </li>
- </ul>
- </li>
- </ul>
- </li>
-</ul>
-<h3>Client request:</h3>
-<p>The server's reply to the client's request is not synchronous.</p>
-<ul>
- <li>Client calls ccs_rpc_request(msglen, msg, msgtype, UUIDlen, &lt;UUID&gt;, SST, status) on server's endpoint.</li>
- <li>Server listen thread receives message, queues request.</li>
- <li>Server worker thread dequeues request, processes, calls ccs_rpc_reply(replylen, reply, msgtype, status) on CCAPI_&lt;UUID&gt;.</li>
- <li>Server checks SST. If server's SST is different, it means server has restarted since client created connection. </li>
- <li>Client receives reply. </li>
-</ul>
-<h3>Detecting client exit</h3>
-<ul>
- <li>When connection created, client created an endpoint.</li>
- <li>Server calls isAlive on client's endpoint. </li>
- <li>When isAlive returns, the server's notification callback will be called. Call back routine queues a DISCONNECT pseudo-message. When the server's worker thread handles the DISCONNECT, it will release connection resources.</li>
-</ul>
-<h3>Detecting server exit </h3>
-<ul>
- <li>Client's call to ccs_rpc_request will return an error if the server has gone away. </li>
-</ul>
-<p>&nbsp;</p>
-<p>------<br />
- Stop: <br />
-Start: </p>
-</body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>Windows CCAPI RPC design</title>
+<style type="text/css">
+<!--
+.style2 {color: 0}
+.style3 {font-family: "Courier New", Courier, monospace}
+.style5 {color: #CC3300}
+.style6 {color: #999999}
+.style7 {color: #000099}
+-->
+</style>
+</head>
+
+<body>
+<h2 class="style5">Proposed RPC design for Windows CCAPI clients and server</h2>
+<p>The proposal is for a single user; the solution is replicated for each user logged onto the PC.</p>
+<h2>Conventions &amp; clarifications </h2>
+<p>&quot;Client&quot; and &quot;server&quot; refer to the CCAPI client and server. </p>
+<p>The CCAPI client acts as both an RPC client and RPC server and the CCAPI server acts as both an RPC client and RPC server. </p>
+<ul>
+ <li class="style2">The RPC call from the CCAPI client to the CCAPI server is called the &quot;request.&quot; In this mode, the CCAPI client is the RPC client and the CCAPI server is the RPC server.</li>
+ <li class="style2">The RPC call from the CCAPI server to the CCAPI client is called the &quot;reply.&quot; In this mode, the CCAPI client is the RPC server and the CCAPI server is the RPC client. </li>
+</ul>
+<p>The Windows username is referred to below as &quot;&lt;USER&gt;.&quot; </p>
+<p>The Windows Logon Security Identifier is referred to as &quot;&lt;LSID&gt;.&quot; </p>
+<p>&lt;UUID&gt; means a thread-specific UUID.</p>
+<p>&lt;SST&gt; means <strong>s</strong>erver <strong>s</strong>tart <strong>t</strong>ime, a time_t. </p>
+<p>A description of client and server authentication has not been added yet.</p>
+<h2>Design Requirements </h2>
+<ul>
+ <li>The server's OS-independent code is single threaded, because it must operate on platforms that do not allow multiple threads. </li>
+ <li>The client and server must be able to maintain connections, where state is maintained between individual messages.</li>
+ <li>Individual messages must be handled in a single threaded server. </li>
+ <li>The server must be able to detect when a client dies, so that any connection state can be cleaned up. </li>
+</ul>
+<h2>Design</h2>
+<p>The server and each client create an RPC endpoint. The server's endpoint is CCS_&lt;LSID&gt; and the client's endpoint is CCAPI_&lt;UUID&gt;, where each client geta a UUID. </p>
+<p>On Windows, the server's ccs_pipe_t type is a char* and is set to the client UUID.</p>
+<h3>How is the request handled in the server and the reply sent to the client? </h3>
+<p>One straightforward way is for the reply to be the returned data in the request RPC call (an [out] parameter). That is, data passed from the RPC server to the RPC client. The request handler calls <span class="style3">ccs_server_handle_request</span>. Eventually, the server code calls <span class="style3">ccs_os_server_send_reply, </span>which saves the reply somewhere. When the server eventually returns to the request handler, the handler returns the saved reply to the client.</p>
+<p>But this doesn't work. If two clients A and B ask for the same lock, A will acquire the lock and B will have to wait. But if the single threaded server waits for B's lock, it will never handle A's unlock message. Therefore the server must return to B's request handler and <em>not </em>send a reply to B. So this method will not work. </p>
+<p>Instead, there are listener and worker threads in Windows-specific code. </p>
+<p>The client's <span class="style3">cci_os_ipc </span>function waits for <span class="style3">ccs_reply</span>. The client sends the request, including <em>it's UUID, </em>from which the server can construct the endpoint on which to call <span class="style3">ccs_reply</span>. </p>
+<p>The server's listener thread listens for RPC requests. The request handler puts each request/<em>reply</em> endpoint in a queue and returns to the client.</p>
+<p>The server's worker thread removes items from the queue, calls <span class="style3">ccs_server_handle_request</span>. <span class="style3">ccs_server_handle_request</span> takes both the request data and the client UUID . Eventually <span class="style3">ccs_os_server_send_reply</span> is called, with the reply data and client UUID in the reply_pipe. <span class="style3">ccs_os_server_send_reply</span> calls <span class="style3">ccs_reply </span>on the client's endpoint, which sends the reply to the client. </p>
+<p>Is there any security issue with the client listening for RPC calls from the server?</p>
+<h3>Connections</h3>
+<p>If the client wants state to be maintained on the server, the client creates a connection. When the connection is closed, the server cleans up any state associated with the connection. </p>
+<p>Any given thread in an application process could want to create a connection. When cci_ipc_thread_init is called, the connection thread-local variables are initialized. New connections are created when cci_os_ipc() (via _cci_ipc_send) is called and no connection was previously established. Basically we lazily establish connections so the client doesn't talk to the server until it has to.</p>
+<h3>Detecting client exit</h3>
+<p>The server must be able to detect when clients disappear, so the server can free any resources that had been held for the client. </p>
+<p>The Windows RPC API does not appear to provide a notification for an endpoint disappearing. It does provide a way to ask if an endpoint is listening. This is useful for polling, but we want a better performing solution than that. </p>
+<p>The client has an <em>isAlive </em>function on its endpoint. </p>
+<p>To detect the client disappearing without using polling, the server makes an asynchronous call to the <em>isAlive </em>function on the client's endpoint. The <em>isAlive </em>function never returns. When the client exits for any reason, it's <em></em>endpoint will be closed and the server's function call will return an error. The asynchronous call on the server means no additional threads are used. </p>
+<p>Windows provides a number of notification methods to signal I/O completion. Among them are I/O completion ports and callback functions. I chose callback functions because they appear to consume fewer resources. </p>
+<h3>RPC Endpoint / Function summary</h3>
+<ul>
+ <li>The server creates one CCS_&lt;LSID&gt; endpoint to listen for connection requests and client requests.
+ It has the functions
+ <ul>
+ <li>ccs_rpc_connect(msgtype, UUIDlen, &lt;UUID&gt;, status)</li>
+ <li>ccs_rpc_request(msgtype, UUIDlen, &lt;UUID&gt;, msglen, msg, SST, status) called by client. NB: The windows server sets the <span class="style3">in_client_pipe </span>to the <span class="style3">in_reply_pipe</span>.<br />
+ </li>
+ </ul>
+ </li>
+ <li>Each client thread creates a CCAPI_&lt;UUID&gt; endpoint. It has the functions
+ <ul>
+ <li>isAlive [function never returns.] </li>
+ <li>ccs_rpc_request_reply(msgtype, SST, replylen, reply, status)</li>
+ <li>ccs_rpc_connect_reply(msgtype, SST, status</li>
+ </ul>
+ </li>
+</ul>
+<h2>Windows-specific implementation details </h2>
+<h3>Client CCAPI library initialization:</h3>
+<p>This code runs when the CCAPI DLL is loaded. </p>
+<ul>
+ <li>?</li>
+</ul>
+<h3>Client initialization: </h3>
+<p>This code runs when cci_os_ipc_thread_init is called: </p>
+<ul>
+ <li>Generate &lt;UUID&gt; and save in thread-specific storage. This serves as the client ID / ccs_pipe_t. </li>
+ <li>Create client endpoint.</li>
+ <li>Listen on client <em></em>endpoint.</li>
+ <li>Create canonical server connection endpoint from the &lt;LSID&gt;, which the client and server should have in common. </li>
+ <li>Test if server is listening to the CCS_&lt;LSID&gt; endpoint.
+ <ul>
+ <li>If not, quit. (! Start it?) </li>
+ </ul>
+ </li>
+ <li>Call ccs_connect(&lt;UUID&gt;) on the CCS_&lt;LSID&gt; endpoint.</li>
+ <li>Save SST in thread-specific storage. </li>
+</ul>
+<h3>Server initialization:</h3>
+<p class="style6">[old]</p>
+<ul>
+ <li class="style6">Server is initialized by client starting a new process. There should be only one server process per Windows username. </li>
+</ul>
+<p class="style7">[new]</p>
+<ul>
+ <li class="style7">Server is started by kfwlogon (as is done currently). </li>
+ <li>Capture <strong>s</strong>erver <strong>s</strong>tart <strong>t</strong>ime (SST). </li>
+ <li>Start listener thread, create listener endpoint, listen on CCS_&lt;LSID&gt; endpoint. </li>
+</ul>
+<h3>Establishing a connection: </h3>
+<ul>
+ <li>Client calls ccs_connect(&lt;UUID&gt;) on server's CCS_&lt;LSID&gt; endpoint.</li>
+ <li>Client gets back and stores SST in thread-specific storage.</li>
+ <li>If new connection, server ...
+ <ul>
+ <li>adds connection to connection table</li>
+ <li>calls isAlive on CCAPI_&lt;UUID&gt;.
+ <ul>
+ <li>NB: isAlive never returns. </li>
+ </ul>
+ </li>
+ </ul>
+ </li>
+</ul>
+<h3>Client request:</h3>
+<p>The server's reply to the client's request is not synchronous.</p>
+<ul>
+ <li>Client calls ccs_rpc_request(msglen, msg, msgtype, UUIDlen, &lt;UUID&gt;, SST, status) on server's endpoint.</li>
+ <li>Server listen thread receives message, queues request.</li>
+ <li>Server worker thread dequeues request, processes, calls ccs_rpc_reply(replylen, reply, msgtype, status) on CCAPI_&lt;UUID&gt;.</li>
+ <li>Server checks SST. If server's SST is different, it means server has restarted since client created connection. </li>
+ <li>Client receives reply. </li>
+</ul>
+<h3>Detecting client exit</h3>
+<ul>
+ <li>When connection created, client created an endpoint.</li>
+ <li>Server calls isAlive on client's endpoint. </li>
+ <li>When isAlive returns, the server's notification callback will be called. Call back routine queues a DISCONNECT pseudo-message. When the server's worker thread handles the DISCONNECT, it will release connection resources.</li>
+</ul>
+<h3>Detecting server exit </h3>
+<ul>
+ <li>Client's call to ccs_rpc_request will return an error if the server has gone away. </li>
+</ul>
+<p>&nbsp;</p>
+<p>------<br />
+ Stop: <br />
+Start: </p>
+</body>
+</html>
diff --git a/src/ccapi/lib/ccapi_ccache.c b/src/ccapi/lib/ccapi_ccache.c
index f168c0a..3905a06 100644
--- a/src/ccapi/lib/ccapi_ccache.c
+++ b/src/ccapi/lib/ccapi_ccache.c
@@ -45,6 +45,7 @@ typedef struct cci_ccache_d {
#endif
cci_identifier_t identifier;
cc_time_t last_wait_for_change_time;
+ cc_uint32 compat_version;
} *cci_ccache_t;
/* ------------------------------------------------------------------------ */
@@ -156,19 +157,6 @@ cc_int32 ccapi_ccache_release (cc_ccache_t io_ccache)
if (!err) {
cci_identifier_release (ccache->identifier);
-#if TARGET_OS_MAC
-#warning Workaround for AppleConnect crash causes leak
- CFBundleRef main_bundle = CFBundleGetMainBundle ();
- if (main_bundle) {
- CFStringRef bundle_id = CFBundleGetIdentifier (main_bundle);
- if (bundle_id) {
- CFStringRef ac_id = CFSTR("com.apple.ist.ds.appleconnect");
- if (CFStringCompare (bundle_id, ac_id, 0) == kCFCompareEqualTo) {
- return ccNoError;
- }
- }
- }
-#endif
free ((char *) ccache->functions);
free (ccache);
}
@@ -379,7 +367,7 @@ cc_int32 ccapi_ccache_store_credentials (cc_ccache_t io_ccache,
}
if (!err) {
- err = cci_cred_union_write (in_credentials_union, request);
+ err = cci_credentials_union_write (in_credentials_union, request);
}
if (!err) {
@@ -770,3 +758,42 @@ cc_int32 ccapi_ccache_clear_kdc_time_offset (cc_ccache_t io_ccache,
return cci_check_error (err);
}
+
+#ifdef TARGET_OS_MAC
+#pragma mark -
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_ccache_get_compat_version (cc_ccache_t in_ccache,
+ cc_uint32 *out_compat_version)
+{
+ cc_int32 err = ccNoError;
+ cci_ccache_t ccache = (cci_ccache_t) in_ccache;
+
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_compat_version) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ *out_compat_version = ccache->compat_version;
+ }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_ccache_set_compat_version (cc_ccache_t io_ccache,
+ cc_uint32 in_compat_version)
+{
+ cc_int32 err = ccNoError;
+ cci_ccache_t ccache = (cci_ccache_t) io_ccache;
+
+ if (!io_ccache) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ ccache->compat_version = in_compat_version;
+ }
+
+ return cci_check_error (err);
+}
diff --git a/src/ccapi/lib/ccapi_ccache.h b/src/ccapi/lib/ccapi_ccache.h
index 82a9f6c..73091b7 100644
--- a/src/ccapi/lib/ccapi_ccache.h
+++ b/src/ccapi/lib/ccapi_ccache.h
@@ -96,4 +96,11 @@ cc_int32 ccapi_ccache_set_kdc_time_offset (cc_ccache_t io_ccache,
cc_int32 ccapi_ccache_clear_kdc_time_offset (cc_ccache_t io_ccache,
cc_uint32 in_credentials_version);
+cc_int32 cci_ccache_get_compat_version (cc_ccache_t in_ccache,
+ cc_uint32 *out_compat_version);
+
+cc_int32 cci_ccache_set_compat_version (cc_ccache_t io_ccache,
+ cc_uint32 in_compat_version);
+
+
#endif /* CCAPI_CCACHE_H */
diff --git a/src/ccapi/lib/ccapi_ccache_iterator.c b/src/ccapi/lib/ccapi_ccache_iterator.c
index 815da36..26162af 100644
--- a/src/ccapi/lib/ccapi_ccache_iterator.c
+++ b/src/ccapi/lib/ccapi_ccache_iterator.c
@@ -36,6 +36,7 @@ typedef struct cci_ccache_iterator_d {
cc_ccache_iterator_f *vector_functions;
#endif
cci_identifier_t identifier;
+ char *saved_ccache_name;
} *cci_ccache_iterator_t;
/* ------------------------------------------------------------------------ */
@@ -43,6 +44,7 @@ typedef struct cci_ccache_iterator_d {
struct cci_ccache_iterator_d cci_ccache_iterator_initializer = {
NULL
VECTOR_FUNCTIONS_INITIALIZER,
+ NULL,
NULL
};
@@ -125,6 +127,7 @@ cc_int32 ccapi_ccache_iterator_release (cc_ccache_iterator_t io_ccache_iterator)
if (!err) {
free ((char *) ccache_iterator->functions);
cci_identifier_release (ccache_iterator->identifier);
+ free (ccache_iterator->saved_ccache_name);
free (ccache_iterator);
}
@@ -222,3 +225,49 @@ cc_int32 ccapi_ccache_iterator_clone (cc_ccache_iterator_t in_ccache_iterator,
return cci_check_error (err);
}
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_ccache_iterator_get_saved_ccache_name (cc_ccache_iterator_t in_ccache_iterator,
+ const char **out_saved_ccache_name)
+{
+ cc_int32 err = ccNoError;
+ cci_ccache_iterator_t ccache_iterator = (cci_ccache_iterator_t) in_ccache_iterator;
+
+ if (!in_ccache_iterator ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_saved_ccache_name) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ *out_saved_ccache_name = ccache_iterator->saved_ccache_name;
+ }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_ccache_iterator_set_saved_ccache_name (cc_ccache_iterator_t io_ccache_iterator,
+ const char *in_saved_ccache_name)
+{
+ cc_int32 err = ccNoError;
+ cci_ccache_iterator_t ccache_iterator = (cci_ccache_iterator_t) io_ccache_iterator;
+ char *new_saved_ccache_name = NULL;
+
+ if (!io_ccache_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err && in_saved_ccache_name) {
+ new_saved_ccache_name = strdup (in_saved_ccache_name);
+ if (!new_saved_ccache_name) { err = ccErrNoMem; }
+ }
+
+ if (!err) {
+ free (ccache_iterator->saved_ccache_name);
+
+ ccache_iterator->saved_ccache_name = new_saved_ccache_name;
+ new_saved_ccache_name = NULL; /* take ownership */
+ }
+
+ free (new_saved_ccache_name);
+
+ return cci_check_error (err);
+}
diff --git a/src/ccapi/lib/ccapi_ccache_iterator.h b/src/ccapi/lib/ccapi_ccache_iterator.h
index 0a5a4f4..8b07b07 100644
--- a/src/ccapi/lib/ccapi_ccache_iterator.h
+++ b/src/ccapi/lib/ccapi_ccache_iterator.h
@@ -43,4 +43,10 @@ cc_int32 ccapi_ccache_iterator_next (cc_ccache_iterator_t in_ccache_iterator,
cc_int32 ccapi_ccache_iterator_clone (cc_ccache_iterator_t in_ccache_iterator,
cc_ccache_iterator_t *out_ccache_iterator);
+cc_int32 cci_ccache_iterator_get_saved_ccache_name (cc_ccache_iterator_t in_ccache_iterator,
+ const char **out_saved_ccache_name);
+
+cc_int32 cci_ccache_iterator_set_saved_ccache_name (cc_ccache_iterator_t io_ccache_iterator,
+ const char *in_saved_ccache_name);
+
#endif /* CCAPI_CCACHE_ITERATOR_H */
diff --git a/src/ccapi/lib/ccapi_context.c b/src/ccapi/lib/ccapi_context.c
index 7a165cf..3b8d60e 100644
--- a/src/ccapi/lib/ccapi_context.c
+++ b/src/ccapi/lib/ccapi_context.c
@@ -122,9 +122,6 @@ cc_int32 cc_initialize (cc_context_t *out_context,
if (!err) {
switch (in_version) {
case ccapi_version_2:
- err = CC_BAD_API_VERSION;
- break;
-
case ccapi_version_3:
case ccapi_version_4:
case ccapi_version_5:
diff --git a/src/ccapi/lib/ccapi_credentials.c b/src/ccapi/lib/ccapi_credentials.c
index 4e1f48e..3c40478 100644
--- a/src/ccapi/lib/ccapi_credentials.c
+++ b/src/ccapi/lib/ccapi_credentials.c
@@ -53,7 +53,7 @@ cc_credentials_f cci_credentials_f_initializer = {
ccapi_credentials_compare
};
-cc_credentials_union cci_cred_union_initializer = {
+cc_credentials_union cci_credentials_union_initializer = {
0,
{ NULL }
};
@@ -92,7 +92,7 @@ cc_int32 cci_credentials_read (cc_credentials_t *out_credentials,
}
if (!err) {
- err = cci_cred_union_read (&credentials->data, in_stream);
+ err = cci_credentials_union_read (&credentials->data, in_stream);
}
if (!err) {
@@ -156,7 +156,7 @@ cc_int32 ccapi_credentials_release (cc_credentials_t io_credentials)
if (!io_credentials) { err = ccErrBadParam; }
if (!err) {
- cci_cred_union_release (credentials->data);
+ cci_credentials_union_release (credentials->data);
free ((char *) credentials->functions);
cci_identifier_release (credentials->identifier);
free (credentials);
diff --git a/src/ccapi/lib/ccapi_credentials_iterator.c b/src/ccapi/lib/ccapi_credentials_iterator.c
index a99e52b..4f38d07 100644
--- a/src/ccapi/lib/ccapi_credentials_iterator.c
+++ b/src/ccapi/lib/ccapi_credentials_iterator.c
@@ -36,6 +36,7 @@ typedef struct cci_credentials_iterator_d {
cc_credentials_iterator_f *vector_functions;
#endif
cci_identifier_t identifier;
+ cc_uint32 compat_version;
} *cci_credentials_iterator_t;
/* ------------------------------------------------------------------------ */
@@ -43,7 +44,8 @@ typedef struct cci_credentials_iterator_d {
struct cci_credentials_iterator_d cci_credentials_iterator_initializer = {
NULL
VECTOR_FUNCTIONS_INITIALIZER,
- NULL
+ NULL,
+ 0
};
cc_credentials_iterator_f cci_credentials_iterator_f_initializer = {
@@ -192,3 +194,42 @@ cc_int32 ccapi_credentials_iterator_clone (cc_credentials_iterator_t in_credent
return cci_check_error (err);
}
+
+#ifdef TARGET_OS_MAC
+#pragma mark -
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_credentials_iterator_get_compat_version (cc_credentials_iterator_t in_credentials_iterator,
+ cc_uint32 *out_compat_version)
+{
+ cc_int32 err = ccNoError;
+ cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) in_credentials_iterator;
+
+ if (!in_credentials_iterator) { err = cci_check_error (ccErrBadParam); }
+ if (!out_compat_version ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ *out_compat_version = credentials_iterator->compat_version;
+ }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_credentials_iterator_set_compat_version (cc_credentials_iterator_t io_credentials_iterator,
+ cc_uint32 in_compat_version)
+{
+ cc_int32 err = ccNoError;
+ cci_credentials_iterator_t credentials_iterator = (cci_credentials_iterator_t) io_credentials_iterator;
+
+ if (!io_credentials_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ credentials_iterator->compat_version = in_compat_version;
+ }
+
+ return cci_check_error (err);
+}
diff --git a/src/ccapi/lib/ccapi_credentials_iterator.h b/src/ccapi/lib/ccapi_credentials_iterator.h
index 7ffbd23..12647d4 100644
--- a/src/ccapi/lib/ccapi_credentials_iterator.h
+++ b/src/ccapi/lib/ccapi_credentials_iterator.h
@@ -43,4 +43,10 @@ cc_int32 ccapi_credentials_iterator_next (cc_credentials_iterator_t in_credenti
cc_int32 ccapi_credentials_iterator_clone (cc_credentials_iterator_t in_credentials_iterator,
cc_credentials_iterator_t *out_credentials_iterator);
+cc_int32 cci_credentials_iterator_get_compat_version (cc_credentials_iterator_t in_credentials_iterator,
+ cc_uint32 *out_compat_version);
+
+cc_int32 cci_credentials_iterator_set_compat_version (cc_credentials_iterator_t io_credentials_iterator,
+ cc_uint32 in_compat_version);
+
#endif /* CCAPI_CREDENTIALS_ITERATOR_H */
diff --git a/src/ccapi/lib/ccapi_v2.c b/src/ccapi/lib/ccapi_v2.c
index 0036c70..8a25ae6 100644
--- a/src/ccapi/lib/ccapi_v2.c
+++ b/src/ccapi/lib/ccapi_v2.c
@@ -25,21 +25,109 @@
*/
#include "cci_common.h"
+#include "ccapi_string.h"
+#include "ccapi_context.h"
+#include "ccapi_ccache.h"
+#include "ccapi_ccache_iterator.h"
+#include "ccapi_credentials.h"
+#include "ccapi_credentials_iterator.h"
#include <CredentialsCache2.h>
+infoNC infoNC_initializer = { NULL, NULL, CC_CRED_UNKNOWN };
+
/* ------------------------------------------------------------------------ */
-cc_result cc_shutdown (apiCB **io_context)
+static cc_int32 cci_remap_version (cc_int32 in_v2_version,
+ cc_uint32 *out_v3_version)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!out_v3_version) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ if (in_v2_version == CC_CRED_V4) {
+ *out_v3_version = cc_credentials_v4;
+
+ } else if (in_v2_version == CC_CRED_V5) {
+ *out_v3_version = cc_credentials_v5;
+
+ } else {
+ err = ccErrBadCredentialsVersion;
+ }
+ }
+
+ return cci_check_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+static cc_result cci_remap_error (cc_result in_error)
+{
+ switch (in_error) {
+ case ccNoError:
+ return CC_NOERROR;
+
+ case ccIteratorEnd:
+ return CC_END;
+
+ case ccErrBadParam:
+ case ccErrInvalidCredentials:
+ case ccErrInvalidCCacheIterator:
+ case ccErrInvalidCredentialsIterator:
+ case ccErrBadLockType:
+ return CC_BAD_PARM;
+
+ case ccErrNoMem:
+ return CC_NOMEM;
+
+ case ccErrInvalidContext:
+ case ccErrInvalidCCache:
+ case ccErrCCacheNotFound:
+ return CC_NO_EXIST;
+
+ case ccErrCredentialsNotFound:
+ return CC_NOTFOUND;
+
+ case ccErrBadName:
+ return CC_BADNAME;
+
+ case ccErrContextLocked:
+ case ccErrContextUnlocked:
+ case ccErrCCacheLocked:
+ case ccErrCCacheUnlocked:
+ return CC_LOCKED;
+
+ case ccErrServerUnavailable:
+ case ccErrServerInsecure:
+ return CC_IO;
+
+ default:
+ cci_debug_printf ("%s(): Unhandled error", __FUNCTION__);
+ return CC_BAD_PARM;
+ }
}
+#if TARGET_OS_MAC
+#pragma mark -
+#endif
+
/* ------------------------------------------------------------------------ */
-cc_result cc_get_NC_info (apiCB *in_context,
- infoNC ***out_info)
+cc_result cc_shutdown (apiCB **io_context)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!io_context) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_context_release (*io_context);
+ }
+
+ if (!err) {
+ *io_context = NULL;
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -47,9 +135,115 @@ cc_result cc_get_NC_info (apiCB *in_context,
cc_result cc_get_change_time (apiCB *in_context,
cc_time_t *out_change_time)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_change_time) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_context_get_change_time (in_context, out_change_time);
+ }
+
+ return cci_remap_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_result cc_get_NC_info (apiCB *in_context,
+ infoNC ***out_info)
+{
+ cc_result err = CC_NOERROR;
+ infoNC **info = NULL;
+ cc_uint64 count = 0; /* Preflight the size */
+ cc_uint64 i;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!out_info ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ ccache_cit *iterator = NULL;
+
+ err = cc_seq_fetch_NCs_begin (in_context, &iterator);
+
+ while (!err) {
+ ccache_p *ccache = NULL;
+
+ err = cc_seq_fetch_NCs_next (in_context, &ccache, iterator);
+
+ if (!err) { count++; }
+
+ if (ccache) { cc_close (in_context, &ccache); }
+ }
+ if (err == CC_END) { err = CC_NOERROR; }
+
+ if (!err) {
+ err = cc_seq_fetch_NCs_end (in_context, &iterator);
+ }
+ }
+
+ if (!err) {
+ info = malloc (sizeof (*info) * (count + 1));
+ if (info) {
+ for (i = 0; i < count + 1; i++) { info[i] = NULL; }
+ } else {
+ err = cci_check_error (CC_NOMEM);
+ }
+ }
+
+ if (!err) {
+ ccache_cit *iterator = NULL;
+
+ err = cc_seq_fetch_NCs_begin (in_context, &iterator);
+
+ for (i = 0; !err && i < count; i++) {
+ ccache_p *ccache = NULL;
+ infoNC *item = NULL;
+
+ err = cc_seq_fetch_NCs_next (in_context, &ccache, iterator);
+
+ if (!err) {
+ info[i] = malloc (sizeof (*item));
+ if (info[i]) {
+ *info[i] = infoNC_initializer;
+ } else {
+ err = cci_check_error (CC_NOMEM);
+ }
+ }
+
+ if (!err) {
+ err = cc_get_name (in_context, ccache, &info[i]->name);
+ }
+
+ if (!err) {
+ err = cc_get_principal (in_context, ccache, &info[i]->principal);
+ }
+
+ if (!err) {
+ err = cc_get_cred_version (in_context, ccache, &info[i]->vers);
+ }
+
+ if (ccache) { cc_close (in_context, &ccache); }
+ }
+
+ if (!err) {
+ err = cc_seq_fetch_NCs_end (in_context, &iterator);
+ }
+ }
+
+ if (!err) {
+ *out_info = info;
+ info = NULL;
+ }
+
+ if (info) { cc_free_NC_info (in_context, &info); }
+
+ return cci_check_error (err);
}
+#if TARGET_OS_MAC
+#pragma mark -
+#endif
+
/* ------------------------------------------------------------------------ */
cc_int32 cc_open (apiCB *in_context,
@@ -58,7 +252,48 @@ cc_int32 cc_open (apiCB *in_context,
cc_uint32 in_flags,
ccache_p **out_ccache)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_ccache_t ccache = NULL;
+ cc_uint32 compat_version;
+ cc_uint32 real_version;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!in_name ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_ccache) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_remap_version (in_version, &compat_version);
+ }
+
+ if (!err) {
+ err = ccapi_context_open_ccache (in_context, in_name, &ccache);
+ }
+
+ /* We must not allow a CCAPI v2 caller to open a v5-only ccache
+ as a v4 ccache and vice versa. Allowing that would break
+ (valid) assumptions made by CCAPI v2 callers. */
+
+ if (!err) {
+ err = ccapi_ccache_get_credentials_version (ccache, &real_version);
+ }
+
+ if (!err) {
+ /* check the version and set up the ccache to use it */
+ if (compat_version & real_version) {
+ err = cci_ccache_set_compat_version (ccache, compat_version);
+ } else {
+ err = ccErrInvalidCCache;
+ }
+ }
+
+ if (!err) {
+ *out_ccache = ccache;
+ ccache = NULL;
+ }
+
+ if (ccache) { ccapi_ccache_release (ccache); }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -70,7 +305,35 @@ cc_result cc_create (apiCB *in_context,
cc_uint32 in_flags,
ccache_p **out_ccache)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_ccache_t ccache = NULL;
+ cc_uint32 compat_version;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!in_name ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_ccache) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_remap_version (in_version, &compat_version);
+ }
+
+ if (!err) {
+ err = ccapi_context_create_ccache (in_context, in_name, compat_version,
+ in_principal, &ccache);
+ }
+
+ if (!err) {
+ err = cci_ccache_set_compat_version (ccache, compat_version);
+ }
+
+ if (!err) {
+ *out_ccache = ccache;
+ ccache = NULL;
+ }
+
+ if (ccache) { ccapi_ccache_release (ccache); }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -78,7 +341,20 @@ cc_result cc_create (apiCB *in_context,
cc_result cc_close (apiCB *in_context,
ccache_p **io_ccache)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_ccache_release (*io_ccache);
+ }
+
+ if (!err) {
+ *io_ccache = NULL;
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -86,36 +362,20 @@ cc_result cc_close (apiCB *in_context,
cc_result cc_destroy (apiCB *in_context,
ccache_p **io_ccache)
{
- return CC_NOT_SUPP;
-}
-
-/* ------------------------------------------------------------------------ */
-
-cc_result cc_seq_fetch_NCs_begin (apiCB *in_context,
- ccache_cit **out_iterator)
-{
- return CC_NOT_SUPP;
-}
-
-/* ------------------------------------------------------------------------ */
-
-// CCache iterators need to return some ccaches twice (when v3 ccache has
-// two kinds of credentials). To do that, we use a single v3 iterator, but
-// sometimes don't advance it.
-
-cc_result cc_seq_fetch_NCs_next (apiCB *in_context,
- ccache_p **out_ccache,
- ccache_cit *in_iterator)
-{
- return CC_NOT_SUPP;
-}
-
-/* ------------------------------------------------------------------------ */
-
-cc_result cc_seq_fetch_NCs_end (apiCB *in_context,
- ccache_cit **io_iterator)
-{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_ccache_destroy (*io_ccache);
+ }
+
+ if (!err) {
+ *io_ccache = NULL;
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -124,7 +384,29 @@ cc_result cc_get_name (apiCB *in_context,
ccache_p *in_ccache,
char **out_name)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_string_t name = NULL;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_name ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_ccache_get_name (in_ccache, &name);
+ }
+
+ if (!err) {
+ char *string = strdup (name->data);
+ if (string) {
+ *out_name = string;
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+ }
+
+ if (name) { ccapi_string_release (name); }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -133,7 +415,30 @@ cc_result cc_get_cred_version (apiCB *in_context,
ccache_p *in_ccache,
cc_int32 *out_version)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_uint32 compat_version;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_version) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_ccache_get_compat_version (in_ccache, &compat_version);
+ }
+
+ if (!err) {
+ if (compat_version == cc_credentials_v4) {
+ *out_version = CC_CRED_V4;
+
+ } else if (compat_version == cc_credentials_v5) {
+ *out_version = CC_CRED_V5;
+
+ } else {
+ err = ccErrBadCredentialsVersion;
+ }
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -143,7 +448,22 @@ cc_result cc_set_principal (apiCB *in_context,
cc_int32 in_version,
char *in_principal)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_uint32 version;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_principal) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_remap_version (in_version, &version);
+ }
+
+ if (!err) {
+ err = ccapi_ccache_set_principal (io_ccache, version, in_principal);
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -152,7 +472,34 @@ cc_result cc_get_principal (apiCB *in_context,
ccache_p *in_ccache,
char **out_principal)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_uint32 compat_version;
+ cc_string_t principal = NULL;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_principal) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_ccache_get_compat_version (in_ccache, &compat_version);
+ }
+
+ if (!err) {
+ err = ccapi_ccache_get_principal (in_ccache, compat_version, &principal);
+ }
+
+ if (!err) {
+ char *string = strdup (principal->data);
+ if (string) {
+ *out_principal = string;
+ } else {
+ err = cci_check_error (ccErrNoMem);
+ }
+ }
+
+ if (principal) { ccapi_string_release (principal); }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -161,7 +508,23 @@ cc_result cc_store (apiCB *in_context,
ccache_p *io_ccache,
cred_union in_credentials)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_credentials_union *creds_union = NULL;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!io_ccache ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_cred_union_to_credentials_union (&in_credentials,
+ &creds_union);
+ }
+
+ if (!err) {
+ err = ccapi_ccache_store_credentials (io_ccache, creds_union);
+ }
+
+ if (creds_union) { cci_credentials_union_release (creds_union); }
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -170,16 +533,207 @@ cc_result cc_remove_cred (apiCB *in_context,
ccache_p *in_ccache,
cred_union in_credentials)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_credentials_iterator_t iterator = NULL;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_ccache_new_credentials_iterator (in_ccache, &iterator);
+ }
+
+ while (!err) {
+ cc_credentials_t creds = NULL;
+ cc_uint32 equal = 0;
+
+ err = ccapi_credentials_iterator_next (iterator, &creds);
+
+ if (!err) {
+ err = cci_cred_union_compare_to_credentials_union (&in_credentials,
+ creds->data,
+ &equal);
+ }
+
+ if (!err && equal) {
+ err = ccapi_ccache_remove_credentials (in_ccache, creds);
+ }
+
+ ccapi_credentials_release (creds);
+ }
+ if (err) { err = cci_check_error (ccErrCredentialsNotFound); }
+
+ return cci_remap_error (err);
}
+#if TARGET_OS_MAC
+#pragma mark -
+#endif
+
+/* ------------------------------------------------------------------------ */
+
+cc_result cc_seq_fetch_NCs_begin (apiCB *in_context,
+ ccache_cit **out_iterator)
+{
+ cc_result err = ccNoError;
+ cc_ccache_iterator_t iterator = NULL;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_context_new_ccache_iterator (in_context, &iterator);
+ }
+
+ if (!err) {
+ *out_iterator = (ccache_cit *) iterator;
+ iterator = NULL; /* take ownership */
+ }
+
+ if (iterator) { ccapi_ccache_iterator_release (iterator); }
+
+ return cci_remap_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_result cc_seq_fetch_NCs_next (apiCB *in_context,
+ ccache_p **out_ccache,
+ ccache_cit *in_iterator)
+{
+ cc_result err = ccNoError;
+ cc_ccache_iterator_t iterator = (cc_ccache_iterator_t) in_iterator;
+ cc_ccache_t ccache = NULL;
+ const char *saved_ccache_name;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ /* CCache iterators need to return some ccaches twice (when v3 ccache has
+ * two kinds of credentials). To do that, we return such ccaches twice
+ * v4 first, then v5. */
+
+ if (!err) {
+ err = cci_ccache_iterator_get_saved_ccache_name (iterator,
+ &saved_ccache_name);
+ }
+
+ if (!err) {
+ if (saved_ccache_name) {
+ err = ccapi_context_open_ccache (in_context, saved_ccache_name,
+ &ccache);
+
+ if (!err) {
+ err = cci_ccache_set_compat_version (ccache, cc_credentials_v5);
+ }
+
+ if (!err) {
+ err = cci_ccache_iterator_set_saved_ccache_name (iterator, NULL);
+ }
+
+ } else {
+ cc_uint32 version = 0;
+
+ err = ccapi_ccache_iterator_next (iterator, &ccache);
+
+ if (!err) {
+ err = ccapi_ccache_get_credentials_version (ccache, &version);
+ }
+
+ if (!err) {
+ if (version == cc_credentials_v4_v5) {
+ cc_string_t name = NULL;
+
+ err = cci_ccache_set_compat_version (ccache, cc_credentials_v4);
+
+ if (!err) {
+ err = ccapi_ccache_get_name (ccache, &name);
+ }
+
+ if (!err) {
+ err = cci_ccache_iterator_set_saved_ccache_name (iterator,
+ name->data);
+ }
+
+ if (name) { ccapi_string_release (name); }
+
+ } else {
+ err = cci_ccache_set_compat_version (ccache, version);
+ }
+ }
+ }
+ }
+
+ if (!err) {
+ *out_ccache = ccache;
+ ccache = NULL; /* take ownership */
+ }
+
+ if (ccache) { ccapi_ccache_release (ccache); }
+
+ return cci_remap_error (err);
+}
+
+/* ------------------------------------------------------------------------ */
+
+cc_result cc_seq_fetch_NCs_end (apiCB *in_context,
+ ccache_cit **io_iterator)
+{
+ cc_result err = ccNoError;
+ cc_ccache_iterator_t iterator = (cc_ccache_iterator_t) io_iterator;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!io_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_ccache_iterator_release (iterator);
+ }
+
+ return cci_remap_error (err);
+}
+
+#if TARGET_OS_MAC
+#pragma mark -
+#endif
+
/* ------------------------------------------------------------------------ */
cc_result cc_seq_fetch_creds_begin (apiCB *in_context,
const ccache_p *in_ccache,
ccache_cit **out_iterator)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_credentials_iterator_t iterator = NULL;
+ cc_uint32 compat_version;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_ccache ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_ccache_get_compat_version ((cc_ccache_t) in_ccache,
+ &compat_version);
+ }
+
+ if (!err) {
+ err = ccapi_ccache_new_credentials_iterator ((cc_ccache_t) in_ccache,
+ &iterator);
+ }
+
+ if (!err) {
+ err = cci_credentials_iterator_set_compat_version (iterator,
+ compat_version);
+ }
+
+ if (!err) {
+ *out_iterator = (ccache_cit *) iterator;
+ iterator = NULL; /* take ownership */
+ }
+
+ if (iterator) { ccapi_credentials_iterator_release (iterator); }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -188,7 +742,35 @@ cc_result cc_seq_fetch_creds_next (apiCB *in_context,
cred_union **out_creds,
ccache_cit *in_iterator)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_credentials_iterator_t iterator = (cc_credentials_iterator_t) in_iterator;
+ cc_uint32 compat_version;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!out_creds ) { err = cci_check_error (ccErrBadParam); }
+ if (!in_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_credentials_iterator_get_compat_version (iterator,
+ &compat_version);
+ }
+
+ while (!err) {
+ cc_credentials_t credentials = NULL;
+
+ err = ccapi_credentials_iterator_next (iterator, &credentials);
+
+ if (!err && (credentials->data->version & compat_version)) {
+ /* got the next credentials for the correct version */
+ err = cci_credentials_union_to_cred_union (credentials->data,
+ out_creds);
+ break;
+ }
+
+ if (credentials) { ccapi_credentials_release (credentials); }
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -196,15 +778,43 @@ cc_result cc_seq_fetch_creds_next (apiCB *in_context,
cc_result cc_seq_fetch_creds_end (apiCB *in_context,
ccache_cit **io_iterator)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+ cc_credentials_iterator_t *iterator = (cc_credentials_iterator_t *) io_iterator;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!io_iterator) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = ccapi_credentials_iterator_release (*iterator);
+ }
+
+ if (!err) {
+ *iterator = NULL;
+ }
+
+ return cci_remap_error (err);
}
+#if TARGET_OS_MAC
+#pragma mark -
+#endif
+
/* ------------------------------------------------------------------------ */
cc_result cc_free_principal (apiCB *in_context,
char **io_principal)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!io_principal) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ free (*io_principal);
+ *io_principal = NULL;
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -212,7 +822,17 @@ cc_result cc_free_principal (apiCB *in_context,
cc_result cc_free_name (apiCB *in_context,
char **io_name)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!io_name ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ free (*io_name);
+ *io_name = NULL;
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -220,7 +840,17 @@ cc_result cc_free_name (apiCB *in_context,
cc_result cc_free_creds (apiCB *in_context,
cred_union **io_credentials)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context ) { err = cci_check_error (ccErrBadParam); }
+ if (!io_credentials) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err) {
+ err = cci_cred_union_release (*io_credentials);
+ if (!err) { *io_credentials = NULL; }
+ }
+
+ return cci_remap_error (err);
}
/* ------------------------------------------------------------------------ */
@@ -228,5 +858,24 @@ cc_result cc_free_creds (apiCB *in_context,
cc_result cc_free_NC_info (apiCB *in_context,
infoNC ***io_info)
{
- return CC_NOT_SUPP;
+ cc_result err = ccNoError;
+
+ if (!in_context) { err = cci_check_error (ccErrBadParam); }
+ if (!io_info ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!err && *io_info) {
+ infoNC **data = *io_info;
+ int i;
+
+ for (i = 0; data[i] != NULL; i++) {
+ cc_free_principal (in_context, &data[i]->principal);
+ cc_free_name (in_context, &data[i]->name);
+ free (data[i]);
+ }
+ free (data);
+
+ *io_info = NULL;
+ }
+
+ return cci_remap_error (err);
}
diff --git a/src/ccapi/lib/mac/ccapi_os_ipc.c b/src/ccapi/lib/mac/ccapi_os_ipc.c
index 95a2f0b..f905621 100644
--- a/src/ccapi/lib/mac/ccapi_os_ipc.c
+++ b/src/ccapi/lib/mac/ccapi_os_ipc.c
@@ -140,13 +140,8 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server,
if (!out_reply_stream ) { err = cci_check_error (ccErrBadParam); }
if (!err) {
- err = kipc_client_lookup_server (cci_server_bundle_id, cci_server_path,
- in_launch_server, &server_port);
- }
-
- if (!err) {
/* depending on how big the message is, use the fast inline buffer or
- * the slow dynamically allocated buffer */
+ * the slow dynamically allocated buffer */
mach_msg_type_number_t request_length = cci_stream_size (in_request_stream);
if (request_length > kCCAPIMaxILMsgSize) {
@@ -164,7 +159,7 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server,
inl_request = cci_stream_data (in_request_stream);
}
}
-
+
if (!err) {
request_port = pthread_getspecific (g_request_port_key);
@@ -183,6 +178,11 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server,
err = mach_port_allocate (mach_task_self (), MACH_PORT_RIGHT_RECEIVE, &reply_port);
}
+ if (!err) {
+ err = kipc_client_lookup_server (cci_server_bundle_id, cci_server_path,
+ in_launch_server, TRUE, &server_port);
+ }
+
while (!err && !done) {
if (!err && !MACH_PORT_VALID (*request_port)) {
err = cci_mipc_create_client_connection (server_port, request_port);
@@ -196,15 +196,20 @@ cc_int32 cci_os_ipc (cc_int32 in_launch_server,
}
if (err == MACH_SEND_INVALID_DEST) {
+ if (try_count < 2) {
+ try_count++;
+ err = ccNoError;
+ }
+
if (request_port && MACH_PORT_VALID (*request_port)) {
mach_port_mod_refs (mach_task_self(), *request_port, MACH_PORT_RIGHT_SEND, -1 );
*request_port = MACH_PORT_NULL;
}
- if (try_count < 2) {
- try_count++;
- err = ccNoError;
- }
+ /* Look up server name again without using the cached copy */
+ err = kipc_client_lookup_server (cci_server_bundle_id, cci_server_path,
+ in_launch_server, FALSE, &server_port);
+
} else {
/* Talked to server, though we may have gotten an error */
done = 1;
diff --git a/src/ccapi/lib/win/OldCC/ccapi.h b/src/ccapi/lib/win/OldCC/ccapi.h
index 65a72ed..c40bd11 100644
--- a/src/ccapi/lib/win/OldCC/ccapi.h
+++ b/src/ccapi/lib/win/OldCC/ccapi.h
@@ -1,284 +1,284 @@
-
-
-/* this ALWAYS GENERATED file contains the definitions for the interfaces */
-
-
- /* File created by MIDL compiler version 6.00.0366 */
-/* at Fri Nov 30 10:06:16 2007
- */
-/* Compiler settings for ccapi.idl:
- Oic, W1, Zp8, env=Win32 (32b run)
- protocol : dce , ms_ext, c_ext, oldnames
- error checks: allocation ref bounds_check enum stub_data
- VC __declspec() decoration level:
- __declspec(uuid()), __declspec(selectany), __declspec(novtable)
- DECLSPEC_UUID(), MIDL_INTERFACE()
-*/
-//@@MIDL_FILE_HEADING( )
-
-#pragma warning( disable: 4049 ) /* more than 64k source lines */
-
-
-/* verify that the <rpcndr.h> version is high enough to compile this file*/
-#ifndef __REQUIRED_RPCNDR_H_VERSION__
-#define __REQUIRED_RPCNDR_H_VERSION__ 440
-#endif
-
-#include "rpc.h"
-#include "rpcndr.h"
-
-#ifndef __ccapi_h__
-#define __ccapi_h__
-
-#if defined(_MSC_VER) && (_MSC_VER >= 1020)
-#pragma once
-#endif
-
-/* Forward Declarations */
-
-#ifdef __cplusplus
-extern "C"{
-#endif
-
-void * __RPC_USER MIDL_user_allocate(size_t);
-void __RPC_USER MIDL_user_free( void * );
-
-#ifndef __ccapi_INTERFACE_DEFINED__
-#define __ccapi_INTERFACE_DEFINED__
-
-/* interface ccapi */
-/* [implicit_handle][unique][version][uuid] */
-
-typedef /* [context_handle] */ struct opaque_handle_CTX *HCTX;
-
-typedef /* [context_handle] */ struct opaque_handle_CACHE *HCACHE;
-
-typedef /* [context_handle] */ struct opaque_handle_CACHE_ITER *HCACHE_ITER;
-
-typedef /* [context_handle] */ struct opaque_handle_CRED_ITER *HCRED_ITER;
-
-typedef unsigned char CC_CHAR;
-
-typedef unsigned char CC_UCHAR;
-
-typedef int CC_INT32;
-
-typedef unsigned int CC_UINT32;
-
-typedef CC_INT32 CC_TIME_T;
-
-
-enum __MIDL_ccapi_0001
- { STK_AFS = 0,
- STK_DES = 1
- } ;
-
-enum __MIDL_ccapi_0002
- { CC_API_VER_1 = 1,
- CC_API_VER_2 = 2
- } ;
-
-enum __MIDL_ccapi_0003
- { KRB_NAME_SZ = 40,
- KRB_INSTANCE_SZ = 40,
- KRB_REALM_SZ = 40,
- MAX_V4_CRED_LEN = 1250
- } ;
-typedef struct _NC_INFO
- {
- /* [string] */ CC_CHAR *name;
- /* [string] */ CC_CHAR *principal;
- CC_INT32 vers;
- } NC_INFO;
-
-typedef struct _NC_INFO_LIST
- {
- CC_UINT32 length;
- /* [size_is] */ NC_INFO *info;
- } NC_INFO_LIST;
-
-typedef struct _V4_CRED
- {
- CC_UCHAR kversion;
- CC_CHAR principal[ 41 ];
- CC_CHAR principal_instance[ 41 ];
- CC_CHAR service[ 41 ];
- CC_CHAR service_instance[ 41 ];
- CC_CHAR realm[ 41 ];
- CC_UCHAR session_key[ 8 ];
- CC_INT32 kvno;
- CC_INT32 str_to_key;
- CC_INT32 issue_date;
- CC_INT32 lifetime;
- CC_UINT32 address;
- CC_INT32 ticket_sz;
- CC_UCHAR ticket[ 1250 ];
- } V4_CRED;
-
-typedef struct _CC_DATA
- {
- CC_UINT32 type;
- CC_UINT32 length;
- /* [size_is] */ CC_UCHAR *data;
- } CC_DATA;
-
-typedef struct _CC_DATA_LIST
- {
- CC_UINT32 count;
- /* [size_is] */ CC_DATA *data;
- } CC_DATA_LIST;
-
-typedef struct _V5_CRED
- {
- /* [string] */ CC_CHAR *client;
- /* [string] */ CC_CHAR *server;
- CC_DATA keyblock;
- CC_TIME_T authtime;
- CC_TIME_T starttime;
- CC_TIME_T endtime;
- CC_TIME_T renew_till;
- CC_UINT32 is_skey;
- CC_UINT32 ticket_flags;
- CC_DATA_LIST addresses;
- CC_DATA ticket;
- CC_DATA second_ticket;
- CC_DATA_LIST authdata;
- } V5_CRED;
-
-typedef /* [switch_type] */ union _CRED_PTR_UNION
- {
- /* [case()] */ V4_CRED *pV4Cred;
- /* [case()] */ V5_CRED *pV5Cred;
- } CRED_PTR_UNION;
-
-typedef struct _CRED_UNION
- {
- CC_INT32 cred_type;
- /* [switch_is] */ CRED_PTR_UNION cred;
- } CRED_UNION;
-
-CC_INT32 rcc_initialize(
- /* [out] */ HCTX *pctx);
-
-CC_INT32 rcc_shutdown(
- /* [out][in] */ HCTX *pctx);
-
-CC_INT32 rcc_get_change_time(
- /* [in] */ HCTX ctx,
- /* [out] */ CC_TIME_T *time);
-
-CC_INT32 rcc_create(
- /* [in] */ HCTX ctx,
- /* [string][in] */ const CC_CHAR *name,
- /* [string][in] */ const CC_CHAR *principal,
- /* [in] */ CC_INT32 vers,
- /* [in] */ CC_UINT32 flags,
- /* [out] */ HCACHE *pcache);
-
-CC_INT32 rcc_open(
- /* [in] */ HCTX ctx,
- /* [string][in] */ const CC_CHAR *name,
- /* [in] */ CC_INT32 vers,
- /* [in] */ CC_UINT32 flags,
- /* [out] */ HCACHE *pcache);
-
-CC_INT32 rcc_close(
- /* [out][in] */ HCACHE *pcache);
-
-CC_INT32 rcc_destroy(
- /* [out][in] */ HCACHE *pcache);
-
-CC_INT32 rcc_seq_fetch_NCs_begin(
- /* [in] */ HCTX ctx,
- /* [out] */ HCACHE_ITER *piter);
-
-CC_INT32 rcc_seq_fetch_NCs_end(
- /* [out][in] */ HCACHE_ITER *piter);
-
-CC_INT32 rcc_seq_fetch_NCs_next(
- /* [in] */ HCACHE_ITER iter,
- /* [out] */ HCACHE *pcache);
-
-CC_INT32 rcc_seq_fetch_NCs(
- /* [in] */ HCTX ctx,
- /* [out][in] */ HCACHE_ITER *piter,
- /* [out] */ HCACHE *pcache);
-
-CC_INT32 rcc_get_NC_info(
- /* [in] */ HCTX ctx,
- /* [out] */ NC_INFO_LIST **info_list);
-
-CC_INT32 rcc_get_name(
- /* [in] */ HCACHE cache,
- /* [string][out] */ CC_CHAR **name);
-
-CC_INT32 rcc_set_principal(
- /* [in] */ HCACHE cache,
- /* [in] */ CC_INT32 vers,
- /* [string][in] */ const CC_CHAR *principal);
-
-CC_INT32 rcc_get_principal(
- /* [in] */ HCACHE cache,
- /* [string][out] */ CC_CHAR **principal);
-
-CC_INT32 rcc_get_cred_version(
- /* [in] */ HCACHE cache,
- /* [out] */ CC_INT32 *vers);
-
-CC_INT32 rcc_lock_request(
- /* [in] */ HCACHE cache,
- /* [in] */ CC_INT32 lock_type);
-
-CC_INT32 rcc_store(
- /* [in] */ HCACHE cache,
- /* [in] */ CRED_UNION cred);
-
-CC_INT32 rcc_remove_cred(
- /* [in] */ HCACHE cache,
- /* [in] */ CRED_UNION cred);
-
-CC_INT32 rcc_seq_fetch_creds(
- /* [in] */ HCACHE cache,
- /* [out][in] */ HCRED_ITER *piter,
- /* [out] */ CRED_UNION **cred);
-
-CC_INT32 rcc_seq_fetch_creds_begin(
- /* [in] */ HCACHE cache,
- /* [out] */ HCRED_ITER *piter);
-
-CC_INT32 rcc_seq_fetch_creds_end(
- /* [out][in] */ HCRED_ITER *piter);
-
-CC_INT32 rcc_seq_fetch_creds_next(
- /* [in] */ HCRED_ITER iter,
- /* [out] */ CRED_UNION **cred);
-
-CC_UINT32 Connect(
- /* [string][in] */ CC_CHAR *name);
-
-void Shutdown( void);
-
-
-extern handle_t ccapi_IfHandle;
-
-
-extern RPC_IF_HANDLE ccapi_ClientIfHandle;
-extern RPC_IF_HANDLE ccapi_ServerIfHandle;
-#endif /* __ccapi_INTERFACE_DEFINED__ */
-
-/* Additional Prototypes for ALL interfaces */
-
-void __RPC_USER HCTX_rundown( HCTX );
-void __RPC_USER HCACHE_rundown( HCACHE );
-void __RPC_USER HCACHE_ITER_rundown( HCACHE_ITER );
-void __RPC_USER HCRED_ITER_rundown( HCRED_ITER );
-
-/* end of Additional Prototypes */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
-
-
+
+
+/* this ALWAYS GENERATED file contains the definitions for the interfaces */
+
+
+ /* File created by MIDL compiler version 6.00.0366 */
+/* at Fri Nov 30 10:06:16 2007
+ */
+/* Compiler settings for ccapi.idl:
+ Oic, W1, Zp8, env=Win32 (32b run)
+ protocol : dce , ms_ext, c_ext, oldnames
+ error checks: allocation ref bounds_check enum stub_data
+ VC __declspec() decoration level:
+ __declspec(uuid()), __declspec(selectany), __declspec(novtable)
+ DECLSPEC_UUID(), MIDL_INTERFACE()
+*/
+//@@MIDL_FILE_HEADING( )
+
+#pragma warning( disable: 4049 ) /* more than 64k source lines */
+
+
+/* verify that the <rpcndr.h> version is high enough to compile this file*/
+#ifndef __REQUIRED_RPCNDR_H_VERSION__
+#define __REQUIRED_RPCNDR_H_VERSION__ 440
+#endif
+
+#include "rpc.h"
+#include "rpcndr.h"
+
+#ifndef __ccapi_h__
+#define __ccapi_h__
+
+#if defined(_MSC_VER) && (_MSC_VER >= 1020)
+#pragma once
+#endif
+
+/* Forward Declarations */
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+void * __RPC_USER MIDL_user_allocate(size_t);
+void __RPC_USER MIDL_user_free( void * );
+
+#ifndef __ccapi_INTERFACE_DEFINED__
+#define __ccapi_INTERFACE_DEFINED__
+
+/* interface ccapi */
+/* [implicit_handle][unique][version][uuid] */
+
+typedef /* [context_handle] */ struct opaque_handle_CTX *HCTX;
+
+typedef /* [context_handle] */ struct opaque_handle_CACHE *HCACHE;
+
+typedef /* [context_handle] */ struct opaque_handle_CACHE_ITER *HCACHE_ITER;
+
+typedef /* [context_handle] */ struct opaque_handle_CRED_ITER *HCRED_ITER;
+
+typedef unsigned char CC_CHAR;
+
+typedef unsigned char CC_UCHAR;
+
+typedef int CC_INT32;
+
+typedef unsigned int CC_UINT32;
+
+typedef CC_INT32 CC_TIME_T;
+
+
+enum __MIDL_ccapi_0001
+ { STK_AFS = 0,
+ STK_DES = 1
+ } ;
+
+enum __MIDL_ccapi_0002
+ { CC_API_VER_1 = 1,
+ CC_API_VER_2 = 2
+ } ;
+
+enum __MIDL_ccapi_0003
+ { KRB_NAME_SZ = 40,
+ KRB_INSTANCE_SZ = 40,
+ KRB_REALM_SZ = 40,
+ MAX_V4_CRED_LEN = 1250
+ } ;
+typedef struct _NC_INFO
+ {
+ /* [string] */ CC_CHAR *name;
+ /* [string] */ CC_CHAR *principal;
+ CC_INT32 vers;
+ } NC_INFO;
+
+typedef struct _NC_INFO_LIST
+ {
+ CC_UINT32 length;
+ /* [size_is] */ NC_INFO *info;
+ } NC_INFO_LIST;
+
+typedef struct _V4_CRED
+ {
+ CC_UCHAR kversion;
+ CC_CHAR principal[ 41 ];
+ CC_CHAR principal_instance[ 41 ];
+ CC_CHAR service[ 41 ];
+ CC_CHAR service_instance[ 41 ];
+ CC_CHAR realm[ 41 ];
+ CC_UCHAR session_key[ 8 ];
+ CC_INT32 kvno;
+ CC_INT32 str_to_key;
+ CC_INT32 issue_date;
+ CC_INT32 lifetime;
+ CC_UINT32 address;
+ CC_INT32 ticket_sz;
+ CC_UCHAR ticket[ 1250 ];
+ } V4_CRED;
+
+typedef struct _CC_DATA
+ {
+ CC_UINT32 type;
+ CC_UINT32 length;
+ /* [size_is] */ CC_UCHAR *data;
+ } CC_DATA;
+
+typedef struct _CC_DATA_LIST
+ {
+ CC_UINT32 count;
+ /* [size_is] */ CC_DATA *data;
+ } CC_DATA_LIST;
+
+typedef struct _V5_CRED
+ {
+ /* [string] */ CC_CHAR *client;
+ /* [string] */ CC_CHAR *server;
+ CC_DATA keyblock;
+ CC_TIME_T authtime;
+ CC_TIME_T starttime;
+ CC_TIME_T endtime;
+ CC_TIME_T renew_till;
+ CC_UINT32 is_skey;
+ CC_UINT32 ticket_flags;
+ CC_DATA_LIST addresses;
+ CC_DATA ticket;
+ CC_DATA second_ticket;
+ CC_DATA_LIST authdata;
+ } V5_CRED;
+
+typedef /* [switch_type] */ union _CRED_PTR_UNION
+ {
+ /* [case()] */ V4_CRED *pV4Cred;
+ /* [case()] */ V5_CRED *pV5Cred;
+ } CRED_PTR_UNION;
+
+typedef struct _CRED_UNION
+ {
+ CC_INT32 cred_type;
+ /* [switch_is] */ CRED_PTR_UNION cred;
+ } CRED_UNION;
+
+CC_INT32 rcc_initialize(
+ /* [out] */ HCTX *pctx);
+
+CC_INT32 rcc_shutdown(
+ /* [out][in] */ HCTX *pctx);
+
+CC_INT32 rcc_get_change_time(
+ /* [in] */ HCTX ctx,
+ /* [out] */ CC_TIME_T *time);
+
+CC_INT32 rcc_create(
+ /* [in] */ HCTX ctx,
+ /* [string][in] */ const CC_CHAR *name,
+ /* [string][in] */ const CC_CHAR *principal,
+ /* [in] */ CC_INT32 vers,
+ /* [in] */ CC_UINT32 flags,
+ /* [out] */ HCACHE *pcache);
+
+CC_INT32 rcc_open(
+ /* [in] */ HCTX ctx,
+ /* [string][in] */ const CC_CHAR *name,
+ /* [in] */ CC_INT32 vers,
+ /* [in] */ CC_UINT32 flags,
+ /* [out] */ HCACHE *pcache);
+
+CC_INT32 rcc_close(
+ /* [out][in] */ HCACHE *pcache);
+
+CC_INT32 rcc_destroy(
+ /* [out][in] */ HCACHE *pcache);
+
+CC_INT32 rcc_seq_fetch_NCs_begin(
+ /* [in] */ HCTX ctx,
+ /* [out] */ HCACHE_ITER *piter);
+
+CC_INT32 rcc_seq_fetch_NCs_end(
+ /* [out][in] */ HCACHE_ITER *piter);
+
+CC_INT32 rcc_seq_fetch_NCs_next(
+ /* [in] */ HCACHE_ITER iter,
+ /* [out] */ HCACHE *pcache);
+
+CC_INT32 rcc_seq_fetch_NCs(
+ /* [in] */ HCTX ctx,
+ /* [out][in] */ HCACHE_ITER *piter,
+ /* [out] */ HCACHE *pcache);
+
+CC_INT32 rcc_get_NC_info(
+ /* [in] */ HCTX ctx,
+ /* [out] */ NC_INFO_LIST **info_list);
+
+CC_INT32 rcc_get_name(
+ /* [in] */ HCACHE cache,
+ /* [string][out] */ CC_CHAR **name);
+
+CC_INT32 rcc_set_principal(
+ /* [in] */ HCACHE cache,
+ /* [in] */ CC_INT32 vers,
+ /* [string][in] */ const CC_CHAR *principal);
+
+CC_INT32 rcc_get_principal(
+ /* [in] */ HCACHE cache,
+ /* [string][out] */ CC_CHAR **principal);
+
+CC_INT32 rcc_get_cred_version(
+ /* [in] */ HCACHE cache,
+ /* [out] */ CC_INT32 *vers);
+
+CC_INT32 rcc_lock_request(
+ /* [in] */ HCACHE cache,
+ /* [in] */ CC_INT32 lock_type);
+
+CC_INT32 rcc_store(
+ /* [in] */ HCACHE cache,
+ /* [in] */ CRED_UNION cred);
+
+CC_INT32 rcc_remove_cred(
+ /* [in] */ HCACHE cache,
+ /* [in] */ CRED_UNION cred);
+
+CC_INT32 rcc_seq_fetch_creds(
+ /* [in] */ HCACHE cache,
+ /* [out][in] */ HCRED_ITER *piter,
+ /* [out] */ CRED_UNION **cred);
+
+CC_INT32 rcc_seq_fetch_creds_begin(
+ /* [in] */ HCACHE cache,
+ /* [out] */ HCRED_ITER *piter);
+
+CC_INT32 rcc_seq_fetch_creds_end(
+ /* [out][in] */ HCRED_ITER *piter);
+
+CC_INT32 rcc_seq_fetch_creds_next(
+ /* [in] */ HCRED_ITER iter,
+ /* [out] */ CRED_UNION **cred);
+
+CC_UINT32 Connect(
+ /* [string][in] */ CC_CHAR *name);
+
+void Shutdown( void);
+
+
+extern handle_t ccapi_IfHandle;
+
+
+extern RPC_IF_HANDLE ccapi_ClientIfHandle;
+extern RPC_IF_HANDLE ccapi_ServerIfHandle;
+#endif /* __ccapi_INTERFACE_DEFINED__ */
+
+/* Additional Prototypes for ALL interfaces */
+
+void __RPC_USER HCTX_rundown( HCTX );
+void __RPC_USER HCACHE_rundown( HCACHE );
+void __RPC_USER HCACHE_ITER_rundown( HCACHE_ITER );
+void __RPC_USER HCRED_ITER_rundown( HCRED_ITER );
+
+/* end of Additional Prototypes */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
diff --git a/src/ccapi/lib/win/OldCC/client.cxx b/src/ccapi/lib/win/OldCC/client.cxx
index 1f90510..4928d4c 100644
--- a/src/ccapi/lib/win/OldCC/client.cxx
+++ b/src/ccapi/lib/win/OldCC/client.cxx
@@ -1,389 +1,389 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "stdio.h" // KPKDBG
-
-#include "ccs_request.h"
-
-#include "ccapi.h"
-#include "util.h"
-
-extern "C" {
-#include "cci_debugging.h"
-#include "tls.h" // KPKDBG
- }
-
-#include "client.h"
-#include "init.hxx"
-#include "name.h"
-#include "secure.hxx"
-
-#define SECONDS_TO_WAIT 10
-
-#define STARTUP "CLIENT STARTUP: "
-#define DISCONNECT "CLIENT DISCONNECT: "
-
-bool Client::s_init = false;
-CcOsLock Client::sLock;
-
-static DWORD bind_client(char* ep OPTIONAL, Init::InitInfo& info, LPSTR* endpoint) {
- DWORD status = 0;
- unsigned char * pszStringBinding = NULL;
-
- if (!ep) {
- status = alloc_name(endpoint, "ep", isNT());
- }
- else {
- *endpoint = ep;
- }
-
- if (!status) {
- /* Use a convenience function to concatenate the elements of */
- /* the string binding into the proper sequence. */
- status = RpcStringBindingCompose(0, // uuid
- (unsigned char*)"ncalrpc", // protseq
- 0, // address
- (unsigned char*)(*endpoint), // endpoint
- 0, // options
- &pszStringBinding);
- cci_check_error(status);
- }
-
- if (!status) {
- /* Set the binding handle that will be used to bind to the server. */
- status = RpcBindingFromStringBinding(pszStringBinding, &ccs_request_IfHandle);
- cci_check_error(status);
- }
-
- if (!status) {
- // Win9x might call RpcBindingSetAuthInfo (not Ex), but it does not
- // quite work on Win9x...
- if (isNT()) {
- RPC_SECURITY_QOS qos;
- qos.Version = RPC_C_SECURITY_QOS_VERSION;
- qos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
- qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
- qos.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
-
- status = info.fRpcBindingSetAuthInfoEx(ccs_request_IfHandle,
- 0, // principal
- RPC_C_AUTHN_LEVEL_CONNECT,
- RPC_C_AUTHN_WINNT,
- 0, // current address space
- RPC_C_AUTHZ_NAME,
- &qos);
- cci_check_error(status);
- }
- }
-
- if (pszStringBinding) {
- DWORD status = RpcStringFree(&pszStringBinding);
- cci_check_error(status);
- }
- return cci_check_error(status);
- }
-
-DWORD find_server(Init::InitInfo& info, LPSTR endpoint) {
- DWORD status = 0;
- LPSTR event_name = 0;
- HANDLE hEvent = 0;
- SECURITY_ATTRIBUTES sa = { 0 };
- PSECURITY_ATTRIBUTES psa = 0;
- STARTUPINFO si = { 0 };
- PROCESS_INFORMATION pi = { 0 };
- char* szExe = 0;
- char* szDir = 0;
- BOOL bRes = FALSE;
- char* cmdline = NULL;
-#if 0
- HANDLE hToken = 0;
-#endif
-
- psa = isNT() ? &sa : 0;
-
-// cci_debug_printf("%s Looking for server; ccs_request_IfHandle:0x%X", __FUNCTION__, ccs_request_IfHandle);
- status = cci_check_error(RpcMgmtIsServerListening(ccs_request_IfHandle));
- if (status == RPC_S_NOT_LISTENING) {
-// cci_debug_printf(" Server *NOT* found!");
- si.cb = sizeof(si);
-
- status = alloc_module_dir_name(CCAPI_DLL, &szDir);
-
- if (!status) {
- status = alloc_module_dir_name_with_file(CCAPI_DLL, CCAPI_EXE, &szExe);
- }
-
- if (!status) {
- status = alloc_name(&event_name, "startup", isNT());
- cci_check_error(status);
- }
-
- if (!status) {
- if (isNT()) {
- sa.nLength = sizeof(sa);
- status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
- cci_check_error(status);
- }
- }
-
- if (!status) {
- hEvent = CreateEvent(psa, FALSE, FALSE, event_name);
- cci_debug_printf(" CreateEvent(... %s) returned hEvent 0x%X", event_name, hEvent);
- if (!hEvent) status = GetLastError();
- }
-
- if (!status) {
-
-#if 0
- if (SecureClient::IsImp()) {
- cci_debug_printf(STARTUP "Token is impersonation token"));
- SecureClient::DuplicateImpAsPrimary(hToken);
- }
- else {
- cci_debug_printf(STARTUP "Token is NOT impersonation token"));
- }
-#endif
-
-#if 0
- if (hToken)
- bRes = CreateProcessAsUser(hToken,
- szExe, // app name
- NULL, // cmd line
- psa, // SA
- psa, // SA
- FALSE,
- CREATE_NEW_PROCESS_GROUP |
- //CREATE_NEW_CONSOLE |
- NORMAL_PRIORITY_CLASS |
- // CREATE_NO_WINDOW |
- DETACHED_PROCESS |
- 0
- ,
- NULL, // environment
- szDir, // current dir
- &si,
- &pi);
- else
-#endif
- alloc_cmdline_2_args(szExe, endpoint, "-D", &cmdline);
- bRes = CreateProcess( szExe, // app name
- NULL, //cmdline, // cmd line is <server endpoint -[DC]>
- psa, // SA
- psa, // SA
- FALSE,
- CREATE_NEW_PROCESS_GROUP |
- CREATE_NEW_CONSOLE |
- NORMAL_PRIORITY_CLASS |
- // CREATE_NO_WINDOW |
- // DETACHED_PROCESS | /* KPK TODO: was set - restore */
- 0
- ,
- NULL, // environment
- szDir, // current dir
- &si,
- &pi);
- if (!bRes) {
- status = GetLastError();
- cci_debug_printf(" CreateProcess returned %d; LastError: %d", bRes, status);
- }
- cci_debug_printf(" Waiting...");
- }
- cci_check_error(status);
-
- if (!status) {
- status = WaitForSingleObject(hEvent, (SECONDS_TO_WAIT)*1000);
- status = RpcMgmtIsServerListening(ccs_request_IfHandle);
- }
- }
- else if (status) {
- cci_debug_printf(" unexpected error while looking for server: 0D%d / 0U%u / 0X%X", status, status, status);
- }
-
-#if 0
- if (hToken)
- CloseHandle(hToken);
-#endif
- if (szDir) free_alloc_p(&szDir);
- if (szExe) free_alloc_p(&szExe);
- if (hEvent) CloseHandle(hEvent);
- if (pi.hThread) CloseHandle(pi.hThread);
- if (pi.hProcess) CloseHandle(pi.hProcess);
- if (sa.lpSecurityDescriptor) free_alloc_p(&sa.lpSecurityDescriptor);
- return cci_check_error(status);
-
-}
-
-static
-DWORD
-authenticate_server(Init::InitInfo& info) {
- DWORD challenge = 17; // XXX - maybe use random number
- DWORD desired_response= challenge + 1;
- HANDLE hMap = 0;
- LPSTR mem_name = 0;
- PDWORD pvalue = 0;
- CC_UINT32 response = 0;
- SECURITY_ATTRIBUTES sa = { 0 };
- DWORD status = 0;
-
- cci_debug_printf("%s entry", __FUNCTION__);
-
- status = alloc_name(&mem_name, "auth", isNT());
- cci_check_error(status);
-
- if (!status) {
- if (isNT()) {
- sa.nLength = sizeof(sa);
- status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
- }
- }
- cci_check_error(status);
-
- if (!status) {
- hMap = CreateFileMapping(INVALID_HANDLE_VALUE, isNT() ? &sa : 0,
- PAGE_READWRITE, 0, sizeof(DWORD), mem_name);
- if (!hMap)
- status = GetLastError();
- }
- cci_check_error(status);
-
- if (!status) {
- pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
- if (!pvalue) status = GetLastError();
- }
- cci_check_error(status);
-
- if (!status) {
- *pvalue = challenge;
-
- RpcTryExcept {
- response = ccs_authenticate( (CC_CHAR*)mem_name );
- }
- RpcExcept(1) {
- status = RpcExceptionCode();
- cci_check_error(status);
- }
- RpcEndExcept;
- }
- cci_check_error(status);
-
- if (!status) {
- // Check response
- if ((response != desired_response) && (*pvalue != desired_response)) {
- cci_debug_printf(" Could not authenticate server.");
- status = ERROR_ACCESS_DENIED; // XXX - CO_E_NOMATCHINGSIDFOUND?
- }
- else {
- cci_debug_printf(" Server authenticated!");
- }
- cci_check_error(status);
- }
-
- free_alloc_p(&mem_name);
- free_alloc_p(&sa.lpSecurityDescriptor);
- if (pvalue) {
- BOOL ok = UnmapViewOfFile(pvalue);
-// DEBUG_ASSERT(ok);
- }
- if (hMap) CloseHandle(hMap);
- return status;
-}
-
-DWORD
-Client::Disconnect() {
- DWORD status = 0;
- if (ccs_request_IfHandle) {
- /* The calls to the remote procedures are complete. */
- /* Free the binding handle */
- status = RpcBindingFree(&ccs_request_IfHandle);
- }
- s_init = false;
- return status;
- }
-
-DWORD
-Client::Connect(char* ep OPTIONAL) {
- LPSTR endpoint = 0;
- DWORD status = 0;
-
- if (!ccs_request_IfHandle) {
- Init::InitInfo info;
-
- status = Init::Info(info);
- cci_check_error(status);
-
- if (!status) {
- status = bind_client(ep, info, &endpoint);
- cci_check_error(status);
- }
-
- if (!status) {
- status = find_server(info, endpoint);
- cci_check_error(status);
- }
-
- if (!status) {
- status = authenticate_server(info);
- cci_check_error(status);
- }
- }
-
-
- if (endpoint && (endpoint != ep)) free_alloc_p(&endpoint);
-
- if (status) Client::Disconnect();
- return status;
- }
-
-DWORD Client::Initialize(char* ep OPTIONAL) {
- CcAutoLock AL(Client::sLock);
- SecureClient s;
- ccs_request_IfHandle = NULL;
- if (s_init) return 0;
- DWORD status = Client::Connect(ep);
- if (!status) s_init = true;
- return status;
- }
-
-DWORD Client::Cleanup() {
- CcAutoLock AL(Client::sLock);
- SecureClient s;
- return Client::Disconnect();
- }
-
-DWORD Client::Reconnect(char* ep OPTIONAL) {
- CcAutoLock AL(Client::sLock);
- SecureClient s;
- DWORD status = 0;
-
- if (Initialized()) {
- DWORD status = Client::Cleanup();
- }
- if ( (!status) ) {
- status = Client::Initialize(ep);
- }
-
- return status;
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "stdio.h" // KPKDBG
+
+#include "ccs_request.h"
+
+#include "ccapi.h"
+#include "util.h"
+
+extern "C" {
+#include "cci_debugging.h"
+#include "tls.h" // KPKDBG
+ }
+
+#include "client.h"
+#include "init.hxx"
+#include "name.h"
+#include "secure.hxx"
+
+#define SECONDS_TO_WAIT 10
+
+#define STARTUP "CLIENT STARTUP: "
+#define DISCONNECT "CLIENT DISCONNECT: "
+
+bool Client::s_init = false;
+CcOsLock Client::sLock;
+
+static DWORD bind_client(char* ep OPTIONAL, Init::InitInfo& info, LPSTR* endpoint) {
+ DWORD status = 0;
+ unsigned char * pszStringBinding = NULL;
+
+ if (!ep) {
+ status = alloc_name(endpoint, "ep", isNT());
+ }
+ else {
+ *endpoint = ep;
+ }
+
+ if (!status) {
+ /* Use a convenience function to concatenate the elements of */
+ /* the string binding into the proper sequence. */
+ status = RpcStringBindingCompose(0, // uuid
+ (unsigned char*)"ncalrpc", // protseq
+ 0, // address
+ (unsigned char*)(*endpoint), // endpoint
+ 0, // options
+ &pszStringBinding);
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ /* Set the binding handle that will be used to bind to the server. */
+ status = RpcBindingFromStringBinding(pszStringBinding, &ccs_request_IfHandle);
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ // Win9x might call RpcBindingSetAuthInfo (not Ex), but it does not
+ // quite work on Win9x...
+ if (isNT()) {
+ RPC_SECURITY_QOS qos;
+ qos.Version = RPC_C_SECURITY_QOS_VERSION;
+ qos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
+ qos.IdentityTracking = RPC_C_QOS_IDENTITY_STATIC;
+ qos.ImpersonationType = RPC_C_IMP_LEVEL_IDENTIFY;
+
+ status = info.fRpcBindingSetAuthInfoEx(ccs_request_IfHandle,
+ 0, // principal
+ RPC_C_AUTHN_LEVEL_CONNECT,
+ RPC_C_AUTHN_WINNT,
+ 0, // current address space
+ RPC_C_AUTHZ_NAME,
+ &qos);
+ cci_check_error(status);
+ }
+ }
+
+ if (pszStringBinding) {
+ DWORD status = RpcStringFree(&pszStringBinding);
+ cci_check_error(status);
+ }
+ return cci_check_error(status);
+ }
+
+DWORD find_server(Init::InitInfo& info, LPSTR endpoint) {
+ DWORD status = 0;
+ LPSTR event_name = 0;
+ HANDLE hEvent = 0;
+ SECURITY_ATTRIBUTES sa = { 0 };
+ PSECURITY_ATTRIBUTES psa = 0;
+ STARTUPINFO si = { 0 };
+ PROCESS_INFORMATION pi = { 0 };
+ char* szExe = 0;
+ char* szDir = 0;
+ BOOL bRes = FALSE;
+ char* cmdline = NULL;
+#if 0
+ HANDLE hToken = 0;
+#endif
+
+ psa = isNT() ? &sa : 0;
+
+// cci_debug_printf("%s Looking for server; ccs_request_IfHandle:0x%X", __FUNCTION__, ccs_request_IfHandle);
+ status = cci_check_error(RpcMgmtIsServerListening(ccs_request_IfHandle));
+ if (status == RPC_S_NOT_LISTENING) {
+// cci_debug_printf(" Server *NOT* found!");
+ si.cb = sizeof(si);
+
+ status = alloc_module_dir_name(CCAPI_DLL, &szDir);
+
+ if (!status) {
+ status = alloc_module_dir_name_with_file(CCAPI_DLL, CCAPI_EXE, &szExe);
+ }
+
+ if (!status) {
+ status = alloc_name(&event_name, "startup", isNT());
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ if (isNT()) {
+ sa.nLength = sizeof(sa);
+ status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
+ cci_check_error(status);
+ }
+ }
+
+ if (!status) {
+ hEvent = CreateEvent(psa, FALSE, FALSE, event_name);
+ cci_debug_printf(" CreateEvent(... %s) returned hEvent 0x%X", event_name, hEvent);
+ if (!hEvent) status = GetLastError();
+ }
+
+ if (!status) {
+
+#if 0
+ if (SecureClient::IsImp()) {
+ cci_debug_printf(STARTUP "Token is impersonation token"));
+ SecureClient::DuplicateImpAsPrimary(hToken);
+ }
+ else {
+ cci_debug_printf(STARTUP "Token is NOT impersonation token"));
+ }
+#endif
+
+#if 0
+ if (hToken)
+ bRes = CreateProcessAsUser(hToken,
+ szExe, // app name
+ NULL, // cmd line
+ psa, // SA
+ psa, // SA
+ FALSE,
+ CREATE_NEW_PROCESS_GROUP |
+ //CREATE_NEW_CONSOLE |
+ NORMAL_PRIORITY_CLASS |
+ // CREATE_NO_WINDOW |
+ DETACHED_PROCESS |
+ 0
+ ,
+ NULL, // environment
+ szDir, // current dir
+ &si,
+ &pi);
+ else
+#endif
+ alloc_cmdline_2_args(szExe, endpoint, "-D", &cmdline);
+ bRes = CreateProcess( szExe, // app name
+ NULL, //cmdline, // cmd line is <server endpoint -[DC]>
+ psa, // SA
+ psa, // SA
+ FALSE,
+ CREATE_NEW_PROCESS_GROUP |
+ CREATE_NEW_CONSOLE |
+ NORMAL_PRIORITY_CLASS |
+ // CREATE_NO_WINDOW |
+ // DETACHED_PROCESS | /* KPK TODO: was set - restore */
+ 0
+ ,
+ NULL, // environment
+ szDir, // current dir
+ &si,
+ &pi);
+ if (!bRes) {
+ status = GetLastError();
+ cci_debug_printf(" CreateProcess returned %d; LastError: %d", bRes, status);
+ }
+ cci_debug_printf(" Waiting...");
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ status = WaitForSingleObject(hEvent, (SECONDS_TO_WAIT)*1000);
+ status = RpcMgmtIsServerListening(ccs_request_IfHandle);
+ }
+ }
+ else if (status) {
+ cci_debug_printf(" unexpected error while looking for server: 0D%d / 0U%u / 0X%X", status, status, status);
+ }
+
+#if 0
+ if (hToken)
+ CloseHandle(hToken);
+#endif
+ if (szDir) free_alloc_p(&szDir);
+ if (szExe) free_alloc_p(&szExe);
+ if (hEvent) CloseHandle(hEvent);
+ if (pi.hThread) CloseHandle(pi.hThread);
+ if (pi.hProcess) CloseHandle(pi.hProcess);
+ if (sa.lpSecurityDescriptor) free_alloc_p(&sa.lpSecurityDescriptor);
+ return cci_check_error(status);
+
+}
+
+static
+DWORD
+authenticate_server(Init::InitInfo& info) {
+ DWORD challenge = 17; // XXX - maybe use random number
+ DWORD desired_response= challenge + 1;
+ HANDLE hMap = 0;
+ LPSTR mem_name = 0;
+ PDWORD pvalue = 0;
+ CC_UINT32 response = 0;
+ SECURITY_ATTRIBUTES sa = { 0 };
+ DWORD status = 0;
+
+ cci_debug_printf("%s entry", __FUNCTION__);
+
+ status = alloc_name(&mem_name, "auth", isNT());
+ cci_check_error(status);
+
+ if (!status) {
+ if (isNT()) {
+ sa.nLength = sizeof(sa);
+ status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);
+ }
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ hMap = CreateFileMapping(INVALID_HANDLE_VALUE, isNT() ? &sa : 0,
+ PAGE_READWRITE, 0, sizeof(DWORD), mem_name);
+ if (!hMap)
+ status = GetLastError();
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, 0);
+ if (!pvalue) status = GetLastError();
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ *pvalue = challenge;
+
+ RpcTryExcept {
+ response = ccs_authenticate( (CC_CHAR*)mem_name );
+ }
+ RpcExcept(1) {
+ status = RpcExceptionCode();
+ cci_check_error(status);
+ }
+ RpcEndExcept;
+ }
+ cci_check_error(status);
+
+ if (!status) {
+ // Check response
+ if ((response != desired_response) && (*pvalue != desired_response)) {
+ cci_debug_printf(" Could not authenticate server.");
+ status = ERROR_ACCESS_DENIED; // XXX - CO_E_NOMATCHINGSIDFOUND?
+ }
+ else {
+ cci_debug_printf(" Server authenticated!");
+ }
+ cci_check_error(status);
+ }
+
+ free_alloc_p(&mem_name);
+ free_alloc_p(&sa.lpSecurityDescriptor);
+ if (pvalue) {
+ BOOL ok = UnmapViewOfFile(pvalue);
+// DEBUG_ASSERT(ok);
+ }
+ if (hMap) CloseHandle(hMap);
+ return status;
+}
+
+DWORD
+Client::Disconnect() {
+ DWORD status = 0;
+ if (ccs_request_IfHandle) {
+ /* The calls to the remote procedures are complete. */
+ /* Free the binding handle */
+ status = RpcBindingFree(&ccs_request_IfHandle);
+ }
+ s_init = false;
+ return status;
+ }
+
+DWORD
+Client::Connect(char* ep OPTIONAL) {
+ LPSTR endpoint = 0;
+ DWORD status = 0;
+
+ if (!ccs_request_IfHandle) {
+ Init::InitInfo info;
+
+ status = Init::Info(info);
+ cci_check_error(status);
+
+ if (!status) {
+ status = bind_client(ep, info, &endpoint);
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ status = find_server(info, endpoint);
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ status = authenticate_server(info);
+ cci_check_error(status);
+ }
+ }
+
+
+ if (endpoint && (endpoint != ep)) free_alloc_p(&endpoint);
+
+ if (status) Client::Disconnect();
+ return status;
+ }
+
+DWORD Client::Initialize(char* ep OPTIONAL) {
+ CcAutoLock AL(Client::sLock);
+ SecureClient s;
+ ccs_request_IfHandle = NULL;
+ if (s_init) return 0;
+ DWORD status = Client::Connect(ep);
+ if (!status) s_init = true;
+ return status;
+ }
+
+DWORD Client::Cleanup() {
+ CcAutoLock AL(Client::sLock);
+ SecureClient s;
+ return Client::Disconnect();
+ }
+
+DWORD Client::Reconnect(char* ep OPTIONAL) {
+ CcAutoLock AL(Client::sLock);
+ SecureClient s;
+ DWORD status = 0;
+
+ if (Initialized()) {
+ DWORD status = Client::Cleanup();
+ }
+ if ( (!status) ) {
+ status = Client::Initialize(ep);
+ }
+
+ return status;
+ }
diff --git a/src/ccapi/lib/win/OldCC/client.h b/src/ccapi/lib/win/OldCC/client.h
index f263ce1..52be2ed 100644
--- a/src/ccapi/lib/win/OldCC/client.h
+++ b/src/ccapi/lib/win/OldCC/client.h
@@ -1,61 +1,61 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef __DLL_CLIENT_H__
-#define __DLL_CLIENT_H__
-
-#include "autolock.hxx"
-#include "init.hxx"
-
-class Client {
-public:
- static DWORD Initialize(char* ep OPTIONAL);
- static DWORD Cleanup();
- static DWORD Reconnect(char* ep OPTIONAL);
-
- static bool Initialized() { return s_init; }
-
- static CcOsLock sLock;
-
-private:
- static bool s_init;
-
- static DWORD Disconnect();
- static DWORD Connect(char* ep OPTIONAL);
- };
-
-#define CLIENT_INIT_EX(trap, error) \
-do \
-{ \
- INIT_INIT_EX(trap, error); \
- if (!Client::Initialized()) \
- { \
- DWORD status = Client::Initialize(0); \
- if (status) return (trap) ? (error) : status; \
- } \
-} while(0)
-
-#endif
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef __DLL_CLIENT_H__
+#define __DLL_CLIENT_H__
+
+#include "autolock.hxx"
+#include "init.hxx"
+
+class Client {
+public:
+ static DWORD Initialize(char* ep OPTIONAL);
+ static DWORD Cleanup();
+ static DWORD Reconnect(char* ep OPTIONAL);
+
+ static bool Initialized() { return s_init; }
+
+ static CcOsLock sLock;
+
+private:
+ static bool s_init;
+
+ static DWORD Disconnect();
+ static DWORD Connect(char* ep OPTIONAL);
+ };
+
+#define CLIENT_INIT_EX(trap, error) \
+do \
+{ \
+ INIT_INIT_EX(trap, error); \
+ if (!Client::Initialized()) \
+ { \
+ DWORD status = Client::Initialize(0); \
+ if (status) return (trap) ? (error) : status; \
+ } \
+} while(0)
+
+#endif
diff --git a/src/ccapi/lib/win/OldCC/rpc.cxx b/src/ccapi/lib/win/OldCC/rpc.cxx
index 332f1c5..29edc3c 100644
--- a/src/ccapi/lib/win/OldCC/rpc.cxx
+++ b/src/ccapi/lib/win/OldCC/rpc.cxx
@@ -1,79 +1,79 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-extern "C" {
-#include "CredentialsCache.h"
-#include "secure.hxx"
-#include "client.h"
-#include "autolock.hxx"
-#include "cci_debugging.h"
- }
-
-extern HANDLE hCCAPIv2Mutex;
-
-#define MAKE_RPC_CALL(rc, x) \
-do { \
- WaitForSingleObject( hCCAPIv2Mutex, INFINITE ); \
- SecureClient* s = 0; \
- SecureClient::Start(s); \
- CcAutoLock* a = 0; \
- CcAutoLock::Start(a, Client::sLock); \
- RpcTryExcept { \
- cci_debug_printf("RpcTry: #x"); \
- x; \
- } \
- RpcExcept(1) { \
- rc = handle_exception(RpcExceptionCode()); \
- } \
- RpcEndExcept; \
- CcAutoLock::Stop(a); \
- SecureClient::Stop(s); \
- ReleaseMutex( hCCAPIv2Mutex ); \
-} while (0)
-
-static
-DWORD
-handle_exception(DWORD code) {
- cci_debug_printf("Runtime reported exception %u", code);
- if (code == RPC_S_SERVER_UNAVAILABLE) {
- Client::Reconnect(0);
- }
- return 4;
- }
-
-//////////////////////////////////////////////////////////////////////////////
-
-cc_int32 cc_initialize() {
-
- CLIENT_INIT_EX(true, 4);
- cc_int32 rc = ccNoError;
-
- MAKE_RPC_CALL(rc, rc = 5);
- return rc;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+extern "C" {
+#include "CredentialsCache.h"
+#include "secure.hxx"
+#include "client.h"
+#include "autolock.hxx"
+#include "cci_debugging.h"
+ }
+
+extern HANDLE hCCAPIv2Mutex;
+
+#define MAKE_RPC_CALL(rc, x) \
+do { \
+ WaitForSingleObject( hCCAPIv2Mutex, INFINITE ); \
+ SecureClient* s = 0; \
+ SecureClient::Start(s); \
+ CcAutoLock* a = 0; \
+ CcAutoLock::Start(a, Client::sLock); \
+ RpcTryExcept { \
+ cci_debug_printf("RpcTry: #x"); \
+ x; \
+ } \
+ RpcExcept(1) { \
+ rc = handle_exception(RpcExceptionCode()); \
+ } \
+ RpcEndExcept; \
+ CcAutoLock::Stop(a); \
+ SecureClient::Stop(s); \
+ ReleaseMutex( hCCAPIv2Mutex ); \
+} while (0)
+
+static
+DWORD
+handle_exception(DWORD code) {
+ cci_debug_printf("Runtime reported exception %u", code);
+ if (code == RPC_S_SERVER_UNAVAILABLE) {
+ Client::Reconnect(0);
+ }
+ return 4;
+ }
+
+//////////////////////////////////////////////////////////////////////////////
+
+cc_int32 cc_initialize() {
+
+ CLIENT_INIT_EX(true, 4);
+ cc_int32 rc = ccNoError;
+
+ MAKE_RPC_CALL(rc, rc = 5);
+ return rc;
} \ No newline at end of file
diff --git a/src/ccapi/lib/win/ccapi.def b/src/ccapi/lib/win/ccapi.def
index 0450331..d062e55 100644
--- a/src/ccapi/lib/win/ccapi.def
+++ b/src/ccapi/lib/win/ccapi.def
@@ -1,39 +1,39 @@
-;LIBRARY COMERR32
-HEAPSIZE 8192
-
-EXPORTS
- cci_debug_printf
-
- cc_initialize
-
- cci_string_new
- cci_string_d_initializer
- ccapi_string_release
-
- cci_credentials_iterator_new
- cci_credentials_iterator_write
-
- cci_ccache_iterator_new
- cci_ccache_iterator_write
-
- ccapi_ccache_iterator_release
- ccapi_ccache_iterator_next
- ccapi_ccache_iterator_clone
-
- ccapi_credentials_iterator_release
- ccapi_credentials_iterator_next
- ccapi_credentials_iterator_clone
-
-;debugging:
- _cci_check_error
- cci_os_ipc
- cci_os_ipc_msg
- cci_os_ipc_thread_init
- cci_stream_data
- cci_stream_write
- cci_stream_new
-
- ccs_authenticate
-
-
+;LIBRARY COMERR32
+HEAPSIZE 8192
+
+EXPORTS
+ cci_debug_printf
+
+ cc_initialize
+
+ cci_string_new
+ cci_string_d_initializer
+ ccapi_string_release
+
+ cci_credentials_iterator_new
+ cci_credentials_iterator_write
+
+ cci_ccache_iterator_new
+ cci_ccache_iterator_write
+
+ ccapi_ccache_iterator_release
+ ccapi_ccache_iterator_next
+ ccapi_ccache_iterator_clone
+
+ ccapi_credentials_iterator_release
+ ccapi_credentials_iterator_next
+ ccapi_credentials_iterator_clone
+
+;debugging:
+ _cci_check_error
+ cci_os_ipc
+ cci_os_ipc_msg
+ cci_os_ipc_thread_init
+ cci_stream_data
+ cci_stream_write
+ cci_stream_new
+
+ ccs_authenticate
+
+
\ No newline at end of file
diff --git a/src/ccapi/lib/win/ccapi_os_ipc.cxx b/src/ccapi/lib/win/ccapi_os_ipc.cxx
index 7ee9176..770e75b 100644
--- a/src/ccapi/lib/win/ccapi_os_ipc.cxx
+++ b/src/ccapi/lib/win/ccapi_os_ipc.cxx
@@ -1,373 +1,373 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-extern "C" {
-#include "k5-thread.h"
-#include "ccapi_os_ipc.h"
-#include "tls.h"
-#include "dllmain.h"
-#include "ccs_reply.h"
-#include "ccs_request.h"
-#include "win-utils.h"
-#include "ccutils.h"
-#include "util.h"
- }
-
-#include "CredentialsCache.h"
-#include "secure.hxx"
-#include "opts.hxx"
-#include "client.h"
-#include "autolock.hxx"
-#include "cci_debugging.h"
-
-#define SECONDS_TO_WAIT 10
-#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
-
-extern HANDLE hCCAPIv2Mutex;
-ParseOpts::Opts opts = { 0 };
-PSECURITY_ATTRIBUTES psa = 0;
-SECURITY_ATTRIBUTES sa = { 0 };
-
-/* The layout of the rest of this module:
-
- The entrypoints defined in ccs_os_ipc.h:
- cci_os_ipc_thread_init
- cci_os_ipc
-
- Other routines needed by those four.
- cci_os_connect
- handle_exception
- */
-
-cc_int32 ccapi_connect(const struct tspdata* tsp);
-static DWORD handle_exception(DWORD code);
-
-extern "C" {
-cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
- cci_stream_t in_request_stream,
- cc_int32 in_msg,
- cci_stream_t* out_reply_stream);
- }
-
-/* ------------------------------------------------------------------------ */
-
-extern "C" cc_int32 cci_os_ipc_thread_init (void) {
- cc_int32 err = ccNoError;
- struct tspdata* ptspdata;
- HANDLE replyEvent;
- UUID __RPC_FAR uuid;
- unsigned char __RPC_FAR* uuidString = NULL;
-
- if (!GetTspData(&ptspdata)) return ccErrNoMem;
-
- opts.cMinCalls = 1;
- opts.cMaxCalls = 20;
- opts.fDontWait = TRUE;
-
- err = cci_check_error(UuidCreate(&uuid)); // Get a UUID
- if (err == RPC_S_OK) { // Convert to string
- err = UuidToString(&uuid, &uuidString);
- }
- if (!err) { // Save in thread local storage
- tspdata_setUUID(ptspdata, uuidString);
- }
- cci_debug_printf("%s UUID:<%s>", __FUNCTION__, tspdata_getUUID(ptspdata));
-
- // Initialize old CCAPI if necessary:
- if (!err) if (!Init:: Initialized()) err = Init:: Initialize( );
- if (!err) if (!Client::Initialized()) err = Client::Initialize(0);
-
- if (!err) {
- /* Whenever a reply to an RPC request is received, the RPC caller needs to
- know when the reply has been received. It does that by waiting for a
- client-specific event to be set. Define the event name to be <UUID>_reply: */
- replyEvent = createThreadEvent((char*)uuidString, REPLY_SUFFIX);
- }
-
- if (replyEvent) tspdata_setReplyEvent(ptspdata, replyEvent);
- else err = cci_check_error(GetLastError());
-
- if (uuidString) RpcStringFree(&uuidString);
-
- return cci_check_error(err);
- }
-
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 cci_os_ipc (cc_int32 in_launch_server,
- cci_stream_t in_request_stream,
- cci_stream_t* out_reply_stream) {
- return cci_os_ipc_msg( in_launch_server,
- in_request_stream,
- CCMSG_REQUEST,
- out_reply_stream);
- }
-
-extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
- cci_stream_t in_request_stream,
- cc_int32 in_msg,
- cci_stream_t* out_reply_stream) {
-
- cc_int32 err = ccNoError;
- cc_int32 done = FALSE;
- cc_int32 try_count = 0;
- cc_int32 server_died = FALSE;
- TCHAR* pszStringBinding= NULL;
- struct tspdata* ptspdata = NULL;
- char* uuid = NULL;
- int lenUUID = 0;
- unsigned int trycount = 0;
- time_t sst = 0;
- STARTUPINFO si = { 0 };
- PROCESS_INFORMATION pi = { 0 };
- HANDLE replyEvent = 0;
- BOOL bCCAPI_Connected= FALSE;
-
- if (!in_request_stream) { err = cci_check_error (ccErrBadParam); }
- if (!out_reply_stream ) { err = cci_check_error (ccErrBadParam); }
-
- if (!GetTspData(&ptspdata)) {return ccErrBadParam;}
- bCCAPI_Connected = tspdata_getConnected (ptspdata);
- replyEvent = tspdata_getReplyEvent (ptspdata);
- sst = tspdata_getSST (ptspdata);
- uuid = tspdata_getUUID(ptspdata);
-
- // The lazy connection to the server has been put off as long as possible!
- // ccapi_connect starts listening for replies as an RPC server and then
- // calls ccs_rpc_connect.
- if (!bCCAPI_Connected) {
- err = cci_check_error(ccapi_connect(ptspdata));
- bCCAPI_Connected = !err;
- tspdata_setConnected(ptspdata, bCCAPI_Connected);
- }
-
- // Clear replyEvent so we can detect when a reply to our request has been received:
- ResetEvent(replyEvent);
-
- //++ Use the old CCAPI implementation to try to talk to the server:
- // It has all the code to use the RPC in a thread-safe way, make the endpoint,
- // (re)connect and (re)start the server.
- // Note: the old implementation wrapped the thread-safety stuff in a macro.
- // Here it is expanded and thus duplicated for each RPC call. The new code has
- // a very limited number of RPC calls, unlike the older code.
- WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
- SecureClient* s = 0;
- SecureClient::Start(s);
- CcAutoLock* a = 0;
- CcAutoLock::Start(a, Client::sLock);
-
- // Initialize old CCAPI if necessary:
- if (!err) if (!Init:: Initialized()) err = cci_check_error(Init:: Initialize( ));
- if (!err) if (!Client::Initialized()) err = cci_check_error(Client::Initialize(0));
-
- // New code using new RPC procedures for sending the data and receiving a reply:
- if (!err) {
- RpcTryExcept {
- if (!GetTspData(&ptspdata)) {return ccErrBadParam;}
- uuid = tspdata_getUUID(ptspdata);
- lenUUID = 1 + strlen(uuid); /* 1+ includes terminating \0. */
- cci_debug_printf("%s calling remote ccs_rpc_request tsp*:0x%X", __FUNCTION__, ptspdata);
- cci_debug_printf(" rpcmsg:%d; UUID[%d]:<%s> SST:%ld", in_msg, lenUUID, uuid, sst);
-
- ccs_rpc_request( /* make call with user message: */
- in_msg, /* Message type */
- (unsigned char*)&ptspdata, /* Our tspdata* will be sent back to the reply proc. */
- (unsigned char*)uuid,
- cci_stream_size(in_request_stream),
- (unsigned char*)cci_stream_data(in_request_stream), /* Data buffer */
- sst, /* session start time */
- (long*)(&err) ); /* Return code */
- }
- RpcExcept(1) {
- handle_exception(RpcExceptionCode());
- }
- RpcEndExcept;
- }
-
- cci_check_error(err);
- CcAutoLock::Stop(a);
- SecureClient::Stop(s);
- ReleaseMutex(hCCAPIv2Mutex);
- //-- Use the old CCAPI implementation to try to talk to the server.
-
- // Wait for reply handler to set event:
- if (!err) {
- cci_debug_printf(" Waiting for request reply.");
- err = cci_check_error(WaitForSingleObject(replyEvent, INFINITE));//(SECONDS_TO_WAIT)*1000));
- cci_debug_printf(" Request reply received!");
- }
-
- if (!err) {
- err = cci_check_error(RpcMgmtIsServerListening(CLIENT_REQUEST_RPC_HANDLE));
- }
-
- if (!err && server_died) {
- err = cci_check_error (ccErrServerUnavailable);
- }
-#if 0
- if (err == BOOTSTRAP_UNKNOWN_SERVICE && !in_launch_server) {
- err = ccNoError; /* If the server is not running just return an empty stream. */
- }
-#endif
-
- if (!err) {
- *out_reply_stream = tspdata_getStream(ptspdata);
- }
-
- cci_debug_printf(" payload:<%s>", cci_stream_data(*out_reply_stream));
-
- return cci_check_error (err);
- }
-
-
-
-static DWORD handle_exception(DWORD code) {
- cci_debug_printf("%s code %u; ccs_request_IfHandle:0x%X", __FUNCTION__, code, ccs_request_IfHandle);
- if ( (code == RPC_S_SERVER_UNAVAILABLE) || (code == RPC_S_INVALID_BINDING) ) {
- Client::Reconnect(0);
- }
- return 4;
- }
-
-
-/* Establish a CCAPI connection with the server.
- * The connect logic here is identical to the logic in the send request code.
- * TODO: merge this connect code with that request code.
- */
-cc_int32 ccapi_connect(const struct tspdata* tsp) {
- BOOL bListen = TRUE;
- char* endpoint = NULL;
- HANDLE replyEvent = 0;
- RPC_STATUS status = FALSE;
- char* uuid = NULL;
-
- /* Start listening to our uuid before establishing the connection,
- * so that when the server tries to call ccapi_listen, we will be ready.
- */
-
- /* Build complete RPC uuid using previous CCAPI implementation: */
- replyEvent = tspdata_getReplyEvent(tsp);
- uuid = tspdata_getUUID(tsp);
- endpoint = clientEndpoint(uuid);
- cci_debug_printf("%s Registering endpoint %s", __FUNCTION__, endpoint);
-
- opts.cMinCalls = 1;
- opts.cMaxCalls = 20;
- opts.fDontWait = TRUE;
-
- if (!status) {
- status = RpcServerUseProtseqEp((RPC_CSTR)"ncalrpc",
- opts.cMaxCalls,
- (RPC_CSTR)endpoint,
- sa.lpSecurityDescriptor); // SD
- cci_check_error(status);
- }
-
- if (!status) {
- status = RpcServerRegisterAuthInfo(0, // server principal
- RPC_C_AUTHN_WINNT,
- 0,
- 0 );
- cci_check_error(status);
- }
-
- cci_debug_printf("%s is listening ...", __FUNCTION__);
-
- if (!status) {
- if (!isNT()) {
- status = RpcServerRegisterIf(ccs_reply_ServerIfHandle, // interface
- NULL, // MgrTypeUuid
- NULL); // MgrEpv; null means use default
- }
- else {
- status = RpcServerRegisterIfEx(ccs_reply_ServerIfHandle,// interface
- NULL, // MgrTypeUuid
- NULL, // MgrEpv; 0 means default
- RPC_IF_ALLOW_SECURE_ONLY,
- opts.cMaxCalls,
- NULL); // No security callback.
- }
-
- cci_check_error(status);
-
- if (!status) {
- status = RpcServerListen(opts.cMinCalls,
- opts.cMaxCalls,
- TRUE);
- cci_check_error(status);
- }
- }
-
- // Clear replyEvent so we can detect when a reply to our connect request has been received:
- ResetEvent(replyEvent);
-
- // We use the old CCAPI implementation to try to talk to the server.
- // It has all the code to make the uuid, (re)connect and (re)start the server.
- WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
- SecureClient* s = 0;
- SecureClient::Start(s);
- CcAutoLock* a = 0;
- CcAutoLock::Start(a, Client::sLock);
-
- // Initialize old CCAPI if necessary:
- if (!status) if (!Init:: Initialized()) status = Init:: Initialize( );
- if (!status) if (!Client::Initialized()) status = Client::Initialize(0);
-
- // New code using new RPC procedures for sending the data and receiving a reply:
- if (!status) {
- RpcTryExcept {
- ccs_rpc_connect( /* make call with user message: */
- CCMSG_CONNECT, /* Message type */
- (unsigned char*)&tsp, /* Our tspdata* will be sent back to the reply proc. */
- (unsigned char*)uuid,
- (long*)(&status) ); /* Return code */
- }
- RpcExcept(1) {
- cci_check_error(RpcExceptionCode());
- status = ccErrBadInternalMessage;
- }
- RpcEndExcept;
- }
-
- CcAutoLock::Stop(a);
- SecureClient::Stop(s);
- ReleaseMutex(hCCAPIv2Mutex);
-
- if (!status) {
- cci_debug_printf("%s Waiting for replyEvent.", __FUNCTION__);
- status = WaitForSingleObject(replyEvent, INFINITE);//(SECONDS_TO_WAIT)*1000);
- status = cci_check_error(RpcMgmtIsServerListening(CLIENT_REQUEST_RPC_HANDLE));
- cci_debug_printf(" Server %sFOUND!", (status) ? "NOT " : "");
- }
- if (status) {
- cci_debug_printf(" unexpected error while looking for server... (%u)", status);
- }
-
- cci_debug_printf("%s TODO: check connect reply result.", __FUNCTION__);
- cci_debug_printf("%s TODO: merge this connect code with that request code.", __FUNCTION__);
- return status;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+extern "C" {
+#include "k5-thread.h"
+#include "ccapi_os_ipc.h"
+#include "tls.h"
+#include "dllmain.h"
+#include "ccs_reply.h"
+#include "ccs_request.h"
+#include "win-utils.h"
+#include "ccutils.h"
+#include "util.h"
+ }
+
+#include "CredentialsCache.h"
+#include "secure.hxx"
+#include "opts.hxx"
+#include "client.h"
+#include "autolock.hxx"
+#include "cci_debugging.h"
+
+#define SECONDS_TO_WAIT 10
+#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
+
+extern HANDLE hCCAPIv2Mutex;
+ParseOpts::Opts opts = { 0 };
+PSECURITY_ATTRIBUTES psa = 0;
+SECURITY_ATTRIBUTES sa = { 0 };
+
+/* The layout of the rest of this module:
+
+ The entrypoints defined in ccs_os_ipc.h:
+ cci_os_ipc_thread_init
+ cci_os_ipc
+
+ Other routines needed by those four.
+ cci_os_connect
+ handle_exception
+ */
+
+cc_int32 ccapi_connect(const struct tspdata* tsp);
+static DWORD handle_exception(DWORD code);
+
+extern "C" {
+cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
+ cci_stream_t in_request_stream,
+ cc_int32 in_msg,
+ cci_stream_t* out_reply_stream);
+ }
+
+/* ------------------------------------------------------------------------ */
+
+extern "C" cc_int32 cci_os_ipc_thread_init (void) {
+ cc_int32 err = ccNoError;
+ struct tspdata* ptspdata;
+ HANDLE replyEvent;
+ UUID __RPC_FAR uuid;
+ unsigned char __RPC_FAR* uuidString = NULL;
+
+ if (!GetTspData(&ptspdata)) return ccErrNoMem;
+
+ opts.cMinCalls = 1;
+ opts.cMaxCalls = 20;
+ opts.fDontWait = TRUE;
+
+ err = cci_check_error(UuidCreate(&uuid)); // Get a UUID
+ if (err == RPC_S_OK) { // Convert to string
+ err = UuidToString(&uuid, &uuidString);
+ }
+ if (!err) { // Save in thread local storage
+ tspdata_setUUID(ptspdata, uuidString);
+ }
+ cci_debug_printf("%s UUID:<%s>", __FUNCTION__, tspdata_getUUID(ptspdata));
+
+ // Initialize old CCAPI if necessary:
+ if (!err) if (!Init:: Initialized()) err = Init:: Initialize( );
+ if (!err) if (!Client::Initialized()) err = Client::Initialize(0);
+
+ if (!err) {
+ /* Whenever a reply to an RPC request is received, the RPC caller needs to
+ know when the reply has been received. It does that by waiting for a
+ client-specific event to be set. Define the event name to be <UUID>_reply: */
+ replyEvent = createThreadEvent((char*)uuidString, REPLY_SUFFIX);
+ }
+
+ if (replyEvent) tspdata_setReplyEvent(ptspdata, replyEvent);
+ else err = cci_check_error(GetLastError());
+
+ if (uuidString) RpcStringFree(&uuidString);
+
+ return cci_check_error(err);
+ }
+
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 cci_os_ipc (cc_int32 in_launch_server,
+ cci_stream_t in_request_stream,
+ cci_stream_t* out_reply_stream) {
+ return cci_os_ipc_msg( in_launch_server,
+ in_request_stream,
+ CCMSG_REQUEST,
+ out_reply_stream);
+ }
+
+extern "C" cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
+ cci_stream_t in_request_stream,
+ cc_int32 in_msg,
+ cci_stream_t* out_reply_stream) {
+
+ cc_int32 err = ccNoError;
+ cc_int32 done = FALSE;
+ cc_int32 try_count = 0;
+ cc_int32 server_died = FALSE;
+ TCHAR* pszStringBinding= NULL;
+ struct tspdata* ptspdata = NULL;
+ char* uuid = NULL;
+ int lenUUID = 0;
+ unsigned int trycount = 0;
+ time_t sst = 0;
+ STARTUPINFO si = { 0 };
+ PROCESS_INFORMATION pi = { 0 };
+ HANDLE replyEvent = 0;
+ BOOL bCCAPI_Connected= FALSE;
+
+ if (!in_request_stream) { err = cci_check_error (ccErrBadParam); }
+ if (!out_reply_stream ) { err = cci_check_error (ccErrBadParam); }
+
+ if (!GetTspData(&ptspdata)) {return ccErrBadParam;}
+ bCCAPI_Connected = tspdata_getConnected (ptspdata);
+ replyEvent = tspdata_getReplyEvent (ptspdata);
+ sst = tspdata_getSST (ptspdata);
+ uuid = tspdata_getUUID(ptspdata);
+
+ // The lazy connection to the server has been put off as long as possible!
+ // ccapi_connect starts listening for replies as an RPC server and then
+ // calls ccs_rpc_connect.
+ if (!bCCAPI_Connected) {
+ err = cci_check_error(ccapi_connect(ptspdata));
+ bCCAPI_Connected = !err;
+ tspdata_setConnected(ptspdata, bCCAPI_Connected);
+ }
+
+ // Clear replyEvent so we can detect when a reply to our request has been received:
+ ResetEvent(replyEvent);
+
+ //++ Use the old CCAPI implementation to try to talk to the server:
+ // It has all the code to use the RPC in a thread-safe way, make the endpoint,
+ // (re)connect and (re)start the server.
+ // Note: the old implementation wrapped the thread-safety stuff in a macro.
+ // Here it is expanded and thus duplicated for each RPC call. The new code has
+ // a very limited number of RPC calls, unlike the older code.
+ WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
+ SecureClient* s = 0;
+ SecureClient::Start(s);
+ CcAutoLock* a = 0;
+ CcAutoLock::Start(a, Client::sLock);
+
+ // Initialize old CCAPI if necessary:
+ if (!err) if (!Init:: Initialized()) err = cci_check_error(Init:: Initialize( ));
+ if (!err) if (!Client::Initialized()) err = cci_check_error(Client::Initialize(0));
+
+ // New code using new RPC procedures for sending the data and receiving a reply:
+ if (!err) {
+ RpcTryExcept {
+ if (!GetTspData(&ptspdata)) {return ccErrBadParam;}
+ uuid = tspdata_getUUID(ptspdata);
+ lenUUID = 1 + strlen(uuid); /* 1+ includes terminating \0. */
+ cci_debug_printf("%s calling remote ccs_rpc_request tsp*:0x%X", __FUNCTION__, ptspdata);
+ cci_debug_printf(" rpcmsg:%d; UUID[%d]:<%s> SST:%ld", in_msg, lenUUID, uuid, sst);
+
+ ccs_rpc_request( /* make call with user message: */
+ in_msg, /* Message type */
+ (unsigned char*)&ptspdata, /* Our tspdata* will be sent back to the reply proc. */
+ (unsigned char*)uuid,
+ cci_stream_size(in_request_stream),
+ (unsigned char*)cci_stream_data(in_request_stream), /* Data buffer */
+ sst, /* session start time */
+ (long*)(&err) ); /* Return code */
+ }
+ RpcExcept(1) {
+ handle_exception(RpcExceptionCode());
+ }
+ RpcEndExcept;
+ }
+
+ cci_check_error(err);
+ CcAutoLock::Stop(a);
+ SecureClient::Stop(s);
+ ReleaseMutex(hCCAPIv2Mutex);
+ //-- Use the old CCAPI implementation to try to talk to the server.
+
+ // Wait for reply handler to set event:
+ if (!err) {
+ cci_debug_printf(" Waiting for request reply.");
+ err = cci_check_error(WaitForSingleObject(replyEvent, INFINITE));//(SECONDS_TO_WAIT)*1000));
+ cci_debug_printf(" Request reply received!");
+ }
+
+ if (!err) {
+ err = cci_check_error(RpcMgmtIsServerListening(CLIENT_REQUEST_RPC_HANDLE));
+ }
+
+ if (!err && server_died) {
+ err = cci_check_error (ccErrServerUnavailable);
+ }
+#if 0
+ if (err == BOOTSTRAP_UNKNOWN_SERVICE && !in_launch_server) {
+ err = ccNoError; /* If the server is not running just return an empty stream. */
+ }
+#endif
+
+ if (!err) {
+ *out_reply_stream = tspdata_getStream(ptspdata);
+ }
+
+ cci_debug_printf(" payload:<%s>", cci_stream_data(*out_reply_stream));
+
+ return cci_check_error (err);
+ }
+
+
+
+static DWORD handle_exception(DWORD code) {
+ cci_debug_printf("%s code %u; ccs_request_IfHandle:0x%X", __FUNCTION__, code, ccs_request_IfHandle);
+ if ( (code == RPC_S_SERVER_UNAVAILABLE) || (code == RPC_S_INVALID_BINDING) ) {
+ Client::Reconnect(0);
+ }
+ return 4;
+ }
+
+
+/* Establish a CCAPI connection with the server.
+ * The connect logic here is identical to the logic in the send request code.
+ * TODO: merge this connect code with that request code.
+ */
+cc_int32 ccapi_connect(const struct tspdata* tsp) {
+ BOOL bListen = TRUE;
+ char* endpoint = NULL;
+ HANDLE replyEvent = 0;
+ RPC_STATUS status = FALSE;
+ char* uuid = NULL;
+
+ /* Start listening to our uuid before establishing the connection,
+ * so that when the server tries to call ccapi_listen, we will be ready.
+ */
+
+ /* Build complete RPC uuid using previous CCAPI implementation: */
+ replyEvent = tspdata_getReplyEvent(tsp);
+ uuid = tspdata_getUUID(tsp);
+ endpoint = clientEndpoint(uuid);
+ cci_debug_printf("%s Registering endpoint %s", __FUNCTION__, endpoint);
+
+ opts.cMinCalls = 1;
+ opts.cMaxCalls = 20;
+ opts.fDontWait = TRUE;
+
+ if (!status) {
+ status = RpcServerUseProtseqEp((RPC_CSTR)"ncalrpc",
+ opts.cMaxCalls,
+ (RPC_CSTR)endpoint,
+ sa.lpSecurityDescriptor); // SD
+ cci_check_error(status);
+ }
+
+ if (!status) {
+ status = RpcServerRegisterAuthInfo(0, // server principal
+ RPC_C_AUTHN_WINNT,
+ 0,
+ 0 );
+ cci_check_error(status);
+ }
+
+ cci_debug_printf("%s is listening ...", __FUNCTION__);
+
+ if (!status) {
+ if (!isNT()) {
+ status = RpcServerRegisterIf(ccs_reply_ServerIfHandle, // interface
+ NULL, // MgrTypeUuid
+ NULL); // MgrEpv; null means use default
+ }
+ else {
+ status = RpcServerRegisterIfEx(ccs_reply_ServerIfHandle,// interface
+ NULL, // MgrTypeUuid
+ NULL, // MgrEpv; 0 means default
+ RPC_IF_ALLOW_SECURE_ONLY,
+ opts.cMaxCalls,
+ NULL); // No security callback.
+ }
+
+ cci_check_error(status);
+
+ if (!status) {
+ status = RpcServerListen(opts.cMinCalls,
+ opts.cMaxCalls,
+ TRUE);
+ cci_check_error(status);
+ }
+ }
+
+ // Clear replyEvent so we can detect when a reply to our connect request has been received:
+ ResetEvent(replyEvent);
+
+ // We use the old CCAPI implementation to try to talk to the server.
+ // It has all the code to make the uuid, (re)connect and (re)start the server.
+ WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
+ SecureClient* s = 0;
+ SecureClient::Start(s);
+ CcAutoLock* a = 0;
+ CcAutoLock::Start(a, Client::sLock);
+
+ // Initialize old CCAPI if necessary:
+ if (!status) if (!Init:: Initialized()) status = Init:: Initialize( );
+ if (!status) if (!Client::Initialized()) status = Client::Initialize(0);
+
+ // New code using new RPC procedures for sending the data and receiving a reply:
+ if (!status) {
+ RpcTryExcept {
+ ccs_rpc_connect( /* make call with user message: */
+ CCMSG_CONNECT, /* Message type */
+ (unsigned char*)&tsp, /* Our tspdata* will be sent back to the reply proc. */
+ (unsigned char*)uuid,
+ (long*)(&status) ); /* Return code */
+ }
+ RpcExcept(1) {
+ cci_check_error(RpcExceptionCode());
+ status = ccErrBadInternalMessage;
+ }
+ RpcEndExcept;
+ }
+
+ CcAutoLock::Stop(a);
+ SecureClient::Stop(s);
+ ReleaseMutex(hCCAPIv2Mutex);
+
+ if (!status) {
+ cci_debug_printf("%s Waiting for replyEvent.", __FUNCTION__);
+ status = WaitForSingleObject(replyEvent, INFINITE);//(SECONDS_TO_WAIT)*1000);
+ status = cci_check_error(RpcMgmtIsServerListening(CLIENT_REQUEST_RPC_HANDLE));
+ cci_debug_printf(" Server %sFOUND!", (status) ? "NOT " : "");
+ }
+ if (status) {
+ cci_debug_printf(" unexpected error while looking for server... (%u)", status);
+ }
+
+ cci_debug_printf("%s TODO: check connect reply result.", __FUNCTION__);
+ cci_debug_printf("%s TODO: merge this connect code with that request code.", __FUNCTION__);
+ return status;
} \ No newline at end of file
diff --git a/src/ccapi/lib/win/ccs_reply_proc.c b/src/ccapi/lib/win/ccs_reply_proc.c
index ebac6e3..f9eef87 100644
--- a/src/ccapi/lib/win/ccs_reply_proc.c
+++ b/src/ccapi/lib/win/ccs_reply_proc.c
@@ -1,98 +1,98 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <windows.h>
-
-#include "cci_debugging.h"
-#include "ccs_reply.h" /* generated by MIDL compiler */
-#include "ccutils.h"
-#include "tls.h"
-#include "win-utils.h"
-
-
-void ccs_rpc_request_reply(
- const long rpcmsg, /* Message type */
- const char tspHandle[], /* Client's tspdata* */
- const char* uuid, /* uuid for making thread-specific event name */
- const long srvStartTime, /* Server Start Time */
- const long cbIn, /* Length of buffer */
- const char* chIn, /* Data buffer */
- long* ret_status ) { /* Return code */
-
- HANDLE hEvent = openThreadEvent(uuid, REPLY_SUFFIX);
- DWORD* p = (DWORD*)(tspHandle);
- struct tspdata* tsp = (struct tspdata*)*p;
- cci_stream_t stream;
- long status = 0;
-
- cci_debug_printf("%s! msg#:%d SST:%ld uuid:%s", __FUNCTION__, rpcmsg, srvStartTime, uuid);
- cci_debug_printf(" payload:<%s>", chIn);
- cci_debug_printf(" uuid from handle:<%s>", tspdata_getUUID(tsp));
-
- if (!status) {
- status = cci_stream_new (&stream); /* Create a stream for the request data */
- }
-
- if (!status) { /* Put the data into the stream */
- status = cci_stream_write (stream, chIn, cbIn);
- }
-
- if (!status) { /* Put the data into the stream */
- tspdata_setStream(tsp, stream);
- }
-
- SetEvent(hEvent);
- CloseHandle(hEvent);
- *ret_status = status;
- }
-
-void ccs_rpc_connect_reply(
- const long rpcmsg, /* Message type */
- const char tspHandle[], /* Client's tspdata* */
- const char* uuid, /* uuid for making thread-specific event name */
- const long srvStartTime, /* Server Start Time */
- long* status ) { /* Return code */
-
- HANDLE hEvent = openThreadEvent(uuid, REPLY_SUFFIX);
- DWORD* p = (DWORD*)(tspHandle);
-
- cci_debug_printf("%s! msg#:%d SST:%ld uuid:%s", __FUNCTION__, rpcmsg, srvStartTime, uuid);
-
- SetEvent(hEvent);
- CloseHandle(hEvent);
- }
-
-void ccapi_listen(
- RPC_ASYNC_STATE* rpcState,
- handle_t hBinding,
- const long rpcmsg, /* Message type */
- long* status ) { /* Return code */
-
- cci_debug_printf("%s %s!", __FUNCTION__, rpcState->UserInfo);
- *status = 0;
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <windows.h>
+
+#include "cci_debugging.h"
+#include "ccs_reply.h" /* generated by MIDL compiler */
+#include "ccutils.h"
+#include "tls.h"
+#include "win-utils.h"
+
+
+void ccs_rpc_request_reply(
+ const long rpcmsg, /* Message type */
+ const char tspHandle[], /* Client's tspdata* */
+ const char* uuid, /* uuid for making thread-specific event name */
+ const long srvStartTime, /* Server Start Time */
+ const long cbIn, /* Length of buffer */
+ const char* chIn, /* Data buffer */
+ long* ret_status ) { /* Return code */
+
+ HANDLE hEvent = openThreadEvent(uuid, REPLY_SUFFIX);
+ DWORD* p = (DWORD*)(tspHandle);
+ struct tspdata* tsp = (struct tspdata*)*p;
+ cci_stream_t stream;
+ long status = 0;
+
+ cci_debug_printf("%s! msg#:%d SST:%ld uuid:%s", __FUNCTION__, rpcmsg, srvStartTime, uuid);
+ cci_debug_printf(" payload:<%s>", chIn);
+ cci_debug_printf(" uuid from handle:<%s>", tspdata_getUUID(tsp));
+
+ if (!status) {
+ status = cci_stream_new (&stream); /* Create a stream for the request data */
+ }
+
+ if (!status) { /* Put the data into the stream */
+ status = cci_stream_write (stream, chIn, cbIn);
+ }
+
+ if (!status) { /* Put the data into the stream */
+ tspdata_setStream(tsp, stream);
+ }
+
+ SetEvent(hEvent);
+ CloseHandle(hEvent);
+ *ret_status = status;
+ }
+
+void ccs_rpc_connect_reply(
+ const long rpcmsg, /* Message type */
+ const char tspHandle[], /* Client's tspdata* */
+ const char* uuid, /* uuid for making thread-specific event name */
+ const long srvStartTime, /* Server Start Time */
+ long* status ) { /* Return code */
+
+ HANDLE hEvent = openThreadEvent(uuid, REPLY_SUFFIX);
+ DWORD* p = (DWORD*)(tspHandle);
+
+ cci_debug_printf("%s! msg#:%d SST:%ld uuid:%s", __FUNCTION__, rpcmsg, srvStartTime, uuid);
+
+ SetEvent(hEvent);
+ CloseHandle(hEvent);
+ }
+
+void ccapi_listen(
+ RPC_ASYNC_STATE* rpcState,
+ handle_t hBinding,
+ const long rpcmsg, /* Message type */
+ long* status ) { /* Return code */
+
+ cci_debug_printf("%s %s!", __FUNCTION__, rpcState->UserInfo);
+ *status = 0;
+ }
diff --git a/src/ccapi/lib/win/dllmain.cxx b/src/ccapi/lib/win/dllmain.cxx
index 7000e14..dafbab2 100644
--- a/src/ccapi/lib/win/dllmain.cxx
+++ b/src/ccapi/lib/win/dllmain.cxx
@@ -1,279 +1,279 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <windows.h>
-#include <LMCons.h>
-
-extern "C" {
-#include "dllmain.h"
-#include "tls.h"
-#include "cci_debugging.h"
-#include "ccapi_context.h"
-#include "client.h"
-
-//void cci_thread_init__auxinit();
- }
-
-#define CCAPI_V2_MUTEX_NAME TEXT("MIT_CCAPI_V4_MUTEX")
-
-// Process-specific data:
-static DWORD dwTlsIndex;
-static char _user[UNLEN+1]; // Username is used as part of the server and client endpoints.
-static HANDLE sessionToken;
-static char* ep_prefices[] = {"CCS", "CCAPI"};
-HANDLE hCCAPIv2Mutex = NULL;
-DWORD firstThreadID = 0;
-
-// These data structures are used by the old CCAPI implementation
-// to keep track of the state of the RPC connection. All data is static.
-static Init init;
-static Client client;
-
-// DllMain() is the entry-point function for this DLL.
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
- DWORD fdwReason, // reason called
- LPVOID lpvReserved) { // reserved
-
- struct tspdata* ptspdata;
- BOOL fIgnore;
- BOOL bStatus;
- DWORD status = 0; // 0 is success.
- DWORD maxUN = sizeof(_user);
- unsigned int i = 0;
- unsigned int j = 0;
-
- switch (fdwReason) {
- // The DLL is loading due to process initialization or a call to LoadLibrary:
- case DLL_PROCESS_ATTACH:
- cci_debug_printf("%s DLL_PROCESS_ATTACH", __FUNCTION__);
- // Process-wide mutex used to allow only one thread at a time into the RPC code:
- hCCAPIv2Mutex = CreateMutex(NULL, FALSE, CCAPI_V2_MUTEX_NAME);
-
- // Figure out our username; it's process-wide:
- bStatus = GetUserName(_user, &maxUN);
- if (!bStatus) return bStatus;
-
- // Remove any characters that aren't valid endpoint characters:
- while (_user[j] != 0) {
- if (isalnum(_user[j])) _user[i++] = _user[j];
- j++;
- }
- _user[i] = '\0';
-
- // Our logon session is determined in client.cxx, old CCAPI code carried
- // over to this implementation.
-
- // Allocate a TLS index:
- if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
-
- // Initialize CCAPI once per DLL load:
- firstThreadID = GetCurrentThreadId();
-
- // Don't break; fallthrough: Initialize the TLS index for first thread.
-
- // The attached process creates a new thread:
- case DLL_THREAD_ATTACH:
- // Initialize the TLS index for this thread:
- ptspdata = (struct tspdata*) LocalAlloc(LPTR, sizeof(struct tspdata));
- cci_debug_printf("%s DLL_THREAD_ATTACH; tsp*:0x%X", __FUNCTION__, ptspdata);
- if (ptspdata == NULL) return FALSE;
- fIgnore = TlsSetValue(dwTlsIndex, ptspdata);
-
- memset(ptspdata, 0, sizeof(struct tspdata));
-
- // Initialize CCAPI once per DLL load:
- if (GetCurrentThreadId() == firstThreadID) cci_thread_init__auxinit();
-
- break;
-
- // The thread of the attached process terminates:
- case DLL_THREAD_DETACH:
- cci_debug_printf("%s DLL_THREAD_DETACH", __FUNCTION__);
- // Release the allocated memory for this thread:
- ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
- if (ptspdata != NULL) {
- LocalFree((HLOCAL) ptspdata);
- TlsSetValue(dwTlsIndex, NULL);
- }
- break;
-
- // DLL unload due to process termination or FreeLibrary:
- case DLL_PROCESS_DETACH:
- cci_debug_printf("%s DLL_PROCESS_DETACH", __FUNCTION__);
- //++ Copied from previous implementation:
- // Process Teardown "Problem"
- //
- // There are two problems that occur during process teardown:
- //
- // 1) Windows (NT/9x/2000) does not keep track of load/unload
- // ordering dependencies for use in process teardown.
- //
- // 2) The RPC exception handling in the RPC calls do not work
- // during process shutdown in Win9x.
- //
- // When a process is being torn down in Windows, the krbcc DLL
- // may get a DLL_PROCESS_DETACH before other DLLs are done
- // with it. Thus, it may disconnect from the RPC server
- // before the last shutdown RPC call.
- //
- // On NT/2000, this is ok because the RPC call will fail and just
- // return an error.
- //
- // On Win9x/Me, the RPC exception will not be caught.
- // However, Win9x ignores exceptions during process shutdown,
- // so the exception will never be seen unless a debugger is
- // attached to the proccess.
- //
- // A good potential woraround would be to have a global
- // variable that denotes whether the DLL is attached to the
- // process. If it is not, all entrypoints into the DLL should
- // return failure.
- //
- // A not as good workaround is below but ifdefed out.
- //
- // However, we can safely ignore this problem since it can
- // only affects people running debuggers under 9x/Me who are
- // using multiple DLLs that use this DLL.
- //
- WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
-#if 0
- bool process_teardown_workaround = false;
- if (lpvReserved) {
- Init::InitInfo info;
- status = Init::Info(info);
- if (status) break;
- if (!info.isNT) process_teardown_workaround = true;
- }
- if (process_teardown_workaround)
- break;
-#endif
- // return value is ignored, so we set status for debugging purposes
- status = Client::Cleanup();
- status = Init::Cleanup();
- ReleaseMutex( hCCAPIv2Mutex );
- CloseHandle( hCCAPIv2Mutex );
- //-- Copied from previous implementation.
-
- // Release the allocated memory for this thread:
- ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
- if (ptspdata != NULL) LocalFree((HLOCAL) ptspdata);
- TlsFree(dwTlsIndex); // Release the TLS index.
- break;
-
- default: break;
- }
-
- UNREFERENCED_PARAMETER(hinstDLL); // no whining!
- UNREFERENCED_PARAMETER(lpvReserved);
- return status ? FALSE : TRUE;
-}
-
-
-#ifdef __cplusplus // If used by C++ code,
-extern "C" { // we need to export the C interface
-#endif
-
-__declspec(dllexport)
-BOOL WINAPI PutTspData(struct tspdata* dw) {
- LPVOID lpvData;
- struct tspdata** pData; // The stored memory pointer
-
- // Retrieve a data pointer for the current thread:
- lpvData = TlsGetValue(dwTlsIndex);
-
- // If NULL, allocate memory for the TLS slot for this thread:
- if (lpvData == NULL) {
- lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct tspdata));
- if (lpvData == NULL) return FALSE;
- if (!TlsSetValue(dwTlsIndex, lpvData)) return FALSE;
- }
-
- pData = (struct tspdata**) lpvData; // Cast to my data type.
- // In this example, it is only a pointer to a DWORD
- // but it can be a structure pointer to contain more complicated data.
-
- (*pData) = dw;
- return TRUE;
- }
-
-__declspec(dllexport)
-BOOL WINAPI GetTspData(struct tspdata** pdw) {
- struct tspdata* pData; // The stored memory pointer
-
- pData = (struct tspdata*)TlsGetValue(dwTlsIndex);
- if (pData == NULL) return FALSE;
- (*pdw) = pData;
- return TRUE;
- }
-
-#if 0 // replaced by clientEndpoint / serverEndpoint.
-__declspec(dllexport)
-char* WINAPI getEndpoint(enum EndpointType ep) {
- // The server endpoint is of the form CCS_<LSID>
- // The client endpoint is of the form CCAPI_<uuid>
- // Each client thread can have its own connection.
- //
- // NB: Caller must free the data the returned char* points to.
- struct tspdata* pData;
- char* s;
- char* uuid;
- unsigned int len;
-
- switch (ep) {
- case EPT_SERVER:
- s = (char*)malloc(32); // Length of CCS_<DWORD>
- sprintf(s, "%s_%ld", ep_prefices[EPT_SERVER], sessionToken);
- break;
- case EPT_CLIENT:
- GetTspData(&pData);
- uuid = tspdata_getUUID(pData);
- len = 4 + strlen(ep_prefices[ep]) + strlen(_user) + strlen(uuid);
- s = (char*)malloc(len);
- sprintf(s, "%s_%s_%s", ep_prefices[EPT_CLIENT], _user, uuid);
- break;
- default:;
- }
- cci_debug_printf("%s(%d) returning %s", __FUNCTION__, ep, s);
-
- return s;
- }
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-/*********************************************************************/
-/* MIDL allocate and free */
-/*********************************************************************/
-
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
- return(malloc(len));
- }
-
-void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
- free(ptr);
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <windows.h>
+#include <LMCons.h>
+
+extern "C" {
+#include "dllmain.h"
+#include "tls.h"
+#include "cci_debugging.h"
+#include "ccapi_context.h"
+#include "client.h"
+
+//void cci_thread_init__auxinit();
+ }
+
+#define CCAPI_V2_MUTEX_NAME TEXT("MIT_CCAPI_V4_MUTEX")
+
+// Process-specific data:
+static DWORD dwTlsIndex;
+static char _user[UNLEN+1]; // Username is used as part of the server and client endpoints.
+static HANDLE sessionToken;
+static char* ep_prefices[] = {"CCS", "CCAPI"};
+HANDLE hCCAPIv2Mutex = NULL;
+DWORD firstThreadID = 0;
+
+// These data structures are used by the old CCAPI implementation
+// to keep track of the state of the RPC connection. All data is static.
+static Init init;
+static Client client;
+
+// DllMain() is the entry-point function for this DLL.
+BOOL WINAPI DllMain(HINSTANCE hinstDLL, // DLL module handle
+ DWORD fdwReason, // reason called
+ LPVOID lpvReserved) { // reserved
+
+ struct tspdata* ptspdata;
+ BOOL fIgnore;
+ BOOL bStatus;
+ DWORD status = 0; // 0 is success.
+ DWORD maxUN = sizeof(_user);
+ unsigned int i = 0;
+ unsigned int j = 0;
+
+ switch (fdwReason) {
+ // The DLL is loading due to process initialization or a call to LoadLibrary:
+ case DLL_PROCESS_ATTACH:
+ cci_debug_printf("%s DLL_PROCESS_ATTACH", __FUNCTION__);
+ // Process-wide mutex used to allow only one thread at a time into the RPC code:
+ hCCAPIv2Mutex = CreateMutex(NULL, FALSE, CCAPI_V2_MUTEX_NAME);
+
+ // Figure out our username; it's process-wide:
+ bStatus = GetUserName(_user, &maxUN);
+ if (!bStatus) return bStatus;
+
+ // Remove any characters that aren't valid endpoint characters:
+ while (_user[j] != 0) {
+ if (isalnum(_user[j])) _user[i++] = _user[j];
+ j++;
+ }
+ _user[i] = '\0';
+
+ // Our logon session is determined in client.cxx, old CCAPI code carried
+ // over to this implementation.
+
+ // Allocate a TLS index:
+ if ((dwTlsIndex = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
+
+ // Initialize CCAPI once per DLL load:
+ firstThreadID = GetCurrentThreadId();
+
+ // Don't break; fallthrough: Initialize the TLS index for first thread.
+
+ // The attached process creates a new thread:
+ case DLL_THREAD_ATTACH:
+ // Initialize the TLS index for this thread:
+ ptspdata = (struct tspdata*) LocalAlloc(LPTR, sizeof(struct tspdata));
+ cci_debug_printf("%s DLL_THREAD_ATTACH; tsp*:0x%X", __FUNCTION__, ptspdata);
+ if (ptspdata == NULL) return FALSE;
+ fIgnore = TlsSetValue(dwTlsIndex, ptspdata);
+
+ memset(ptspdata, 0, sizeof(struct tspdata));
+
+ // Initialize CCAPI once per DLL load:
+ if (GetCurrentThreadId() == firstThreadID) cci_thread_init__auxinit();
+
+ break;
+
+ // The thread of the attached process terminates:
+ case DLL_THREAD_DETACH:
+ cci_debug_printf("%s DLL_THREAD_DETACH", __FUNCTION__);
+ // Release the allocated memory for this thread:
+ ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
+ if (ptspdata != NULL) {
+ LocalFree((HLOCAL) ptspdata);
+ TlsSetValue(dwTlsIndex, NULL);
+ }
+ break;
+
+ // DLL unload due to process termination or FreeLibrary:
+ case DLL_PROCESS_DETACH:
+ cci_debug_printf("%s DLL_PROCESS_DETACH", __FUNCTION__);
+ //++ Copied from previous implementation:
+ // Process Teardown "Problem"
+ //
+ // There are two problems that occur during process teardown:
+ //
+ // 1) Windows (NT/9x/2000) does not keep track of load/unload
+ // ordering dependencies for use in process teardown.
+ //
+ // 2) The RPC exception handling in the RPC calls do not work
+ // during process shutdown in Win9x.
+ //
+ // When a process is being torn down in Windows, the krbcc DLL
+ // may get a DLL_PROCESS_DETACH before other DLLs are done
+ // with it. Thus, it may disconnect from the RPC server
+ // before the last shutdown RPC call.
+ //
+ // On NT/2000, this is ok because the RPC call will fail and just
+ // return an error.
+ //
+ // On Win9x/Me, the RPC exception will not be caught.
+ // However, Win9x ignores exceptions during process shutdown,
+ // so the exception will never be seen unless a debugger is
+ // attached to the proccess.
+ //
+ // A good potential woraround would be to have a global
+ // variable that denotes whether the DLL is attached to the
+ // process. If it is not, all entrypoints into the DLL should
+ // return failure.
+ //
+ // A not as good workaround is below but ifdefed out.
+ //
+ // However, we can safely ignore this problem since it can
+ // only affects people running debuggers under 9x/Me who are
+ // using multiple DLLs that use this DLL.
+ //
+ WaitForSingleObject( hCCAPIv2Mutex, INFINITE );
+#if 0
+ bool process_teardown_workaround = false;
+ if (lpvReserved) {
+ Init::InitInfo info;
+ status = Init::Info(info);
+ if (status) break;
+ if (!info.isNT) process_teardown_workaround = true;
+ }
+ if (process_teardown_workaround)
+ break;
+#endif
+ // return value is ignored, so we set status for debugging purposes
+ status = Client::Cleanup();
+ status = Init::Cleanup();
+ ReleaseMutex( hCCAPIv2Mutex );
+ CloseHandle( hCCAPIv2Mutex );
+ //-- Copied from previous implementation.
+
+ // Release the allocated memory for this thread:
+ ptspdata = (struct tspdata*)TlsGetValue(dwTlsIndex);
+ if (ptspdata != NULL) LocalFree((HLOCAL) ptspdata);
+ TlsFree(dwTlsIndex); // Release the TLS index.
+ break;
+
+ default: break;
+ }
+
+ UNREFERENCED_PARAMETER(hinstDLL); // no whining!
+ UNREFERENCED_PARAMETER(lpvReserved);
+ return status ? FALSE : TRUE;
+}
+
+
+#ifdef __cplusplus // If used by C++ code,
+extern "C" { // we need to export the C interface
+#endif
+
+__declspec(dllexport)
+BOOL WINAPI PutTspData(struct tspdata* dw) {
+ LPVOID lpvData;
+ struct tspdata** pData; // The stored memory pointer
+
+ // Retrieve a data pointer for the current thread:
+ lpvData = TlsGetValue(dwTlsIndex);
+
+ // If NULL, allocate memory for the TLS slot for this thread:
+ if (lpvData == NULL) {
+ lpvData = (LPVOID) LocalAlloc(LPTR, sizeof(struct tspdata));
+ if (lpvData == NULL) return FALSE;
+ if (!TlsSetValue(dwTlsIndex, lpvData)) return FALSE;
+ }
+
+ pData = (struct tspdata**) lpvData; // Cast to my data type.
+ // In this example, it is only a pointer to a DWORD
+ // but it can be a structure pointer to contain more complicated data.
+
+ (*pData) = dw;
+ return TRUE;
+ }
+
+__declspec(dllexport)
+BOOL WINAPI GetTspData(struct tspdata** pdw) {
+ struct tspdata* pData; // The stored memory pointer
+
+ pData = (struct tspdata*)TlsGetValue(dwTlsIndex);
+ if (pData == NULL) return FALSE;
+ (*pdw) = pData;
+ return TRUE;
+ }
+
+#if 0 // replaced by clientEndpoint / serverEndpoint.
+__declspec(dllexport)
+char* WINAPI getEndpoint(enum EndpointType ep) {
+ // The server endpoint is of the form CCS_<LSID>
+ // The client endpoint is of the form CCAPI_<uuid>
+ // Each client thread can have its own connection.
+ //
+ // NB: Caller must free the data the returned char* points to.
+ struct tspdata* pData;
+ char* s;
+ char* uuid;
+ unsigned int len;
+
+ switch (ep) {
+ case EPT_SERVER:
+ s = (char*)malloc(32); // Length of CCS_<DWORD>
+ sprintf(s, "%s_%ld", ep_prefices[EPT_SERVER], sessionToken);
+ break;
+ case EPT_CLIENT:
+ GetTspData(&pData);
+ uuid = tspdata_getUUID(pData);
+ len = 4 + strlen(ep_prefices[ep]) + strlen(_user) + strlen(uuid);
+ s = (char*)malloc(len);
+ sprintf(s, "%s_%s_%s", ep_prefices[EPT_CLIENT], _user, uuid);
+ break;
+ default:;
+ }
+ cci_debug_printf("%s(%d) returning %s", __FUNCTION__, ep, s);
+
+ return s;
+ }
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+/*********************************************************************/
+/* MIDL allocate and free */
+/*********************************************************************/
+
+void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
+ return(malloc(len));
+ }
+
+void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
+ free(ptr);
+ }
diff --git a/src/ccapi/lib/win/dllmain.h b/src/ccapi/lib/win/dllmain.h
index 3ce2ac2..8c58572 100644
--- a/src/ccapi/lib/win/dllmain.h
+++ b/src/ccapi/lib/win/dllmain.h
@@ -1,45 +1,45 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef _dll_h
-#define _dll_h
-
-#include "windows.h"
-
-enum EndpointType {EPT_SERVER=0, EPT_CLIENT};
-
-#ifdef __cplusplus // If used by C++ code,
-extern "C" { // we need to export the C interface
-#endif
-__declspec(dllexport) BOOL WINAPI PutTspData(struct tspdata* p);
-__declspec(dllexport) BOOL WINAPI GetTspData(struct tspdata** p);
-
-//__declspec(dllexport) char* WINAPI getEndpoint(enum EndpointType);
-#ifdef __cplusplus
-}
-#endif
-
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef _dll_h
+#define _dll_h
+
+#include "windows.h"
+
+enum EndpointType {EPT_SERVER=0, EPT_CLIENT};
+
+#ifdef __cplusplus // If used by C++ code,
+extern "C" { // we need to export the C interface
+#endif
+__declspec(dllexport) BOOL WINAPI PutTspData(struct tspdata* p);
+__declspec(dllexport) BOOL WINAPI GetTspData(struct tspdata** p);
+
+//__declspec(dllexport) char* WINAPI getEndpoint(enum EndpointType);
+#ifdef __cplusplus
+}
+#endif
+
#endif _dll_h \ No newline at end of file
diff --git a/src/ccapi/server/ccs_credentials.c b/src/ccapi/server/ccs_credentials.c
index 04c8e21..72721e6 100644
--- a/src/ccapi/server/ccs_credentials.c
+++ b/src/ccapi/server/ccs_credentials.c
@@ -56,7 +56,7 @@ cc_int32 ccs_credentials_new (ccs_credentials_t *out_credentials,
}
if (!err) {
- err = cci_cred_union_read (&credentials->cred_union, in_stream);
+ err = cci_credentials_union_read (&credentials->cred_union, in_stream);
}
if (!err && !(credentials->cred_union->version & in_ccache_version)) {
@@ -89,7 +89,7 @@ cc_int32 ccs_credentials_release (ccs_credentials_t io_credentials)
cc_int32 err = ccNoError;
if (!err && io_credentials) {
- cci_cred_union_release (io_credentials->cred_union);
+ cci_credentials_union_release (io_credentials->cred_union);
cci_identifier_release (io_credentials->identifier);
free (io_credentials);
}
@@ -112,7 +112,7 @@ cc_int32 ccs_credentials_write (ccs_credentials_t in_credentials,
}
if (!err) {
- err = cci_cred_union_write (in_credentials->cred_union, io_stream);
+ err = cci_credentials_union_write (in_credentials->cred_union, io_stream);
}
return cci_check_error (err);
diff --git a/src/ccapi/server/win/WorkQueue.h b/src/ccapi/server/win/WorkQueue.h
index 106f9ac..eb46780 100644
--- a/src/ccapi/server/win/WorkQueue.h
+++ b/src/ccapi/server/win/WorkQueue.h
@@ -1,46 +1,46 @@
-/*
- * $Header$
- *
- * Copyright 2007 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef _work_queue_h
-#define _work_queue_h
-
-#include "windows.h"
-#include "cci_stream.h"
-#include "ccs_pipe.h"
-
-EXTERN_C BOOL worklist_isEmpty();
-
-EXTERN_C void worklist_add( const long rpcmsg,
- const ccs_pipe_t pipe,
- const cci_stream_t stream,
- const time_t serverStartTime);
-
-EXTERN_C int worklist_remove(long* rpcmsg,
- ccs_pipe_t* pipe,
- cci_stream_t* stream,
- time_t* serverStartTime);
-
+/*
+ * $Header$
+ *
+ * Copyright 2007 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef _work_queue_h
+#define _work_queue_h
+
+#include "windows.h"
+#include "cci_stream.h"
+#include "ccs_pipe.h"
+
+EXTERN_C BOOL worklist_isEmpty();
+
+EXTERN_C void worklist_add( const long rpcmsg,
+ const ccs_pipe_t pipe,
+ const cci_stream_t stream,
+ const time_t serverStartTime);
+
+EXTERN_C int worklist_remove(long* rpcmsg,
+ ccs_pipe_t* pipe,
+ cci_stream_t* stream,
+ time_t* serverStartTime);
+
#endif // _work_queue_h \ No newline at end of file
diff --git a/src/ccapi/server/win/ccs_os_pipe.c b/src/ccapi/server/win/ccs_os_pipe.c
index 69dcec4..95af378 100644
--- a/src/ccapi/server/win/ccs_os_pipe.c
+++ b/src/ccapi/server/win/ccs_os_pipe.c
@@ -1,64 +1,64 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "ccs_common.h"
-#include "ccs_os_pipe.h"
-#include "ccs_win_pipe.h"
-
-/* ------------------------------------------------------------------------ */
-
-/* On Windows, a pipe is a struct. See ccs_win_pipe.h for details. */
-
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_os_pipe_valid (ccs_pipe_t in_pipe) {
- return ccs_win_pipe_valid(in_pipe);
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_os_pipe_copy (ccs_pipe_t* out_pipe, ccs_pipe_t in_pipe) {
- return ccs_win_pipe_copy(
- out_pipe,
- in_pipe);
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_os_pipe_release (ccs_pipe_t io_pipe) {
- return ccs_win_pipe_release(io_pipe);
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_os_pipe_compare (ccs_pipe_t pipe_1,
- ccs_pipe_t pipe_2,
- cc_uint32 *out_equal) {
-
- return ccs_win_pipe_compare(pipe_1, pipe_2, out_equal);
- }
-
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "ccs_common.h"
+#include "ccs_os_pipe.h"
+#include "ccs_win_pipe.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* On Windows, a pipe is a struct. See ccs_win_pipe.h for details. */
+
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_os_pipe_valid (ccs_pipe_t in_pipe) {
+ return ccs_win_pipe_valid(in_pipe);
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_os_pipe_copy (ccs_pipe_t* out_pipe, ccs_pipe_t in_pipe) {
+ return ccs_win_pipe_copy(
+ out_pipe,
+ in_pipe);
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_os_pipe_release (ccs_pipe_t io_pipe) {
+ return ccs_win_pipe_release(io_pipe);
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_os_pipe_compare (ccs_pipe_t pipe_1,
+ ccs_pipe_t pipe_2,
+ cc_uint32 *out_equal) {
+
+ return ccs_win_pipe_compare(pipe_1, pipe_2, out_equal);
+ }
+
diff --git a/src/ccapi/server/win/ccs_request_proc.c b/src/ccapi/server/win/ccs_request_proc.c
index 40713fb..a1c082d 100644
--- a/src/ccapi/server/win/ccs_request_proc.c
+++ b/src/ccapi/server/win/ccs_request_proc.c
@@ -1,116 +1,116 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "ccs_request.h" // header file generated by MIDL compiler
-#include "cci_debugging.h"
-#include "WorkQueue.h"
-#include "win-utils.h"
-#include "ccs_win_pipe.h"
-
-void ccs_rpc_request(
- const long rpcmsg, /* Message type */
- const char tspHandle[], /* Client's tspdata* */
- const char* pszUUID, /* Where client will listen for the reply */
- const long lenRequest, /* Length of buffer */
- const char pbRequest[], /* Data buffer */
- const long serverStartTime, /* Which server session we're talking to */
- long* return_status ) { /* Return code */
-
- cc_int32 status = 0;
- cci_stream_t stream;
- DWORD* p = (DWORD*)(tspHandle);
- WIN_PIPE* pipe = NULL;
-
- cci_debug_printf("%s rpcmsg:%d; UUID:<%s> SST:<%s>",
- __FUNCTION__, rpcmsg, pszUUID, serverStartTime);
-
- status = (rpcmsg != CCMSG_REQUEST) && (rpcmsg != CCMSG_PING);
-
- if (!status) {
- status = cci_stream_new (&stream); /* Create a stream for the request data */
- }
-
- if (!status) { /* Put the data into the stream */
- status = cci_stream_write (stream, pbRequest, lenRequest);
- }
-
- pipe = ccs_win_pipe_new(pszUUID, *p);
- worklist_add(rpcmsg, pipe, stream, serverStartTime);
- *return_status = status;
- }
-
-
-void ccs_rpc_connect(
- const long rpcmsg, /* Message type */
- const char tspHandle[], /* Client's tspdata* */
- const char* pszUUID, /* Data buffer */
- long* return_status ) { /* Return code */
-
- DWORD* p = (DWORD*)(tspHandle);
- WIN_PIPE* pipe = ccs_win_pipe_new(pszUUID, *p);
-
- cci_debug_printf("%s; rpcmsg:%d; UUID: <%s>", __FUNCTION__, rpcmsg, pszUUID);
-
- worklist_add( rpcmsg,
- pipe,
- NULL, /* No payload with connect request */
- (const time_t)0 ); /* No server session number with connect request */
- }
-
-
-// 'Authentication' is client setting a value in a file and the server
-// returning that value plus one.
-CC_UINT32 ccs_authenticate(const CC_CHAR* name) {
- HANDLE hMap = 0;
- PDWORD pvalue = 0;
- CC_UINT32 result = 0;
- DWORD status = 0;
-
- cci_debug_printf("%s ( %s )", __FUNCTION__, name);
-
- hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, (LPSTR)name);
- status = !hMap;
-
- if (!status) {
- pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);
- status = !pvalue;
- }
-
- if (!status) {
- *pvalue += 1;
- result = *pvalue;
- }
-
- if (pvalue) {
- UnmapViewOfFile(pvalue);
- }
-
- if (hMap) CloseHandle(hMap);
- return result;
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "ccs_request.h" // header file generated by MIDL compiler
+#include "cci_debugging.h"
+#include "WorkQueue.h"
+#include "win-utils.h"
+#include "ccs_win_pipe.h"
+
+void ccs_rpc_request(
+ const long rpcmsg, /* Message type */
+ const char tspHandle[], /* Client's tspdata* */
+ const char* pszUUID, /* Where client will listen for the reply */
+ const long lenRequest, /* Length of buffer */
+ const char pbRequest[], /* Data buffer */
+ const long serverStartTime, /* Which server session we're talking to */
+ long* return_status ) { /* Return code */
+
+ cc_int32 status = 0;
+ cci_stream_t stream;
+ DWORD* p = (DWORD*)(tspHandle);
+ WIN_PIPE* pipe = NULL;
+
+ cci_debug_printf("%s rpcmsg:%d; UUID:<%s> SST:<%s>",
+ __FUNCTION__, rpcmsg, pszUUID, serverStartTime);
+
+ status = (rpcmsg != CCMSG_REQUEST) && (rpcmsg != CCMSG_PING);
+
+ if (!status) {
+ status = cci_stream_new (&stream); /* Create a stream for the request data */
+ }
+
+ if (!status) { /* Put the data into the stream */
+ status = cci_stream_write (stream, pbRequest, lenRequest);
+ }
+
+ pipe = ccs_win_pipe_new(pszUUID, *p);
+ worklist_add(rpcmsg, pipe, stream, serverStartTime);
+ *return_status = status;
+ }
+
+
+void ccs_rpc_connect(
+ const long rpcmsg, /* Message type */
+ const char tspHandle[], /* Client's tspdata* */
+ const char* pszUUID, /* Data buffer */
+ long* return_status ) { /* Return code */
+
+ DWORD* p = (DWORD*)(tspHandle);
+ WIN_PIPE* pipe = ccs_win_pipe_new(pszUUID, *p);
+
+ cci_debug_printf("%s; rpcmsg:%d; UUID: <%s>", __FUNCTION__, rpcmsg, pszUUID);
+
+ worklist_add( rpcmsg,
+ pipe,
+ NULL, /* No payload with connect request */
+ (const time_t)0 ); /* No server session number with connect request */
+ }
+
+
+// 'Authentication' is client setting a value in a file and the server
+// returning that value plus one.
+CC_UINT32 ccs_authenticate(const CC_CHAR* name) {
+ HANDLE hMap = 0;
+ PDWORD pvalue = 0;
+ CC_UINT32 result = 0;
+ DWORD status = 0;
+
+ cci_debug_printf("%s ( %s )", __FUNCTION__, name);
+
+ hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, (LPSTR)name);
+ status = !hMap;
+
+ if (!status) {
+ pvalue = (PDWORD)MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0);
+ status = !pvalue;
+ }
+
+ if (!status) {
+ *pvalue += 1;
+ result = *pvalue;
+ }
+
+ if (pvalue) {
+ UnmapViewOfFile(pvalue);
+ }
+
+ if (hMap) CloseHandle(hMap);
+ return result;
} \ No newline at end of file
diff --git a/src/ccapi/server/win/ccs_win_pipe.c b/src/ccapi/server/win/ccs_win_pipe.c
index 4d121aa..a8fea2f 100644
--- a/src/ccapi/server/win/ccs_win_pipe.c
+++ b/src/ccapi/server/win/ccs_win_pipe.c
@@ -1,163 +1,163 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#include "assert.h"
-
-#include "ccs_win_pipe.h"
-#include "cci_debugging.h"
-
-/* Ref:
-struct ccs_win_pipe_t {
- char* uuid;
- HANDLE clientHandle;
- }
- */
-
-/* ------------------------------------------------------------------------ */
-
-struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const HANDLE h) {
-
- cc_int32 err = ccNoError;
- struct ccs_win_pipe_t* out_pipe = NULL;
- char* uuidCopy = NULL;
-
- if (!err) {
- if (!uuid) {err = cci_check_error(ccErrBadParam);}
- }
-
- if (!err) {
- uuidCopy = (char*)malloc(1+strlen(uuid));
- if (!uuidCopy) {err = cci_check_error(ccErrBadParam);}
- strcpy(uuidCopy, uuid);
- }
-
- if (!err) {
- out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t));
- if (!out_pipe) {err = cci_check_error(ccErrBadParam);}
- out_pipe->uuid = uuidCopy;
- out_pipe->clientHandle = h;
- }
-
- cci_debug_printf("0x%X = %s(%s, 0x%X)", out_pipe, __FUNCTION__, uuid, h);
-
- return out_pipe;
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
- const WIN_PIPE* in_pipe) {
-
- *out_pipe =
- ccs_win_pipe_new(
- ccs_win_pipe_getUuid (in_pipe),
- ccs_win_pipe_getHandle(in_pipe) );
-
- return (*out_pipe) ? ccNoError : ccErrBadParam;
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) {
-
- cc_int32 err = ccNoError;
-
- if (!ccs_win_pipe_valid(in_pipe)) {err = cci_check_error(ccErrBadParam);}
-
- if (!err) {
- if (!in_pipe->uuid) free(in_pipe->uuid);
- if (!in_pipe) free(in_pipe);
- }
-
- return err;
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) {
-
- if (!in_pipe) {
- cci_check_error(ccErrBadParam);
- return FALSE;
- }
-
- if (!in_pipe->uuid) {
- cci_check_error(ccErrBadParam);
- return FALSE;
- }
-
- return TRUE;
- }
-
-/* ------------------------------------------------------------------------ */
-
-cc_int32 ccs_win_pipe_compare (const WIN_PIPE* in_pipe_1,
- const WIN_PIPE* in_pipe_2,
- cc_uint32 *out_equal) {
-
- cc_int32 err = ccNoError;
- int seq = 0;
- *out_equal = FALSE;
-
- if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);}
- if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);}
- if (!out_equal) {err = cci_check_error(ccErrBadParam);}
-
- /* A disconnect doesn't have a tls* with it -- only the uuid. SO only
- compare the uuids.
- */
- if (!err) {
- seq = strcmp( ccs_win_pipe_getUuid(in_pipe_1),
- ccs_win_pipe_getUuid(in_pipe_2) );
- *out_equal = (seq == 0);
- }
-
- return err;
- }
-
-/* ------------------------------------------------------------------------ */
-
-char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe) {
-
- char* result = NULL;
-
- if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
- else {result = in_pipe->uuid;}
-
- return result;
- }
-
-/* ------------------------------------------------------------------------ */
-
-HANDLE ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe) {
-
- HANDLE result = NULL;
-
- if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
- else {result = in_pipe->clientHandle;}
-
- return result;
- }
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#include "assert.h"
+
+#include "ccs_win_pipe.h"
+#include "cci_debugging.h"
+
+/* Ref:
+struct ccs_win_pipe_t {
+ char* uuid;
+ HANDLE clientHandle;
+ }
+ */
+
+/* ------------------------------------------------------------------------ */
+
+struct ccs_win_pipe_t* ccs_win_pipe_new (const char* uuid, const HANDLE h) {
+
+ cc_int32 err = ccNoError;
+ struct ccs_win_pipe_t* out_pipe = NULL;
+ char* uuidCopy = NULL;
+
+ if (!err) {
+ if (!uuid) {err = cci_check_error(ccErrBadParam);}
+ }
+
+ if (!err) {
+ uuidCopy = (char*)malloc(1+strlen(uuid));
+ if (!uuidCopy) {err = cci_check_error(ccErrBadParam);}
+ strcpy(uuidCopy, uuid);
+ }
+
+ if (!err) {
+ out_pipe = (struct ccs_win_pipe_t*)malloc(sizeof(struct ccs_win_pipe_t));
+ if (!out_pipe) {err = cci_check_error(ccErrBadParam);}
+ out_pipe->uuid = uuidCopy;
+ out_pipe->clientHandle = h;
+ }
+
+ cci_debug_printf("0x%X = %s(%s, 0x%X)", out_pipe, __FUNCTION__, uuid, h);
+
+ return out_pipe;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
+ const WIN_PIPE* in_pipe) {
+
+ *out_pipe =
+ ccs_win_pipe_new(
+ ccs_win_pipe_getUuid (in_pipe),
+ ccs_win_pipe_getHandle(in_pipe) );
+
+ return (*out_pipe) ? ccNoError : ccErrBadParam;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_win_pipe_release(const WIN_PIPE* in_pipe) {
+
+ cc_int32 err = ccNoError;
+
+ if (!ccs_win_pipe_valid(in_pipe)) {err = cci_check_error(ccErrBadParam);}
+
+ if (!err) {
+ if (!in_pipe->uuid) free(in_pipe->uuid);
+ if (!in_pipe) free(in_pipe);
+ }
+
+ return err;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe) {
+
+ if (!in_pipe) {
+ cci_check_error(ccErrBadParam);
+ return FALSE;
+ }
+
+ if (!in_pipe->uuid) {
+ cci_check_error(ccErrBadParam);
+ return FALSE;
+ }
+
+ return TRUE;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+cc_int32 ccs_win_pipe_compare (const WIN_PIPE* in_pipe_1,
+ const WIN_PIPE* in_pipe_2,
+ cc_uint32 *out_equal) {
+
+ cc_int32 err = ccNoError;
+ int seq = 0;
+ *out_equal = FALSE;
+
+ if (!ccs_win_pipe_valid(in_pipe_1)) {err = cci_check_error(ccErrBadParam);}
+ if (!ccs_win_pipe_valid(in_pipe_2)) {err = cci_check_error(ccErrBadParam);}
+ if (!out_equal) {err = cci_check_error(ccErrBadParam);}
+
+ /* A disconnect doesn't have a tls* with it -- only the uuid. SO only
+ compare the uuids.
+ */
+ if (!err) {
+ seq = strcmp( ccs_win_pipe_getUuid(in_pipe_1),
+ ccs_win_pipe_getUuid(in_pipe_2) );
+ *out_equal = (seq == 0);
+ }
+
+ return err;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe) {
+
+ char* result = NULL;
+
+ if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
+ else {result = in_pipe->uuid;}
+
+ return result;
+ }
+
+/* ------------------------------------------------------------------------ */
+
+HANDLE ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe) {
+
+ HANDLE result = NULL;
+
+ if (!ccs_win_pipe_valid(in_pipe)) {cci_check_error(ccErrBadParam);}
+ else {result = in_pipe->clientHandle;}
+
+ return result;
+ }
diff --git a/src/ccapi/server/win/ccs_win_pipe.h b/src/ccapi/server/win/ccs_win_pipe.h
index afabe12..3600d12 100644
--- a/src/ccapi/server/win/ccs_win_pipe.h
+++ b/src/ccapi/server/win/ccs_win_pipe.h
@@ -1,69 +1,69 @@
-/*
- * $Header$
- *
- * Copyright 2008 Massachusetts Institute of Technology.
- * All Rights Reserved.
- *
- * Export of this software from the United States of America may
- * require a specific license from the United States Government.
- * It is the responsibility of any person or organization contemplating
- * export to obtain such a license before exporting.
- *
- * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
- * distribute this software and its documentation for any purpose and
- * without fee is hereby granted, provided that the above copyright
- * notice appear in all copies and that both that copyright notice and
- * this permission notice appear in supporting documentation, and that
- * the name of M.I.T. not be used in advertising or publicity pertaining
- * to distribution of the software without specific, written prior
- * permission. Furthermore if you modify this software you must label
- * your software as modified software and not distribute it in such a
- * fashion that it might be confused with the original M.I.T. software.
- * M.I.T. makes no representations about the suitability of
- * this software for any purpose. It is provided "as is" without express
- * or implied warranty.
- */
-
-#ifndef _ccs_win_pipe_h_
-#define _ccs_win_pipe_h_
-
-#include "windows.h"
-
-#include "CredentialsCache.h"
-
-/* ------------------------------------------------------------------------ */
-
-/* On Windows, a pipe is a struct containing a UUID and a handle. Both the
- UUID and handle are supplied by the client.
-
- The UUID is used to build the client's reply endpoint.
-
- The handle is to the requesting client thread's thread local storage struct,
- so that the client's one and only reply handler can put reply data where
- the requesting thread will be able to see it.
- */
-
-struct ccs_win_pipe_t {
- char* uuid;
- HANDLE clientHandle;
- };
-
-typedef struct ccs_win_pipe_t WIN_PIPE;
-
-struct ccs_win_pipe_t* ccs_win_pipe_new(const char* uuid, const HANDLE h);
-
-cc_int32 ccs_win_pipe_release (const WIN_PIPE* io_pipe);
-
-cc_int32 ccs_win_pipe_compare (const WIN_PIPE* win_pipe_1,
- const WIN_PIPE* win_pipe_2,
- cc_uint32 *out_equal);
-
-cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
- const WIN_PIPE* in_pipe);
-
-cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe);
-
-char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe);
-HANDLE ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe);
-
+/*
+ * $Header$
+ *
+ * Copyright 2008 Massachusetts Institute of Technology.
+ * All Rights Reserved.
+ *
+ * Export of this software from the United States of America may
+ * require a specific license from the United States Government.
+ * It is the responsibility of any person or organization contemplating
+ * export to obtain such a license before exporting.
+ *
+ * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
+ * distribute this software and its documentation for any purpose and
+ * without fee is hereby granted, provided that the above copyright
+ * notice appear in all copies and that both that copyright notice and
+ * this permission notice appear in supporting documentation, and that
+ * the name of M.I.T. not be used in advertising or publicity pertaining
+ * to distribution of the software without specific, written prior
+ * permission. Furthermore if you modify this software you must label
+ * your software as modified software and not distribute it in such a
+ * fashion that it might be confused with the original M.I.T. software.
+ * M.I.T. makes no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without express
+ * or implied warranty.
+ */
+
+#ifndef _ccs_win_pipe_h_
+#define _ccs_win_pipe_h_
+
+#include "windows.h"
+
+#include "CredentialsCache.h"
+
+/* ------------------------------------------------------------------------ */
+
+/* On Windows, a pipe is a struct containing a UUID and a handle. Both the
+ UUID and handle are supplied by the client.
+
+ The UUID is used to build the client's reply endpoint.
+
+ The handle is to the requesting client thread's thread local storage struct,
+ so that the client's one and only reply handler can put reply data where
+ the requesting thread will be able to see it.
+ */
+
+struct ccs_win_pipe_t {
+ char* uuid;
+ HANDLE clientHandle;
+ };
+
+typedef struct ccs_win_pipe_t WIN_PIPE;
+
+struct ccs_win_pipe_t* ccs_win_pipe_new(const char* uuid, const HANDLE h);
+
+cc_int32 ccs_win_pipe_release (const WIN_PIPE* io_pipe);
+
+cc_int32 ccs_win_pipe_compare (const WIN_PIPE* win_pipe_1,
+ const WIN_PIPE* win_pipe_2,
+ cc_uint32 *out_equal);
+
+cc_int32 ccs_win_pipe_copy (WIN_PIPE** out_pipe,
+ const WIN_PIPE* in_pipe);
+
+cc_int32 ccs_win_pipe_valid (const WIN_PIPE* in_pipe);
+
+char* ccs_win_pipe_getUuid (const WIN_PIPE* in_pipe);
+HANDLE ccs_win_pipe_getHandle (const WIN_PIPE* in_pipe);
+
#endif // _ccs_win_pipe_h_ \ No newline at end of file
diff --git a/src/ccapi/server/win/workitem.h b/src/ccapi/server/win/workitem.h
index a9d1c0e..df1d779 100644
--- a/src/ccapi/server/win/workitem.h
+++ b/src/ccapi/server/win/workitem.h
@@ -1,48 +1,48 @@
-#ifndef __WorkItem
-#define __WorkItem
-
-#include <list>
-#include "windows.h"
-
-extern "C" {
- #include "cci_stream.h"
- #include "ccs_pipe.h"
- }
-
-class WorkItem {
-private:
- cci_stream_t _buf;
- WIN_PIPE* _pipe;
- const long _rpcmsg;
- const long _sst;
-public:
- WorkItem( cci_stream_t buf,
- WIN_PIPE* pipe,
- const long type,
- const long serverStartTime);
- WorkItem( const WorkItem&);
- WorkItem();
- ~WorkItem();
-
- const cci_stream_t payload() const {return _buf;}
- const cci_stream_t take_payload();
- WIN_PIPE* take_pipe();
- WIN_PIPE* pipe() const {return _pipe;}
- const long type() const {return _rpcmsg;}
- const long sst() const {return _sst;}
- char* print(char* buf);
- };
-
-class WorkList {
-private:
- std::list <WorkItem*> wl;
- CRITICAL_SECTION cs;
-public:
- WorkList();
- ~WorkList();
- int add(WorkItem*);
- int remove(WorkItem**);
- bool isEmpty() {return wl.empty();}
- };
-
+#ifndef __WorkItem
+#define __WorkItem
+
+#include <list>
+#include "windows.h"
+
+extern "C" {
+ #include "cci_stream.h"
+ #include "ccs_pipe.h"
+ }
+
+class WorkItem {
+private:
+ cci_stream_t _buf;
+ WIN_PIPE* _pipe;
+ const long _rpcmsg;
+ const long _sst;
+public:
+ WorkItem( cci_stream_t buf,
+ WIN_PIPE* pipe,
+ const long type,
+ const long serverStartTime);
+ WorkItem( const WorkItem&);
+ WorkItem();
+ ~WorkItem();
+
+ const cci_stream_t payload() const {return _buf;}
+ const cci_stream_t take_payload();
+ WIN_PIPE* take_pipe();
+ WIN_PIPE* pipe() const {return _pipe;}
+ const long type() const {return _rpcmsg;}
+ const long sst() const {return _sst;}
+ char* print(char* buf);
+ };
+
+class WorkList {
+private:
+ std::list <WorkItem*> wl;
+ CRITICAL_SECTION cs;
+public:
+ WorkList();
+ ~WorkList();
+ int add(WorkItem*);
+ int remove(WorkItem**);
+ bool isEmpty() {return wl.empty();}
+ };
+
#endif // __WorkItem \ No newline at end of file
diff --git a/src/ccapi/test/Makefile.w32 b/src/ccapi/test/Makefile.w32
index c6e1c53..8c3da95 100644
--- a/src/ccapi/test/Makefile.w32
+++ b/src/ccapi/test/Makefile.w32
@@ -1,75 +1,75 @@
-# . is ccapi/test.
-CO = ..\common
-COWIN = $(CO)\win
-LIBDIR = ..\lib
-LIBWIN = $(LIBDIR)\win
-SRV = ..\server
-SRVWIN = ..\server\win
-
-!include <Win32.Mak>
-
-INC = -I..\..\include -I..\..\util\et -I$(CO) -I$(COWIN) -I$(LIBDIR) -I$(LIBWIN)
-
-!if "$(CPU)" == "i386"
-cflags = $(cflags) /EHsc /MTd -D_CRTAPI1=_cdecl -D_CRTAPI2=_cdecl -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 \
-$(INC)
-!else
-cflags = $(cflags) /W3 -D_CRTAPI1= -D_CRTAPI2= $(INC)
-!endif
-LIBS = $(LIBWIN)\ccapi.lib
-
-DSTROOT = .
-SRC = $(DSTROOT)
-#OBJDIR = $(DSTROOT)\obj
-OBJDIR = .
-OBJEXT = obj
-TESTDIR = $(DSTROOT)\tests
-TESTEXT = exe
-DSTDIR = $(DSTROOT)\ccapi_tests
-
-PINGOBJS = pingtest.obj
-SIMPLEOBJS = simple_lock_test.obj
-
-comobjs = cci_debugging.obj cci_stream.obj
-cowobjs = cci_os_debugging.obj
-libobjs = ccs_request_c.obj
-
-#all: build-base simple_lock_test pingtest
-all: build-base pingtest
-
-# compile base files used by all tests
-build-base: $(comobjs) $(libobjs) $(srvobjs)
- @echo "Base objects built."
-
-# rule to compile src files
-.c.obj:
- $(cc) $(cdebug) $(cflags) /Fo$(OBJDIR)\$(*B).$(OBJEXT) $(SRC)\$(*B).c
-
-$(comobjs) : $(CO)\$(*B).c
- $(cc) $(cdebug) $(cflags) $(CO)\$(*B).c
-
-$(cowobjs) : $(COWIN)\$(*B).c
- $(cc) $(cdebug) $(cflags) $(COWIN)\$(*B).c
-
-$(libobjs) : $(LIBWIN)\$(*B).c
- $(cc) $(cdebug) $(cflags) $(LIBWIN)\$(*B).c
-
-#$(srvobjs) : $(SRVWIN)\$*.c
-# $(cc) $(cdebug) $(cflags) $(SRVWIN)\$*.c
-
-simple_lock_test: simple_lock_test.obj $(OBJS)
- @echo R3+ Build $(*B) in $(TESTDIR)
- $(cc) $(cdebug) $(cflags) $(*B).c
- $(link) $(linkdebug) $(conflags) -out:$(TESTDIR)\$(*B).exe $(*B).obj \
- $(LIBS) rpcrt4.lib
- @echo R3- Built $(*B) in $(TESTDIR)
-
-pingtest: pingtest.obj
- @echo R4+ Build $(*B) in $(TESTDIR)
- $(cc) $(cdebug) $(cflags) $(*B).c
- $(link) $(linkdebug) $(conflags) -out:$(*B).exe $(PINGOBJS) $(libobjs) $(srvobjs) \
- $(LIBS) rpcrt4.lib
- @echo R4- Built $(*B) in $(TESTDIR)
-
-clean:
+# . is ccapi/test.
+CO = ..\common
+COWIN = $(CO)\win
+LIBDIR = ..\lib
+LIBWIN = $(LIBDIR)\win
+SRV = ..\server
+SRVWIN = ..\server\win
+
+!include <Win32.Mak>
+
+INC = -I..\..\include -I..\..\util\et -I$(CO) -I$(COWIN) -I$(LIBDIR) -I$(LIBWIN)
+
+!if "$(CPU)" == "i386"
+cflags = $(cflags) /EHsc /MTd -D_CRTAPI1=_cdecl -D_CRTAPI2=_cdecl -DWINVER=0x0501 -D_WIN32_WINNT=0x0501 \
+$(INC)
+!else
+cflags = $(cflags) /W3 -D_CRTAPI1= -D_CRTAPI2= $(INC)
+!endif
+LIBS = $(LIBWIN)\ccapi.lib
+
+DSTROOT = .
+SRC = $(DSTROOT)
+#OBJDIR = $(DSTROOT)\obj
+OBJDIR = .
+OBJEXT = obj
+TESTDIR = $(DSTROOT)\tests
+TESTEXT = exe
+DSTDIR = $(DSTROOT)\ccapi_tests
+
+PINGOBJS = pingtest.obj
+SIMPLEOBJS = simple_lock_test.obj
+
+comobjs = cci_debugging.obj cci_stream.obj
+cowobjs = cci_os_debugging.obj
+libobjs = ccs_request_c.obj
+
+#all: build-base simple_lock_test pingtest
+all: build-base pingtest
+
+# compile base files used by all tests
+build-base: $(comobjs) $(libobjs) $(srvobjs)
+ @echo "Base objects built."
+
+# rule to compile src files
+.c.obj:
+ $(cc) $(cdebug) $(cflags) /Fo$(OBJDIR)\$(*B).$(OBJEXT) $(SRC)\$(*B).c
+
+$(comobjs) : $(CO)\$(*B).c
+ $(cc) $(cdebug) $(cflags) $(CO)\$(*B).c
+
+$(cowobjs) : $(COWIN)\$(*B).c
+ $(cc) $(cdebug) $(cflags) $(COWIN)\$(*B).c
+
+$(libobjs) : $(LIBWIN)\$(*B).c
+ $(cc) $(cdebug) $(cflags) $(LIBWIN)\$(*B).c
+
+#$(srvobjs) : $(SRVWIN)\$*.c
+# $(cc) $(cdebug) $(cflags) $(SRVWIN)\$*.c
+
+simple_lock_test: simple_lock_test.obj $(OBJS)
+ @echo R3+ Build $(*B) in $(TESTDIR)
+ $(cc) $(cdebug) $(cflags) $(*B).c
+ $(link) $(linkdebug) $(conflags) -out:$(TESTDIR)\$(*B).exe $(*B).obj \
+ $(LIBS) rpcrt4.lib
+ @echo R3- Built $(*B) in $(TESTDIR)
+
+pingtest: pingtest.obj
+ @echo R4+ Build $(*B) in $(TESTDIR)
+ $(cc) $(cdebug) $(cflags) $(*B).c
+ $(link) $(linkdebug) $(conflags) -out:$(*B).exe $(PINGOBJS) $(libobjs) $(srvobjs) \
+ $(LIBS) rpcrt4.lib
+ @echo R4- Built $(*B) in $(TESTDIR)
+
+clean:
DEL *.$(OBJEXT) \ No newline at end of file
diff --git a/src/ccapi/test/pingtest.c b/src/ccapi/test/pingtest.c
index 9927725..a249911 100644
--- a/src/ccapi/test/pingtest.c
+++ b/src/ccapi/test/pingtest.c
@@ -1,108 +1,108 @@
-// pingtest.c
-//
-// Test RPC to server, with PING message, which exists for no other purpose than this test.
-
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "cci_debugging.h"
-#include "CredentialsCache.h"
-#include "cci_stream.h"
-#include "win-utils.h"
-
-#include "ccs_request.h"
-#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
-
-
-extern cc_int32 cci_os_ipc_thread_init (void);
-extern cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
- cci_stream_t in_request_stream,
- cc_int32 in_msg,
- cci_stream_t* out_reply_stream);
-
-RPC_STATUS send_test(char* endpoint) {
- unsigned char* pszNetworkAddress = NULL;
- unsigned char* pszOptions = NULL;
- unsigned char* pszStringBinding = NULL;
- unsigned char* pszUuid = NULL;
- RPC_STATUS status;
-
- status = RpcStringBindingCompose(pszUuid,
- (RPC_CSTR)"ncalrpc",
- pszNetworkAddress,
- (unsigned char*)endpoint,
- pszOptions,
- &pszStringBinding);
- cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding);
- if (status) {return cci_check_error(status);}
-
- /* Set the binding handle that will be used to bind to the RPC server [the 'client']. */
- status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE);
- if (status) {return cci_check_error(status);}
-
- status = RpcStringFree(&pszStringBinding); // Temp var no longer needed.
-
- if (!status) {
- RpcTryExcept {
- cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__);
- status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!");
- cci_debug_printf(" ccs_authenticate returned %d", status);
- }
- RpcExcept(1) {
- status = cci_check_error(RpcExceptionCode());
- }
- RpcEndExcept
- }
-
- cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE));
-
- return (status);
- }
-
-int main( int argc, char *argv[]) {
- cc_int32 err = 0;
- cc_context_t context = NULL;
- cci_stream_t send_stream = NULL;
- cci_stream_t reply_stream = NULL;
- char* message = "Hello, RPC!";
-
-
-// send_test("krbcc.229026.0.ep");
-
-#if 0
- err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
-#endif
-
- if (!err) {
- err = cci_os_ipc_thread_init();
- }
- if (!err) {
- err = cci_stream_new (&send_stream);
- err = cci_stream_write(send_stream, message, 1+strlen(message));
- }
-
- if (!err) {
- err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);
- }
- Sleep(10*1000);
- cci_debug_printf("Try finishing async call.");
-
- Sleep(INFINITE);
- cci_debug_printf("main: return. err == %d", err);
-
- return 0;
- }
-
-
-
-/*********************************************************************/
-/* MIDL allocate and free */
-/*********************************************************************/
-
-void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
- return(malloc(len));
- }
-
-void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
- free(ptr);
- }
+// pingtest.c
+//
+// Test RPC to server, with PING message, which exists for no other purpose than this test.
+
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "cci_debugging.h"
+#include "CredentialsCache.h"
+#include "cci_stream.h"
+#include "win-utils.h"
+
+#include "ccs_request.h"
+#define CLIENT_REQUEST_RPC_HANDLE ccs_request_IfHandle
+
+
+extern cc_int32 cci_os_ipc_thread_init (void);
+extern cc_int32 cci_os_ipc_msg( cc_int32 in_launch_server,
+ cci_stream_t in_request_stream,
+ cc_int32 in_msg,
+ cci_stream_t* out_reply_stream);
+
+RPC_STATUS send_test(char* endpoint) {
+ unsigned char* pszNetworkAddress = NULL;
+ unsigned char* pszOptions = NULL;
+ unsigned char* pszStringBinding = NULL;
+ unsigned char* pszUuid = NULL;
+ RPC_STATUS status;
+
+ status = RpcStringBindingCompose(pszUuid,
+ (RPC_CSTR)"ncalrpc",
+ pszNetworkAddress,
+ (unsigned char*)endpoint,
+ pszOptions,
+ &pszStringBinding);
+ cci_debug_printf("%s pszStringBinding = %s", __FUNCTION__, pszStringBinding);
+ if (status) {return cci_check_error(status);}
+
+ /* Set the binding handle that will be used to bind to the RPC server [the 'client']. */
+ status = RpcBindingFromStringBinding(pszStringBinding, &CLIENT_REQUEST_RPC_HANDLE);
+ if (status) {return cci_check_error(status);}
+
+ status = RpcStringFree(&pszStringBinding); // Temp var no longer needed.
+
+ if (!status) {
+ RpcTryExcept {
+ cci_debug_printf("%s calling remote procedure 'ccs_authenticate'", __FUNCTION__);
+ status = ccs_authenticate((CC_CHAR*)"DLLMAIN TEST!");
+ cci_debug_printf(" ccs_authenticate returned %d", status);
+ }
+ RpcExcept(1) {
+ status = cci_check_error(RpcExceptionCode());
+ }
+ RpcEndExcept
+ }
+
+ cci_check_error(RpcBindingFree(&CLIENT_REQUEST_RPC_HANDLE));
+
+ return (status);
+ }
+
+int main( int argc, char *argv[]) {
+ cc_int32 err = 0;
+ cc_context_t context = NULL;
+ cci_stream_t send_stream = NULL;
+ cci_stream_t reply_stream = NULL;
+ char* message = "Hello, RPC!";
+
+
+// send_test("krbcc.229026.0.ep");
+
+#if 0
+ err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
+#endif
+
+ if (!err) {
+ err = cci_os_ipc_thread_init();
+ }
+ if (!err) {
+ err = cci_stream_new (&send_stream);
+ err = cci_stream_write(send_stream, message, 1+strlen(message));
+ }
+
+ if (!err) {
+ err = cci_os_ipc_msg(TRUE, send_stream, CCMSG_PING, &reply_stream);
+ }
+ Sleep(10*1000);
+ cci_debug_printf("Try finishing async call.");
+
+ Sleep(INFINITE);
+ cci_debug_printf("main: return. err == %d", err);
+
+ return 0;
+ }
+
+
+
+/*********************************************************************/
+/* MIDL allocate and free */
+/*********************************************************************/
+
+void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len) {
+ return(malloc(len));
+ }
+
+void __RPC_USER midl_user_free(void __RPC_FAR * ptr) {
+ free(ptr);
+ }
diff --git a/src/ccapi/test/simple_lock_test.c b/src/ccapi/test/simple_lock_test.c
index 254663c..d51a586 100644
--- a/src/ccapi/test/simple_lock_test.c
+++ b/src/ccapi/test/simple_lock_test.c
@@ -1,84 +1,84 @@
-/*
- simple_lock_test.c
-
- Initializes two contexts in two different threads and tries to get read locks on both at the same time.
- Hangs at line 24.
-*/
-#include <stdio.h>
-#include <stdarg.h>
-
-#include "cci_debugging.h"
-
-#ifdef TARGET_OS_MAC
-#include <stdlib.h>
-#include <Kerberos/CredentialsCache.h>
-#else
-#include "CredentialsCache.h"
-#endif
-
-
-void * other_thread () {
- cc_int32 err;
- cc_context_t context = NULL;
-
- err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
-
- cci_debug_printf("thread: attempting lock. may hang. err == %d", err);
-
- if (!err) {
- // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately
- err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
- }
-
- if (context) {
- cc_context_unlock(context);
- cc_context_release(context);
- context = NULL;
- }
- cci_debug_printf("thread: return. err == %d", err);
- }
-
-
-int main (int argc, char *argv[]) {
- cc_int32 err;
- int status;
- cc_context_t context = NULL;
-
-#ifdef TARGET_OS_MAC
- pthread_t thread_id;
-#endif
-
- err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
- if (!err) {
- err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
- }
-
- cci_debug_printf("main: initialized and read locked context. err == %d", err);
-
-#ifdef TARGET_OS_MAC
- status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);
- if (status != 0) {
- cci_debug_printf("Create error!");
- exit(-1);
- }
-
- pthread_join(thread_id, NULL);
-#else
-
-#endif
-
- cci_debug_printf("main: unlocking and releasing context. err == %d", err);
-
- if (context) {
- cci_debug_printf("main: calling cc_context_unlock");
- cc_context_unlock(context);
- cci_debug_printf("main: calling cc_context_release");
- cc_context_release(context);
- context = NULL;
- }
-
- cci_debug_printf("main: return. err == %d", err);
-
- UNREFERENCED_PARAMETER(status); // no whining!
- return 0;
+/*
+ simple_lock_test.c
+
+ Initializes two contexts in two different threads and tries to get read locks on both at the same time.
+ Hangs at line 24.
+*/
+#include <stdio.h>
+#include <stdarg.h>
+
+#include "cci_debugging.h"
+
+#ifdef TARGET_OS_MAC
+#include <stdlib.h>
+#include <Kerberos/CredentialsCache.h>
+#else
+#include "CredentialsCache.h"
+#endif
+
+
+void * other_thread () {
+ cc_int32 err;
+ cc_context_t context = NULL;
+
+ err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
+
+ cci_debug_printf("thread: attempting lock. may hang. err == %d", err);
+
+ if (!err) {
+ // hangs with cc_lock_read which should succeed immediately, but does not hang with write, upgrade, and downgrade, which fail immediately
+ err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
+ }
+
+ if (context) {
+ cc_context_unlock(context);
+ cc_context_release(context);
+ context = NULL;
+ }
+ cci_debug_printf("thread: return. err == %d", err);
+ }
+
+
+int main (int argc, char *argv[]) {
+ cc_int32 err;
+ int status;
+ cc_context_t context = NULL;
+
+#ifdef TARGET_OS_MAC
+ pthread_t thread_id;
+#endif
+
+ err = cc_initialize(&context, ccapi_version_7, NULL, NULL);
+ if (!err) {
+ err = cc_context_lock(context, cc_lock_read, cc_lock_noblock);
+ }
+
+ cci_debug_printf("main: initialized and read locked context. err == %d", err);
+
+#ifdef TARGET_OS_MAC
+ status = pthread_create (&thread_id, NULL, (void *) other_thread, NULL);
+ if (status != 0) {
+ cci_debug_printf("Create error!");
+ exit(-1);
+ }
+
+ pthread_join(thread_id, NULL);
+#else
+
+#endif
+
+ cci_debug_printf("main: unlocking and releasing context. err == %d", err);
+
+ if (context) {
+ cci_debug_printf("main: calling cc_context_unlock");
+ cc_context_unlock(context);
+ cci_debug_printf("main: calling cc_context_release");
+ cc_context_release(context);
+ context = NULL;
+ }
+
+ cci_debug_printf("main: return. err == %d", err);
+
+ UNREFERENCED_PARAMETER(status); // no whining!
+ return 0;
} \ No newline at end of file
diff --git a/src/plugins/kdb/db2/libdb2/btree/bt_debug.c b/src/plugins/kdb/db2/libdb2/btree/bt_debug.c
index d36256b..b302ca6 100644
--- a/src/plugins/kdb/db2/libdb2/btree/bt_debug.c
+++ b/src/plugins/kdb/db2/libdb2/btree/bt_debug.c
@@ -257,7 +257,8 @@ __bt_dpage(dbp, h)
*(db_pgno_t *)bl->bytes,
*(u_int32_t *)(bl->bytes + sizeof(db_pgno_t)));
else if (bl->ksize)
- (void)fprintf(tracefp, "%s/", bl->bytes);
+ (void)fprintf(tracefp, "%.*s/",
+ (int)bl->ksize, bl->bytes);
if (bl->flags & P_BIGDATA)
(void)fprintf(tracefp,
"big data page %lu size %u",
diff --git a/src/plugins/kdb/db2/libdb2/btree/bt_split.c b/src/plugins/kdb/db2/libdb2/btree/bt_split.c
index 62ec823..9b2708e 100644
--- a/src/plugins/kdb/db2/libdb2/btree/bt_split.c
+++ b/src/plugins/kdb/db2/libdb2/btree/bt_split.c
@@ -727,7 +727,7 @@ bt_psplit(t, h, l, r, pskip, ilen)
* the right page.
*/
if (skip <= off) {
- skip = 0;
+ skip = (indx_t)-1;
rval = l;
} else {
rval = r;
@@ -737,7 +737,7 @@ bt_psplit(t, h, l, r, pskip, ilen)
for (off = 0; nxt < top; ++off) {
if (skip == nxt) {
++off;
- skip = 0;
+ skip = (indx_t)-1;
}
switch (h->flags & P_TYPE) {
case P_BINTERNAL:
diff --git a/src/plugins/kdb/db2/libdb2/mpool/mpool.c b/src/plugins/kdb/db2/libdb2/mpool/mpool.c
index 56f2749..3b0be3f 100644
--- a/src/plugins/kdb/db2/libdb2/mpool/mpool.c
+++ b/src/plugins/kdb/db2/libdb2/mpool/mpool.c
@@ -377,7 +377,7 @@ mpool_bkt(mp)
head = &mp->hqh[HASHKEY(bp->pgno)];
CIRCLEQ_REMOVE(head, bp, hq);
CIRCLEQ_REMOVE(&mp->lqh, bp, q);
-#ifdef DEBUG
+#if defined(DEBUG) && !defined(DEBUG_IDX0SPLIT)
{ void *spage;
spage = bp->page;
memset(bp, 0xff, sizeof(BKT) + mp->pagesize);
diff --git a/src/plugins/kdb/db2/libdb2/test/run.test b/src/plugins/kdb/db2/libdb2/test/run.test
index 48c3a63..d029862 100644
--- a/src/plugins/kdb/db2/libdb2/test/run.test
+++ b/src/plugins/kdb/db2/libdb2/test/run.test
@@ -34,7 +34,7 @@ main()
bindir=/bin/.
if [ $# -eq 0 ]; then
- for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do
+ for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20 40 41; do
test$t
done
else
@@ -45,7 +45,7 @@ main()
[0-9]*)
test$1;;
btree)
- for t in 1 2 3 7 8 9 10 12 13; do
+ for t in 1 2 3 7 8 9 10 12 13 40 41; do
test$t
done;;
hash)
@@ -743,4 +743,162 @@ bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed"
done
}
+# Test for a weird page split condition where an insertion into index
+# 0 of a page that would cause the new item to be the only item on the
+# left page results in index 0 of the right page being erroneously
+# skipped; this only happens with one particular key+data length for
+# each page size.
+test40 () {
+ echo "Test 40: btree: page split on index 0"
+ e=:
+ for psize in 512 1024 2048 4096 8192; do
+ echo " page size $psize"
+ kdsizes=`awk 'BEGIN {
+ psize = '$psize'; hsize = int(psize/2);
+ for (kdsize = hsize-40; kdsize <= hsize; kdsize++) {
+ print kdsize;
+ }
+ }' /dev/null`
+
+ # Use a series of keylen+datalen values in the right
+ # neighborhood to find the one that triggers the bug.
+ # We could compute the exact size that triggers the
+ # bug but this additional fuzz may be useful.
+
+ # Insert keys in reverse order to maximize the chances
+ # for a split on index 0.
+
+ for kdsize in $kdsizes; do
+ awk 'BEGIN {
+ kdsize = '$kdsize';
+ for (i = 8; i-- > 0; ) {
+ s = sprintf("a%03d:%09d", i, kdsize);
+ for (j = 0; j < kdsize-20; j++) {
+ s = s "x";
+ }
+ printf("p\nka%03d\nd%s\n", i, s);
+ }
+ print "o";
+ }' /dev/null > $TMP2
+ sed -n 's/^d//p' $TMP2 | sort > $TMP1
+ $PROG -o $TMP3 -i psize=$psize btree $TMP2
+ if (cmp -s $TMP1 $TMP3); then :
+ else
+ echo "test40: btree: page size $psize, \
+keylen+datalen=$kdsize failed"
+ e='exit 1'
+ fi
+ done
+ done
+ $e
+}
+
+# Extremely tricky test attempting to replicate some unusual database
+# corruption seen in the field: pieces of the database becoming
+# inaccessible to random access, sequential access, or both. The
+# hypothesis is that at least some of these are triggered by the bug
+# in page splits on index 0 with a particular exact keylen+datalen.
+# (See Test 40.) For psize=4096, this size is exactly 2024.
+
+# The order of operations here relies on very specific knowledge of
+# the internals of the btree access method in order to place records
+# at specific offsets in a page and to create certain keys on internal
+# pages. The to-be-split page immediately prior to the bug-triggering
+# split has the following properties:
+#
+# * is not the leftmost leaf page
+# * key on the parent page is compares less than the key of the item
+# on index 0
+# * triggering record's key also compares greater than the key on the
+# parent page
+
+# Additionally, we prime the mpool LRU chain so that the head page on
+# the chain has the following properties:
+#
+# * record at index 0 is located where it will not get overwritten by
+# items written to the right-hand page during the split
+# * key of the record at index 0 compares less than the key of the
+# bug-triggering record
+
+# If the page-split bug exists, this test appears to create a database
+# where some records are inaccessible to a search, but still remain in
+# the file and are accessible by sequential traversal. At least one
+# record gets duplicated out of sequence.
+
+test41 () {
+ echo "Test 41: btree: no unsearchables due to page split on index 0"
+ # list of individual retrievals in a variable for easy reuse
+ list=`(for i in a b c d; do
+ for j in 990 998 999; do
+ echo g ${i}${j} 1024
+ done
+ done;
+ echo g y997 2014
+ for i in y z; do
+ for j in 998 999; do
+ echo g ${i}${j} 1024
+ done
+ done)`
+ # Exact number for trigger condition accounts for newlines
+ # retained by dbtest with -ofile but not without; we use
+ # -ofile, so count newlines. keylen=5,datalen=5+2014 for
+ # psize=4096 here.
+ (cat - <<EOF
+p z999 1024
+p z998 1024
+p y999 1024
+p y990 1024
+p d999 1024
+p d990 1024
+p c999 1024
+p c990 1024
+p b999 1024
+p b990 1024
+p a999 1024
+p a990 1024
+p y998 1024
+r y990
+p d998 1024
+p d990 1024
+p c998 1024
+p c990 1024
+p b998 1024
+p b990 1024
+p a998 1024
+p a990 1024
+p y997 2014
+S
+o
+EOF
+ echo "$list") |
+ # awk script input:
+ # {p|g|r} key [datasize]
+ awk '/^[pgr]/{
+ printf("%s\nk%s\n", $1, $2);
+ }
+ /^p/{
+ s = $2;
+ for (i = 0; i < $3; i++) {
+ s = s "x";
+ }
+ printf("d%s\n", s);
+ }
+ !/^[pgr]/{
+ print $0;
+ }' > $TMP2
+ (echo "$list"; echo "$list") | awk '{
+ s = $2;
+ for (i = 0; i < $3; i++) {
+ s = s "x";
+ }
+ print s;
+ }' > $TMP1
+ $PROG -o $TMP3 -i psize=4096 btree $TMP2
+ if (cmp -s $TMP1 $TMP3); then :
+ else
+ echo "test41: btree: failed"
+ exit 1
+ fi
+}
+
main $*
diff --git a/src/util/find-missing-eol-prop b/src/util/find-missing-eol-prop
new file mode 100755
index 0000000..6cdad65
--- /dev/null
+++ b/src/util/find-missing-eol-prop
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+find . \( \( -name .svn -o -name .\#\* -o -name \*~ -o -name \#\* -o -name autom4te.cache \) -prune \) -o \( -type f -print \) | \
+while read name; do
+ if test "`svn pg svn:eol-style $name`" == ""; then
+ echo svn:eol-style missing on $name
+ fi
+done
diff --git a/src/util/fix-eol-prop b/src/util/fix-eol-prop
new file mode 100755
index 0000000..346568c
--- /dev/null
+++ b/src/util/fix-eol-prop
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+find . \( -name \*.c -o -name \*.h -o -name \*.hin -o -name \*.in \
+ -o -name \*.txt -o -name Makefile.in -o -name \*.sh -o -name \*.exp \
+ -o -name \*.cxx -o -name \*.hxx -o -name \*.html -o -name \*.def \
+ -o -name \*.idl -o -name \*.Acf -o -name \*.Idl \
+ -o -name Makefile.w32 \
+ \) -print | \
+while read name; do
+ if test "`svn pg svn:eol-style $name`" == ""; then
+ svn ps svn:eol-style native $name
+ fi
+done
diff --git a/src/windows/build/bkw-automation.html b/src/windows/build/bkw-automation.html
index 5e21ba5..9592f49 100644
--- a/src/windows/build/bkw-automation.html
+++ b/src/windows/build/bkw-automation.html
@@ -6,7 +6,8 @@
<META http-equiv="Expires" content="-1">
<LINK href="css/main-action.css" type="text/css" rel="stylesheet">
<LINK href="css\main-action(1).css" type="text/css" rel="stylesheet">
- <META content="MSHTML 6.00.2900.3059" name="GENERATOR"></HEAD>
+ <META content="MSHTML 6.00.2900.3059" name="GENERATOR">
+</HEAD>
<BODY>
<DIV style="MARGIN-LEFT: 10px; MARGIN-RIGHT: 10px" align="left">
<DIV class="wiki-content" style="MARGIN-TOP: 5px; MARGIN-BOTTOM: 5px" align="left">The
@@ -80,8 +81,8 @@
<P>perl must be installed so that .pl files are automatically executed with perl.
The ActivePerl installation will do this for you.</P>
<P>In the INCLUDE path, the Microsoft Platform SDK must come before the Microsoft
- Visual C++ include files. Using a Platform SDK Build Environment window will
- set this up the right way.&nbsp;</P>
+ Visual C++ include files. In the PATH path, the Platform SDK bin area must come before the Visual Studio VC\bin area. Using a Platform SDK Build Environment window will
+ set this up the right way.&nbsp; Make sure to use a Platform SDK Windows XP Build Environment shell. </P>
<P>If you make your path modifications permanent via Control Panel / System /
Advanced / Environment Variables:&nbsp; If you use a Platform SDK Build
Environment window, it appears that you need to put your PATH components in the
@@ -291,7 +292,7 @@ Default is bkw.pl.log. <BR>&nbsp;
will substitute %bldtype% with either dbg or rel, depending on the build
type.&nbsp;<STRONG></P>
</DIV>
- <DIV style="MARGIN-LEFT: 10px; MARGIN-RIGHT: 10px" align="left">
+ <DIV style="MARGIN-LEFT: 10px; MARGIN-RIGHT: 10px" align="left">
<H3>Example</H3>
</STRONG>
<P>Here is&nbsp;a copylist entry.&nbsp; Each segment of the file's path that comes
@@ -299,7 +300,7 @@ Default is bkw.pl.log. <BR>&nbsp;
<P>Release build.&nbsp; Config file:
</P>
<P>
- <TABLE id="Table2" cellSpacing="1" cellPadding="1" border="0">
+ <TABLE id="Table2" cellSpacing="1" cellPadding="1" border="0">
<TR>
<TD colSpan="4"><FONT face="courier">&lt;BKW_Config&gt;</FONT></TD>
</TR>
@@ -313,7 +314,7 @@ Default is bkw.pl.log. <BR>&nbsp;
<TD><FONT face="courier">&lt;src&nbsp;value ="<FONT color="#000099">C:\bkw"</FONT> /&gt;</FONT>
</TD>
</TR>
- </TABLE>
+ </TABLE>
</P>
<P>Copylist comments:</P>
<P><tt>&lt;!-- File from paths are relative to
@@ -349,8 +350,18 @@ Default is bkw.pl.log. <BR>&nbsp;
</H2>
<P><STRONG>Can't clean directory; can't delete file or directory</STRONG><BR>
Make sure a file in the named directory isn't open in another application.</P>
- <P><STRONG>Can't find kerberos.ver</STRONG><BR>
- You skipped the repository step and are trying to build in an empty directory.</P>
- </DIV>
+ <P><STRONG>Can't find kerberos.ver</STRONG><BR>
+ You skipped the repository step and are trying to build in an empty directory.</P>
+ <P><strong>Directories don't exist or can't be created <br>
+ </strong>This can be a symptom of the Platform SDK bin area not being before the Visual Studio bin areas, such that the version of nmake running is version 8.x.<strong> <br>
+ </strong>[This explanation courtesy of Jeff Altman]: <br>
+ nmake V8 appears to favor executables over shell commands. As a result, using 'mkdir' instead of 'md' in Makefiles, as a command for creating directory trees, fails when the Cygwin mkdir.exe is present in the PATH. Changing the</P>
+ <P>MKDIR=mkdir<br>
+ RMDIR=rmdir</P>
+ <P>macros in the Makefiles to</P>
+ <P>MKDIR=md<br>
+ RMDIR=rd</P>
+ <P>should make the shell versions execute in all cases.</P>
+ </DIV>
</BODY>
</HTML>
diff --git a/src/windows/build/bkw.pl b/src/windows/build/bkw.pl
index 9984a33..ee93203 100644
--- a/src/windows/build/bkw.pl
+++ b/src/windows/build/bkw.pl
@@ -316,11 +316,11 @@ sub main {
}
print "Executing $cmdline\n";
- local $argvsize = @ARGV;
+ local $argvsize = @ARGV;
+ local $nmakeargs = "";
if ($argvsize > 0) {
- print "\nArguments for NMAKE: ";
- map {print " $_ "} @ARGV;
- print "\n";
+ map {$nmakeargs .= " $_ "} @ARGV;
+ print "Arguments for NMAKE: $nmakeargs\n";
}
print "Info -- Using unix find in $odr->{unixfind}->{value}\n" if ($verbose);
@@ -519,7 +519,7 @@ sub main {
chdir("$wd\\athena") or die "Fatal -- couldn't chdir to source directory $wd\\athena\n";
print "Info -- chdir to ".`cd`."\n" if ($verbose);
local $dbgswitch = ($odr->{debug}->{def}) ? " " : "NODEBUG=1";
- !system("perl ../scripts/build.pl --softdirs --nolog $buildtarget $dbgswitch BUILD_KFW=1 BUILD_OFFICIAL=1 DEBUG_SYMBOL=1")
+ !system("perl ../scripts/build.pl --softdirs --nolog $buildtarget $dbgswitch BUILD_KFW=1 BUILD_OFFICIAL=1 DEBUG_SYMBOL=1 $nmakeargs")
or die "Fatal -- build $buildtarget failed.";
chdir("$wd") or die "Fatal -- couldn't chdir to $wd.";
diff --git a/src/windows/identity/config/Makefile.w2k b/src/windows/identity/config/Makefile.w2k
index 14c707d..2edc113 100644
--- a/src/windows/identity/config/Makefile.w2k
+++ b/src/windows/identity/config/Makefile.w2k
@@ -160,8 +160,8 @@ _WIN32_WINNT=0x0500
CD=cd
RM=del /q
-MKDIR=mkdir
-RMDIR=rmdir
+MKDIR=md
+RMDIR=rd
ECHO=echo
MAKECMD=nmake /nologo
CP=copy /y
diff --git a/src/windows/identity/config/Makefile.w32 b/src/windows/identity/config/Makefile.w32
index 3b61c66..eda4970 100644
--- a/src/windows/identity/config/Makefile.w32
+++ b/src/windows/identity/config/Makefile.w32
@@ -173,8 +173,8 @@ NODEBUG=1
CD=cd
RM=del /q
-MKDIR=mkdir
-RMDIR=rmdir
+MKDIR=md
+RMDIR=rd
ECHO=echo
MAKECMD=nmake /nologo
CP=copy /y