From 83dbb267be47c59dc08a1df50e74a55abda1ba0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Mon, 1 Feb 2010 22:42:14 +0100 Subject: [PATCH] Implement DisableDataBoxExternally This service is exported as isds_disable_box_accessibility_externaly() function. It's designed for prisons to mark box unaccesible on legal basis restrospectively. --- client/Makefile.am | 4 +- client/common.c | 10 +-- client/common.h | 1 + client/disableaccesibilityexternaly.c | 127 ++++++++++++++++++++++++++++++++++ doc/maintanance_web_services | 15 ++++ src/isds.c | 73 +++++++++++++++++-- src/isds.h | 12 ++++ 7 files changed, 232 insertions(+), 10 deletions(-) create mode 100644 client/disableaccesibilityexternaly.c diff --git a/client/Makefile.am b/client/Makefile.am index 2262197..6da3523 100644 --- a/client/Makefile.am +++ b/client/Makefile.am @@ -6,7 +6,8 @@ AM_CFLAGS +=-I$(LIBDIR) LDADD = $(LIBDIR)/libisds.la -L$(LIBDIR) noinst_PROGRAMS = isdsclient login progressbar getuserboxinfo changepassword \ - changeuser switchcommercial switchaccessibility\ + changeuser switchcommercial switchaccessibility \ + disableaccesibilityexternaly \ sendmultiple getsent getsignedsent \ loadreceivedmessage loadcmssignedsentmessage \ getreceived getsignedreceived \ @@ -24,6 +25,7 @@ changepassword_SOURCES = changepassword.c $(common) changeuser_SOURCES = changeuser.c $(common) switchcommercial_SOURCES = switchcommercial.c $(common) switchaccessibility_SOURCES = switchaccessibility.c $(common) +disableaccesibilityexternaly_SOURCES = disableaccesibilityexternaly.c $(common) sendmultiple_SOURCES = sendmultiple.c $(common) getsent_SOURCES = getsent.c $(common) getsignedsent_SOURCES = getsignedsent.c $(common) diff --git a/client/common.c b/client/common.c index 993babf..93227e0 100644 --- a/client/common.c +++ b/client/common.c @@ -188,9 +188,9 @@ void print_Address(const struct isds_Address *address) { } -void print_BiDate(const struct tm *biDate) { - if (!biDate) printf("NULL\n"); - else printf("%s", asctime(biDate)); +void print_date(const struct tm *date) { + if (!date) printf("NULL\n"); + else printf("%s", asctime(date)); } @@ -219,7 +219,7 @@ void print_DbOwnerInfo(const struct isds_DbOwnerInfo *info) { printf("{\n"); printf("\t\tbiDate = "); - print_BiDate(info->birthInfo->biDate); + print_date(info->birthInfo->biDate); printf("\t\tbiCity = %s\n", info->birthInfo->biCity); printf("\t\tbiCounty = %s\n", info->birthInfo->biCounty); @@ -271,7 +271,7 @@ void print_DbUserInfo(const struct isds_DbUserInfo *info) { print_Address(info->address); printf("\tbiDate = "); - print_BiDate(info->biDate); + print_date(info->biDate); printf("\tic = %s\n", info->ic); printf("\tfirmName = %s\n", info->firmName); diff --git a/client/common.h b/client/common.h index 2e7bc2d..e13e619 100644 --- a/client/common.h +++ b/client/common.h @@ -10,6 +10,7 @@ extern char password[]; void print_bool(const _Bool *boolean); void print_longint(const long int *number); void print_DbState(const long int state); +void print_date(const struct tm *date); void print_DbOwnerInfo(const struct isds_DbOwnerInfo *info); void print_DbUserInfo(const struct isds_DbUserInfo *info); void print_timeval(const struct timeval *time); diff --git a/client/disableaccesibilityexternaly.c b/client/disableaccesibilityexternaly.c new file mode 100644 index 0000000..d2265d8 --- /dev/null +++ b/client/disableaccesibilityexternaly.c @@ -0,0 +1,127 @@ +#define _XOPEN_SOURCE 500 +#include +#include +#include +#include +#include +#include +#include "common.h" + + +int main(int argc, char **argv) { + struct isds_ctx *ctx = NULL; + isds_error err; + struct isds_DbOwnerInfo *db_owner_info = NULL; + + setlocale(LC_ALL, ""); + + err = isds_init(); + if (err) { + printf("isds_init() failed: %s\n", isds_strerror(err)); + exit(EXIT_FAILURE); + } + + isds_set_logging(ILF_ALL & ~ILF_HTTP, ILL_ALL); + + ctx = isds_ctx_create(); + if (!ctx) { + printf("isds_ctx_create() failed"); + } + + err = isds_set_timeout(ctx, 10000); + if (err) { + printf("isds_set_timeout() failed: %s\n", isds_strerror(err)); + } + + /* err = isds_set_tls(ctx, ITLS_VERIFY_SERVER, 0); + if (err) { + printf("isds_set_tls(ITLS_VERIFY_SERVER) failed: %s\n", + isds_strerror(err)); + } + + err = isds_set_tls(ctx, ITLS_CA_FILE, "/etc/ssl/certs/ca-certificates.crt"); + if (err) { + printf("isds_set_tls(ITLS_CA_FILE) failed: %s\n", + isds_strerror(err)); + }*/ + + err = isds_login(ctx, url, username, password, NULL, NULL); + if (err) { + printf("isds_login() failed: %s: %s\n", isds_strerror(err), + isds_long_message(ctx)); + } else { + printf("Logged in :)\n"); + } + + + { + printf("Getting info about my box:\n"); + err = isds_GetOwnerInfoFromLogin(ctx, &db_owner_info); + if (err) { + printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n", + isds_strerror(err), isds_long_message(ctx)); + } else { + printf("isds_GetOwnerInfoFromLogin() succeeded\n"); + } + print_DbOwnerInfo(db_owner_info); + } + + + /* Disable access to my box exernally. It should fail. */ + if (db_owner_info) { + struct isds_DbOwnerInfo *new_db_owner_info = NULL; + struct tm date = { + .tm_year = 103, + .tm_mon = 1, + .tm_mday = 1 + }; + char *refnumber = NULL; + + printf("Disabling access to my box externaly since: "); + print_date(&date); + err = isds_disable_box_accessibility_externaly(ctx, + db_owner_info, &date, &refnumber); + if (err) + printf("isds_disable_box_accessibility_externaly() failed: " + "%s: %s\n", isds_strerror(err), isds_long_message(ctx)); + else { + printf("isds_disable_box_accessibility_externaly() " + "succeeded as request #%s\n", refnumber); + } + free(refnumber); + + printf("Verifying info about my box:\n"); + err = isds_GetOwnerInfoFromLogin(ctx, &new_db_owner_info); + if (err) { + printf("isds_GetOwnerInfoFromLogin() failed: %s: %s\n", + isds_strerror(err), isds_long_message(ctx)); + } else { + printf("isds_GetOwnerInfoFromLogin() succeeded\n"); + printf("New box status is: "); + print_longint(new_db_owner_info->dbState); + } + isds_DbOwnerInfo_free(&new_db_owner_info); + } + + isds_DbOwnerInfo_free(&db_owner_info); + + + err = isds_logout(ctx); + if (err) { + printf("isds_logout() failed: %s\n", isds_strerror(err)); + } + + + err = isds_ctx_free(&ctx); + if (err) { + printf("isds_ctx_free() failed: %s\n", isds_strerror(err)); + } + + + err = isds_cleanup(); + if (err) { + printf("isds_cleanup() failed: %s\n", isds_strerror(err)); + } + + exit (EXIT_SUCCESS); +} diff --git a/doc/maintanance_web_services b/doc/maintanance_web_services index 99d1759..fdede11 100644 --- a/doc/maintanance_web_services +++ b/doc/maintanance_web_services @@ -81,6 +81,21 @@ ChangeISDSPassword Change password +DisableDataBoxExternally +======================== + +Make box unaccessible because owner lost ability to use the box for legal +reasons (prisoned person, person with no or weak legal rights). + +Input is box description and date when the ability to access box has became +impossible. This can be retroactive. + +After success, box changes state to state 2. + +Non-normative error codes: + 1004 Operation not permitted + + DisableOwnDataBox ================= diff --git a/src/isds.c b/src/isds.c index be247c3..4117c3a 100644 --- a/src/isds.c +++ b/src/isds.c @@ -4866,10 +4866,6 @@ static isds_error build_send_manipulationdbowner_request_check_drop_response( if (!context) return IE_INVALID_CONTEXT; if (!service_name || *service_name == '\0' || !owner) return IE_INVAL; - /* Check if connection is established - * TODO: This check should be done donwstairs. */ - if (!context->curl) return IE_CONNECTION_CLOSED; - service_name_locale = utf82locale((char*)service_name); if (!service_name_locale) { err = IE_NOMEM; @@ -4929,6 +4925,75 @@ isds_error isds_switch_box_accessibility_on_owner_request( } +/* Disable box accessibility on law enforcement (e.g. by prison) since exact + * date. + * @context is ISDS session context. + * @box identifies box to swith accesibilty state. + * @since is date since accesseibility has been denied. This can be past too. + * Only tm_year, tm_mon and tm_mday carry sane value. + * @refnumber is reallocated serial number of request assigned by ISDS. Use + * NULL, if you don't care. */ +isds_error isds_disable_box_accessibility_externaly( + struct isds_ctx *context, const struct isds_DbOwnerInfo *box, + const struct tm *since, char **refnumber) { + isds_error err = IE_SUCCESS; + char *service_name_locale = NULL; + xmlNodePtr request = NULL, node; + xmlNsPtr isds_ns = NULL; + xmlChar *string = NULL; + + + if (!context) return IE_INVALID_CONTEXT; + if (!box || !since) return IE_INVAL; + + /* Build request */ + request = xmlNewNode(NULL, BAD_CAST "DisableDataBoxExternally"); + if (!request) { + isds_printf_message(context, + _("Could not build %s request"), "DisableDataBoxExternally"); + err = IE_ERROR; + goto leave; + } + isds_ns = xmlNewNs(request, BAD_CAST ISDS_NS, NULL); + if(!isds_ns) { + isds_log_message(context, _("Could not create ISDS name space")); + err = IE_ERROR; + goto leave; + } + xmlSetNs(request, isds_ns); + + + /* Add @box identification */ + INSERT_ELEMENT(node, request, "dbOwnerInfo"); + err = insert_DbOwnerInfo(context, box, node); + if (err) goto leave; + + /* Add @since date */ + err = tm2datestring(since, &string); + if(err) { + isds_log_message(context, + _("Could not convert `since' argument to ISO date string")); + goto leave; + } + INSERT_STRING(request, "dbOwnerDisableDate", string); + zfree(string); + + /* TODO: XSD:gExtApproval*/ + + /* Send it to server and process response */ + err = send_request_check_drop_response(context, SERVICE_DB_MANIPULATION, + BAD_CAST "DisableDataBoxExternally", &request, + (xmlChar **) refnumber); + +leave: + free(string); + xmlFreeNode(request); + free(service_name_locale); + + return err; +} + + /* Insert struct isds_message data (envelope (recipient data optional) and * documents) into XML tree * @context is sesstion context diff --git a/src/isds.h b/src/isds.h index 9338bc6..f8c81c1 100644 --- a/src/isds.h +++ b/src/isds.h @@ -669,6 +669,18 @@ isds_error isds_switch_box_accessibility_on_owner_request( struct isds_ctx *context, const struct isds_DbOwnerInfo *box, const _Bool allow, char **refnumber); +/* Disable box accessibility on law enforcement (e.g. by prison) since exact + * date. + * @context is ISDS session context. + * @box identifies box to swith accesibilty state. + * @since is date since accesseibility has been denied. This can be past too. + * Only tm_year, tm_mon and tm_mday carry sane value. + * @refnumber is reallocated serial number of request assigned by ISDS. Use + * NULL, if you don't care. */ +isds_error isds_disable_box_accessibility_externaly( + struct isds_ctx *context, const struct isds_DbOwnerInfo *box, + const struct tm *since, char **refnumber); + /* Send a message via ISDS to a recipent * @context is session context * @outgoing_message is message to send; Some memebers are mandatory (like -- 2.11.4.GIT