src/pEpEngine.c
author Volker Birk <vb@pep-project.org>
Mon, 16 May 2016 11:55:36 +0200
changeset 632 a213fafe3f4f
parent 619 f93107f46f92
child 633 a2a4ad55e19e
permissions -rw-r--r--
sequence
vb@125
     1
#include "pEp_internal.h"
vb@98
     2
#include "dynamic_api.h"
vb@28
     3
#include "cryptotech.h"
vb@28
     4
#include "transport.h"
vb@515
     5
#include "blacklist.h"
vb@0
     6
vb@221
     7
static int init_count = -1;
vb@62
     8
vb@0
     9
DYNAMIC_API PEP_STATUS init(PEP_SESSION *session)
vb@0
    10
{
vb@65
    11
    PEP_STATUS status = PEP_STATUS_OK;
roker@529
    12
    int int_result;
roker@529
    13
    static const char *sql_log;
roker@529
    14
    static const char *sql_trustword;
roker@529
    15
    static const char *sql_get_identity;
roker@529
    16
    static const char *sql_set_person;
roker@529
    17
    static const char *sql_set_pgp_keypair;
roker@529
    18
    static const char *sql_set_identity;
roker@529
    19
    static const char *sql_set_trust;
vb@62
    20
    static const char *sql_get_trust;
vb@251
    21
    static const char *sql_least_trust;
vb@357
    22
    static const char *sql_mark_as_compromized;
vb@450
    23
    static const char *sql_crashdump;
vb@458
    24
    static const char *sql_languagelist;
vb@458
    25
    static const char *sql_i18n_token;
fdik@494
    26
fdik@494
    27
    // blacklist
fdik@494
    28
    static const char *sql_blacklist_add;
fdik@494
    29
    static const char *sql_blacklist_delete;
fdik@494
    30
    static const char *sql_blacklist_is_listed;
fdik@494
    31
    static const char *sql_blacklist_retrieve;
vb@450
    32
Edouard@584
    33
    // Own keys
Edouard@584
    34
    static const char *sql_own_key_add;
Edouard@584
    35
    static const char *sql_own_key_is_listed;
Edouard@584
    36
    static const char *sql_own_key_retrieve;
Edouard@584
    37
vb@632
    38
    static const char *sql_sequence_value;
vb@632
    39
vb@62
    40
    bool in_first = false;
vb@8
    41
vb@62
    42
    assert(sqlite3_threadsafe());
vb@62
    43
    if (!sqlite3_threadsafe())
vb@62
    44
        return PEP_INIT_SQLITE3_WITHOUT_MUTEX;
vb@62
    45
vb@62
    46
    // a little race condition - but still a race condition
vb@113
    47
    // mitigated by calling caveat (see documentation)
vb@62
    48
vb@62
    49
    ++init_count;
vb@67
    50
    if (init_count == 0)
vb@62
    51
        in_first = true;
vb@0
    52
roker@529
    53
    assert(session);
vb@191
    54
    if (session == NULL)
vb@191
    55
        return PEP_ILLEGAL_VALUE;
vb@191
    56
roker@529
    57
    *session = NULL;
vb@0
    58
vb@107
    59
    pEpSession *_session = calloc(1, sizeof(pEpSession));
roker@529
    60
    assert(_session);
roker@529
    61
    if (_session == NULL)
roker@529
    62
        goto enomem;
vb@62
    63
roker@529
    64
    _session->version = PEP_ENGINE_VERSION;
vb@0
    65
vb@0
    66
    assert(LOCAL_DB);
vb@0
    67
    if (LOCAL_DB == NULL) {
vb@65
    68
        status = PEP_INIT_CANNOT_OPEN_DB;
vb@65
    69
        goto pep_error;
vb@0
    70
    }
vb@0
    71
roker@529
    72
    int_result = sqlite3_open_v2(
roker@529
    73
            LOCAL_DB,
roker@529
    74
            &_session->db,
roker@529
    75
            SQLITE_OPEN_READWRITE
roker@529
    76
                | SQLITE_OPEN_CREATE
roker@529
    77
                | SQLITE_OPEN_FULLMUTEX
roker@529
    78
                | SQLITE_OPEN_PRIVATECACHE,
roker@529
    79
            NULL 
roker@529
    80
        );
vb@0
    81
roker@529
    82
    if (int_result != SQLITE_OK) {
roker@529
    83
        status = PEP_INIT_CANNOT_OPEN_DB;
vb@65
    84
        goto pep_error;
roker@529
    85
    }
vb@0
    86
roker@529
    87
    sqlite3_busy_timeout(_session->db, BUSY_WAIT_TIME);
vb@0
    88
vb@0
    89
    assert(SYSTEM_DB);
vb@0
    90
    if (SYSTEM_DB == NULL) {
roker@529
    91
        status = PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
vb@65
    92
        goto pep_error;
vb@0
    93
    }
vb@0
    94
roker@529
    95
    int_result = sqlite3_open_v2(
roker@529
    96
            SYSTEM_DB, &_session->system_db,
roker@529
    97
            SQLITE_OPEN_READONLY
roker@529
    98
                | SQLITE_OPEN_FULLMUTEX
roker@529
    99
                | SQLITE_OPEN_SHAREDCACHE,
roker@529
   100
            NULL
roker@529
   101
        );
vb@0
   102
roker@529
   103
    if (int_result != SQLITE_OK) {
roker@529
   104
        status = PEP_INIT_CANNOT_OPEN_SYSTEM_DB;
vb@65
   105
        goto pep_error;
roker@529
   106
    }
vb@0
   107
roker@529
   108
    sqlite3_busy_timeout(_session->system_db, 1000);
vb@0
   109
vb@62
   110
    if (in_first) {
vb@62
   111
        int_result = sqlite3_exec(
vb@62
   112
            _session->db,
vb@456
   113
                "create table if not exists version_info (\n"
vb@456
   114
                "   id integer primary key,\n"
vb@456
   115
                "   timestamp integer default (datetime('now')) ,\n"
vb@456
   116
                "   version text,\n"
vb@456
   117
                "   comment text\n"
vb@456
   118
                ");\n"
vb@456
   119
                "create table if not exists log (\n"
vb@456
   120
                "   timestamp integer default (datetime('now')) ,\n"
vb@456
   121
                "   title text not null,\n"
vb@456
   122
                "   entity text not null,\n"
vb@456
   123
                "   description text,\n"
vb@456
   124
                "   comment text\n"
vb@456
   125
                ");\n"
vb@456
   126
                "create index if not exists log_timestamp on log (\n"
vb@456
   127
                "   timestamp\n"
vb@456
   128
                ");\n"
vb@456
   129
                "create table if not exists pgp_keypair (\n"
vb@456
   130
                "   fpr text primary key,\n"
vb@456
   131
                "   public_id text unique,\n"
vb@456
   132
                "   private_id text,\n"
vb@456
   133
                "   created integer,\n"
vb@456
   134
                "   expires integer,\n"
vb@456
   135
                "   comment text\n"
vb@456
   136
                ");\n"
vb@456
   137
                "create index if not exists pgp_keypair_expires on pgp_keypair (\n"
vb@456
   138
                "   expires\n"
vb@456
   139
                ");\n"
vb@456
   140
                "create table if not exists person (\n"
vb@456
   141
                "   id text primary key,\n"
vb@456
   142
                "   username text not null,\n"
vb@456
   143
                "   main_key_id text\n"
vb@456
   144
                "       references pgp_keypair (fpr)\n"
vb@456
   145
                "       on delete set null,\n"
vb@456
   146
                "   lang text,\n"
vb@456
   147
                "   comment text\n"
vb@456
   148
                ");\n"
vb@456
   149
                "create table if not exists identity (\n"
Edouard@559
   150
                "   address text,\n"
vb@456
   151
                "   user_id text\n"
vb@456
   152
                "       references person (id)\n"
vb@456
   153
                "       on delete cascade,\n"
vb@456
   154
                "   main_key_id text\n"
vb@456
   155
                "       references pgp_keypair (fpr)\n"
vb@456
   156
                "       on delete set null,\n"
Edouard@559
   157
                "   comment text,\n"
Edouard@559
   158
                "   primary key (address, user_id)\n"
vb@456
   159
                ");\n"
vb@456
   160
                "create table if not exists trust (\n"
vb@456
   161
                "   user_id text not null\n"
vb@456
   162
                "       references person (id)\n"
vb@456
   163
                "       on delete cascade,\n"
vb@456
   164
                "   pgp_keypair_fpr text not null\n"
vb@456
   165
                "       references pgp_keypair (fpr)\n"
vb@456
   166
                "       on delete cascade,\n"
vb@456
   167
                "   comm_type integer not null,\n"
vb@456
   168
                "   comment text\n"
vb@456
   169
                ");\n"
vb@456
   170
                "create unique index if not exists trust_index on trust (\n"
vb@456
   171
                "   user_id,\n"
vb@456
   172
                "   pgp_keypair_fpr\n"
vb@456
   173
                ");\n"
fdik@494
   174
                // blacklist
vb@456
   175
                "create table if not exists blacklist_keys (\n"
vb@456
   176
                "   fpr text primary key\n"
vb@456
   177
                ");\n"
Edouard@584
   178
                // Own keys
Edouard@584
   179
                "create table if not exists own_keys (\n"
Edouard@584
   180
                "   fpr text primary key\n"
Edouard@584
   181
                "       references pgp_keypair (fpr)\n"
Edouard@588
   182
                "       on delete cascade\n"
Edouard@584
   183
                ");\n"
vb@632
   184
                // sequences
vb@632
   185
                "create table if not exists sequences(\n"
vb@632
   186
                "   name text primary key,\n"
vb@632
   187
                "   value integer default 0\n"
vb@632
   188
                ");\n"
vb@456
   189
                ,
vb@62
   190
            NULL,
vb@62
   191
            NULL,
vb@62
   192
            NULL
vb@62
   193
        );
vb@62
   194
        assert(int_result == SQLITE_OK);
vb@0
   195
vb@62
   196
        int_result = sqlite3_exec(
vb@62
   197
            _session->db,
fdik@494
   198
            "insert or replace into version_info (id, version) values (1, '1.1');",
vb@62
   199
            NULL,
vb@62
   200
            NULL,
vb@62
   201
            NULL
vb@62
   202
        );
vb@62
   203
        assert(int_result == SQLITE_OK);
vb@0
   204
vb@62
   205
        sql_log = "insert into log (title, entity, description, comment)"
vb@62
   206
                  "values (?1, ?2, ?3, ?4);";
vb@62
   207
Edouard@584
   208
        sql_get_identity =  "select fpr, username, comm_type, lang"
vb@62
   209
                            "   from identity"
vb@62
   210
                            "   join person on id = identity.user_id"
vb@62
   211
                            "   join pgp_keypair on fpr = identity.main_key_id"
vb@62
   212
                            "   join trust on id = trust.user_id"
vb@62
   213
                            "       and pgp_keypair_fpr = identity.main_key_id"
Edouard@559
   214
                            "   where address = ?1 and identity.user_id = ?2;";
Edouard@559
   215
vb@233
   216
        sql_trustword = "select id, word from wordlist where lang = lower(?1) "
vb@62
   217
                       "and id = ?2 ;";
vb@62
   218
vb@62
   219
        sql_set_person = "insert or replace into person (id, username, lang) "
vb@62
   220
                         "values (?1, ?2, ?3) ;";
vb@62
   221
vb@62
   222
        sql_set_pgp_keypair = "insert or replace into pgp_keypair (fpr) "
Edouard@559
   223
                              "values (upper(replace(?1,' ',''))) ;";
vb@62
   224
vb@62
   225
        sql_set_identity = "insert or replace into identity (address, main_key_id, "
Edouard@559
   226
                           "user_id) values (?1, upper(replace(?2,' ','')), ?3) ;";
vb@62
   227
vb@62
   228
        sql_set_trust = "insert or replace into trust (user_id, pgp_keypair_fpr, comm_type) "
Edouard@559
   229
                        "values (?1, upper(replace(?2,' ','')), ?3) ;";
vb@62
   230
Edouard@559
   231
        sql_get_trust = "select comm_type from trust where user_id = ?1 "
Edouard@559
   232
                        "and pgp_keypair_fpr = upper(replace(?2,' ','')) ;";
vb@251
   233
Edouard@559
   234
        sql_least_trust = "select min(comm_type) from trust where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
vb@357
   235
vb@457
   236
        sql_mark_as_compromized = "update trust not indexed set comm_type = 15"
Edouard@559
   237
                                  " where pgp_keypair_fpr = upper(replace(?1,' ','')) ;";
vb@450
   238
vb@457
   239
        sql_crashdump = "select timestamp, title, entity, description, comment"
vb@457
   240
                        " from log order by timestamp desc limit ?1 ;";
vb@458
   241
vb@619
   242
        sql_languagelist = "select i18n_language.lang, name, phrase from i18n_language join i18n_token using (lang) where i18n_token.id = 1000;" ;
vb@458
   243
vb@461
   244
        sql_i18n_token = "select phrase from i18n_token where lang = lower(?1) and id = ?2 ;";
vb@482
   245
fdik@494
   246
        // blacklist
fdik@494
   247
Edouard@559
   248
        sql_blacklist_add = "insert or replace into blacklist_keys (fpr) values (upper(replace(?1,' ',''))) ;"
Edouard@559
   249
                            "delete from identity where main_key_id = upper(replace(?1,' ','')) ;"
Edouard@559
   250
                            "delete from pgp_keypair where fpr = upper(replace(?1,' ','')) ;";
vb@514
   251
Edouard@559
   252
        sql_blacklist_delete = "delete from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
vb@514
   253
Edouard@559
   254
        sql_blacklist_is_listed = "select count(*) from blacklist_keys where fpr = upper(replace(?1,' ','')) ;";
vb@514
   255
fdik@494
   256
        sql_blacklist_retrieve = "select * from blacklist_keys ;";
Edouard@584
   257
        
Edouard@584
   258
        // Own keys
Edouard@584
   259
        
Edouard@584
   260
        sql_own_key_add = "insert or replace into own_keys (fpr) "
Edouard@584
   261
                          "    values (upper(replace(?1,' ',''))) ;";
Edouard@584
   262
        
Edouard@584
   263
        sql_own_key_is_listed = "select count(*) from own_keys where fpr = upper(replace(?1,' ','')) ;";
Edouard@584
   264
Edouard@584
   265
        sql_own_key_retrieve = "select * from own_keys ;";
vb@632
   266
 
vb@632
   267
        sql_sequence_value = "insert or replace into sequences (name, value) "
vb@632
   268
                             "values (?1, "
vb@632
   269
                             "(select coalesce((select value + 1 from sequences "
vb@632
   270
                             "where name = ?1), 1 ))) ; "
vb@632
   271
                             "select value from sequences where name = ?1 ;";
vb@62
   272
    }
vb@62
   273
Edouard@417
   274
    int_result = sqlite3_prepare_v2(_session->db, sql_log, (int)strlen(sql_log),
vb@0
   275
            &_session->log, NULL);
roker@529
   276
    assert(int_result == SQLITE_OK);
vb@0
   277
vb@233
   278
    int_result = sqlite3_prepare_v2(_session->system_db, sql_trustword,
Edouard@417
   279
            (int)strlen(sql_trustword), &_session->trustword, NULL);
roker@529
   280
    assert(int_result == SQLITE_OK);
vb@0
   281
vb@0
   282
    int_result = sqlite3_prepare_v2(_session->db, sql_get_identity,
Edouard@417
   283
            (int)strlen(sql_get_identity), &_session->get_identity, NULL);
roker@529
   284
    assert(int_result == SQLITE_OK);
vb@0
   285
vb@0
   286
    int_result = sqlite3_prepare_v2(_session->db, sql_set_person,
Edouard@417
   287
            (int)strlen(sql_set_person), &_session->set_person, NULL);
vb@0
   288
    assert(int_result == SQLITE_OK);
vb@62
   289
vb@0
   290
    int_result = sqlite3_prepare_v2(_session->db, sql_set_pgp_keypair,
Edouard@417
   291
            (int)strlen(sql_set_pgp_keypair), &_session->set_pgp_keypair, NULL);
roker@529
   292
    assert(int_result == SQLITE_OK);
vb@62
   293
vb@0
   294
    int_result = sqlite3_prepare_v2(_session->db, sql_set_identity,
Edouard@417
   295
            (int)strlen(sql_set_identity), &_session->set_identity, NULL);
roker@529
   296
    assert(int_result == SQLITE_OK);
vb@62
   297
vb@0
   298
    int_result = sqlite3_prepare_v2(_session->db, sql_set_trust,
Edouard@417
   299
            (int)strlen(sql_set_trust), &_session->set_trust, NULL);
roker@529
   300
    assert(int_result == SQLITE_OK);
vb@62
   301
vb@8
   302
    int_result = sqlite3_prepare_v2(_session->db, sql_get_trust,
Edouard@417
   303
            (int)strlen(sql_get_trust), &_session->get_trust, NULL);
vb@8
   304
    assert(int_result == SQLITE_OK);
vb@0
   305
vb@251
   306
    int_result = sqlite3_prepare_v2(_session->db, sql_least_trust,
Edouard@417
   307
            (int)strlen(sql_least_trust), &_session->least_trust, NULL);
vb@251
   308
    assert(int_result == SQLITE_OK);
vb@251
   309
vb@357
   310
    int_result = sqlite3_prepare_v2(_session->db, sql_mark_as_compromized,
Edouard@417
   311
            (int)strlen(sql_mark_as_compromized), &_session->mark_compromized, NULL);
vb@357
   312
    assert(int_result == SQLITE_OK);
vb@357
   313
vb@453
   314
    int_result = sqlite3_prepare_v2(_session->db, sql_crashdump,
vb@453
   315
            (int)strlen(sql_crashdump), &_session->crashdump, NULL);
vb@453
   316
    assert(int_result == SQLITE_OK);
vb@453
   317
vb@458
   318
    int_result = sqlite3_prepare_v2(_session->system_db, sql_languagelist,
vb@458
   319
            (int)strlen(sql_languagelist), &_session->languagelist, NULL);
roker@529
   320
    assert(int_result == SQLITE_OK);
vb@458
   321
vb@458
   322
    int_result = sqlite3_prepare_v2(_session->system_db, sql_i18n_token,
vb@458
   323
            (int)strlen(sql_i18n_token), &_session->i18n_token, NULL);
roker@529
   324
    assert(int_result == SQLITE_OK);
vb@458
   325
fdik@494
   326
    // blacklist
fdik@494
   327
fdik@494
   328
    int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_add,
fdik@494
   329
            (int)strlen(sql_blacklist_add), &_session->blacklist_add, NULL);
fdik@494
   330
    assert(int_result == SQLITE_OK);
fdik@494
   331
fdik@494
   332
    int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_delete,
fdik@494
   333
            (int)strlen(sql_blacklist_delete), &_session->blacklist_delete, NULL);
fdik@494
   334
    assert(int_result == SQLITE_OK);
fdik@494
   335
fdik@494
   336
    int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_is_listed,
fdik@494
   337
            (int)strlen(sql_blacklist_is_listed), &_session->blacklist_is_listed, NULL);
fdik@494
   338
    assert(int_result == SQLITE_OK);
fdik@494
   339
fdik@494
   340
    int_result = sqlite3_prepare_v2(_session->db, sql_blacklist_retrieve,
fdik@494
   341
            (int)strlen(sql_blacklist_retrieve), &_session->blacklist_retrieve, NULL);
vb@482
   342
    assert(int_result == SQLITE_OK);
vb@482
   343
Edouard@584
   344
    // Own keys
Edouard@584
   345
    
Edouard@584
   346
    int_result = sqlite3_prepare_v2(_session->db, sql_own_key_add,
Edouard@584
   347
                                    (int)strlen(sql_own_key_add), &_session->own_key_add, NULL);
Edouard@584
   348
    assert(int_result == SQLITE_OK);
Edouard@584
   349
    
Edouard@584
   350
    int_result = sqlite3_prepare_v2(_session->db, sql_own_key_is_listed,
Edouard@584
   351
                                    (int)strlen(sql_own_key_is_listed), &_session->own_key_is_listed, NULL);
Edouard@584
   352
    assert(int_result == SQLITE_OK);
Edouard@584
   353
    
Edouard@584
   354
    int_result = sqlite3_prepare_v2(_session->db, sql_own_key_retrieve,
Edouard@584
   355
                                    (int)strlen(sql_own_key_retrieve), &_session->own_key_retrieve, NULL);
Edouard@584
   356
    assert(int_result == SQLITE_OK);
Edouard@584
   357
    
vb@65
   358
    status = init_cryptotech(_session, in_first);
vb@65
   359
    if (status != PEP_STATUS_OK)
vb@65
   360
        goto pep_error;
vb@0
   361
vb@65
   362
    status = init_transport_system(_session, in_first);
vb@65
   363
    if (status != PEP_STATUS_OK)
vb@65
   364
        goto pep_error;
vb@62
   365
vb@65
   366
    status = log_event(_session, "init", "pEp " PEP_ENGINE_VERSION, NULL, NULL);
vb@65
   367
    if (status != PEP_STATUS_OK)
vb@65
   368
        goto pep_error;
vb@65
   369
vb@464
   370
    // runtime config
vb@464
   371
vb@464
   372
    _session->passive_mode = false;
vb@464
   373
    _session->unencrypted_subject = false;
vb@464
   374
roker@529
   375
    *session = _session;
roker@529
   376
    return PEP_STATUS_OK;
vb@65
   377
vb@65
   378
enomem:
vb@65
   379
    status = PEP_OUT_OF_MEMORY;
vb@65
   380
vb@65
   381
pep_error:
vb@65
   382
    release(_session);
vb@65
   383
    return status;
vb@0
   384
}
vb@0
   385
vb@0
   386
DYNAMIC_API void release(PEP_SESSION session)
vb@0
   387
{
vb@62
   388
    bool out_last = false;
vb@62
   389
vb@62
   390
    assert(init_count >= 0);
roker@529
   391
    assert(session);
vb@0
   392
Edouard@385
   393
    if (!((init_count >= 0) && session))
vb@191
   394
        return;
vb@191
   395
vb@62
   396
    // a small race condition but still a race condition
vb@113
   397
    // mitigated by calling caveat (see documentation)
vb@62
   398
vb@62
   399
    if (init_count == 0)
vb@62
   400
        out_last = true;
vb@62
   401
    --init_count;
vb@62
   402
roker@529
   403
    if (session) {
roker@529
   404
        if (session->db) {
vb@517
   405
            if (session->log)
vb@517
   406
                sqlite3_finalize(session->log);
vb@233
   407
            if (session->trustword)
vb@233
   408
                sqlite3_finalize(session->trustword);
vb@65
   409
            if (session->get_identity)
vb@65
   410
                sqlite3_finalize(session->get_identity);
vb@65
   411
            if (session->set_person)
vb@65
   412
                sqlite3_finalize(session->set_person);
vb@65
   413
            if (session->set_pgp_keypair)
vb@65
   414
                sqlite3_finalize(session->set_pgp_keypair);
vb@517
   415
            if (session->set_identity)
vb@517
   416
                sqlite3_finalize(session->set_identity);
vb@65
   417
            if (session->set_trust)
vb@65
   418
                sqlite3_finalize(session->set_trust);
vb@65
   419
            if (session->get_trust)
vb@65
   420
                sqlite3_finalize(session->get_trust);
vb@251
   421
            if (session->least_trust)
vb@251
   422
                sqlite3_finalize(session->least_trust);
vb@517
   423
            if (session->mark_compromized)
vb@517
   424
                sqlite3_finalize(session->mark_compromized);
vb@517
   425
            if (session->crashdump)
vb@517
   426
                sqlite3_finalize(session->crashdump);
vb@517
   427
            if (session->languagelist)
vb@517
   428
                sqlite3_finalize(session->languagelist);
vb@517
   429
            if (session->i18n_token)
vb@517
   430
                sqlite3_finalize(session->i18n_token);
vb@517
   431
            if (session->blacklist_add)
vb@517
   432
                sqlite3_finalize(session->blacklist_add);
vb@517
   433
            if (session->blacklist_delete)
vb@517
   434
                sqlite3_finalize(session->blacklist_delete);
vb@517
   435
            if (session->blacklist_is_listed)
vb@517
   436
                sqlite3_finalize(session->blacklist_is_listed);
vb@517
   437
            if (session->blacklist_retrieve)
vb@517
   438
                sqlite3_finalize(session->blacklist_retrieve);
vb@26
   439
vb@65
   440
            if (session->db)
vb@65
   441
                sqlite3_close_v2(session->db);
vb@65
   442
            if (session->system_db)
vb@65
   443
                sqlite3_close_v2(session->system_db);
roker@529
   444
        }
vb@65
   445
vb@65
   446
        release_transport_system(session, out_last);
vb@65
   447
        release_cryptotech(session, out_last);
vb@65
   448
vb@65
   449
        free(session);
vb@62
   450
    }
vb@0
   451
}
vb@0
   452
vb@467
   453
DYNAMIC_API void config_passive_mode(PEP_SESSION session, bool enable)
vb@464
   454
{
vb@464
   455
    assert(session);
vb@467
   456
    session->passive_mode = enable;
vb@464
   457
}
vb@464
   458
vb@467
   459
DYNAMIC_API void config_unencrypted_subject(PEP_SESSION session, bool enable)
vb@464
   460
{
vb@464
   461
    assert(session);
vb@467
   462
    session->unencrypted_subject = enable;
vb@464
   463
}
vb@464
   464
vb@0
   465
DYNAMIC_API PEP_STATUS log_event(
vb@450
   466
        PEP_SESSION session,
vb@451
   467
        const char *title,
vb@451
   468
        const char *entity,
vb@451
   469
        const char *description,
vb@451
   470
        const char *comment
vb@0
   471
    )
vb@0
   472
{
roker@529
   473
    PEP_STATUS status = PEP_STATUS_OK;
roker@529
   474
    int result;
vb@0
   475
roker@529
   476
    assert(session);
roker@529
   477
    assert(title);
roker@529
   478
    assert(entity);
vb@0
   479
vb@191
   480
    if (!(session && title && entity))
vb@191
   481
        return PEP_ILLEGAL_VALUE;
vb@191
   482
roker@529
   483
    sqlite3_reset(session->log);
roker@529
   484
    sqlite3_bind_text(session->log, 1, title, -1, SQLITE_STATIC);
roker@529
   485
    sqlite3_bind_text(session->log, 2, entity, -1, SQLITE_STATIC);
roker@529
   486
    if (description)
vb@46
   487
        sqlite3_bind_text(session->log, 3, description, -1, SQLITE_STATIC);
roker@529
   488
    else
roker@529
   489
        sqlite3_bind_null(session->log, 3);
roker@529
   490
    if (comment)
roker@529
   491
        sqlite3_bind_text(session->log, 4, comment, -1, SQLITE_STATIC);
roker@529
   492
    else
roker@529
   493
        sqlite3_bind_null(session->log, 4);
roker@529
   494
    do {
roker@529
   495
        result = sqlite3_step(session->log);
roker@529
   496
        assert(result == SQLITE_DONE || result == SQLITE_BUSY);
roker@529
   497
        if (result != SQLITE_DONE && result != SQLITE_BUSY)
roker@529
   498
            status = PEP_UNKNOWN_ERROR;
roker@529
   499
    } while (result == SQLITE_BUSY);
roker@529
   500
    sqlite3_reset(session->log);
vb@0
   501
roker@529
   502
    return status;
vb@0
   503
}
vb@0
   504
vb@233
   505
DYNAMIC_API PEP_STATUS trustword(
vb@0
   506
            PEP_SESSION session, uint16_t value, const char *lang,
vb@0
   507
            char **word, size_t *wsize
vb@0
   508
        )
vb@0
   509
{
roker@529
   510
    PEP_STATUS status = PEP_STATUS_OK;
roker@529
   511
    int result;
vb@0
   512
roker@529
   513
    assert(session);
roker@529
   514
    assert(word);
roker@529
   515
    assert(wsize);
vb@0
   516
vb@191
   517
    if (!(session && word && wsize))
vb@191
   518
        return PEP_ILLEGAL_VALUE;
vb@191
   519
roker@529
   520
    *word = NULL;
roker@529
   521
    *wsize = 0;
vb@0
   522
roker@529
   523
    if (lang == NULL)
roker@529
   524
        lang = "en";
vb@0
   525
roker@529
   526
    assert((lang[0] >= 'A' && lang[0] <= 'Z')
vb@0
   527
            || (lang[0] >= 'a' && lang[0] <= 'z'));
roker@529
   528
    assert((lang[1] >= 'A' && lang[1] <= 'Z')
vb@0
   529
            || (lang[1] >= 'a' && lang[1] <= 'z'));
roker@529
   530
    assert(lang[2] == 0);
vb@0
   531
roker@529
   532
    sqlite3_reset(session->trustword);
vb@233
   533
    sqlite3_bind_text(session->trustword, 1, lang, -1, SQLITE_STATIC);
roker@529
   534
    sqlite3_bind_int(session->trustword, 2, value);
vb@0
   535
roker@529
   536
    result = sqlite3_step(session->trustword);
roker@529
   537
    if (result == SQLITE_ROW) {
vb@233
   538
        *word = strdup((const char *) sqlite3_column_text(session->trustword,
vb@0
   539
                    1));
roker@529
   540
        if (*word)
vb@233
   541
            *wsize = sqlite3_column_bytes(session->trustword, 1);
roker@529
   542
        else
roker@529
   543
            status = PEP_TRUSTWORD_NOT_FOUND;
roker@529
   544
    } else
roker@529
   545
        status = PEP_TRUSTWORD_NOT_FOUND;
vb@0
   546
roker@529
   547
    sqlite3_reset(session->trustword);
roker@529
   548
    return status;
vb@0
   549
}
vb@0
   550
vb@233
   551
DYNAMIC_API PEP_STATUS trustwords(
vb@0
   552
        PEP_SESSION session, const char *fingerprint, const char *lang,
vb@0
   553
        char **words, size_t *wsize, int max_words
vb@0
   554
    )
vb@0
   555
{
roker@529
   556
    const char *source = fingerprint;
roker@529
   557
    char *buffer;
roker@529
   558
    char *dest;
roker@529
   559
    size_t fsize;
vb@0
   560
    PEP_STATUS _status;
vb@0
   561
roker@529
   562
    assert(session);
roker@529
   563
    assert(fingerprint);
roker@529
   564
    assert(words);
roker@529
   565
    assert(wsize);
roker@529
   566
    assert(max_words >= 0);
vb@0
   567
vb@191
   568
    if (!(session && fingerprint && words && wsize && max_words >= 0))
vb@191
   569
        return PEP_ILLEGAL_VALUE;
vb@191
   570
roker@529
   571
    *words = NULL;
roker@529
   572
    *wsize = 0;
vb@0
   573
vb@251
   574
    buffer = calloc(1, MAX_TRUSTWORDS_SPACE);
vb@0
   575
    assert(buffer);
vb@0
   576
    if (buffer == NULL)
vb@0
   577
        return PEP_OUT_OF_MEMORY;
vb@125
   578
    dest = buffer;
vb@0
   579
roker@529
   580
    fsize = strlen(fingerprint);
vb@0
   581
roker@529
   582
    if (!lang || !lang[0])
roker@529
   583
        lang = "en";
vb@0
   584
roker@529
   585
    assert((lang[0] >= 'A' && lang[0] <= 'Z')
vb@0
   586
            || (lang[0] >= 'a' && lang[0] <= 'z'));
roker@529
   587
    assert((lang[1] >= 'A' && lang[1] <= 'Z')
vb@0
   588
            || (lang[1] >= 'a' && lang[1] <= 'z'));
roker@529
   589
    assert(lang[2] == 0);
vb@0
   590
roker@529
   591
    int n_words = 0;
roker@529
   592
    while (source < fingerprint + fsize) {
roker@529
   593
        uint16_t value;
roker@529
   594
        char *word;
roker@529
   595
        size_t _wsize;
roker@529
   596
        int j;
vb@0
   597
vb@0
   598
        for (value=0, j=0; j < 4 && source < fingerprint + fsize; ) {
roker@529
   599
            if (*source >= 'a' && *source <= 'f')
roker@529
   600
                value += (*source - 'a' + 10) << (3 - j++) * 4;
roker@529
   601
            else if (*source >= 'A' && *source <= 'F')
roker@529
   602
                value += (*source - 'A' + 10) << (3 - j++) * 4;
roker@529
   603
            else if (*source >= '0' && *source <= '9')
roker@529
   604
                value += (*source - '0') << (3 - j++) * 4;
roker@529
   605
            
roker@529
   606
            source++;
roker@529
   607
        }
vb@0
   608
roker@529
   609
        _status = trustword(session, value, lang, &word, &_wsize);
vb@0
   610
        if (_status == PEP_OUT_OF_MEMORY) {
vb@0
   611
            free(buffer);
vb@0
   612
            return PEP_OUT_OF_MEMORY;
vb@0
   613
        }
roker@529
   614
        if (word == NULL) {
vb@0
   615
            free(buffer);
roker@529
   616
            return PEP_TRUSTWORD_NOT_FOUND;
vb@0
   617
        }
vb@0
   618
roker@529
   619
        if (dest + _wsize < buffer + MAX_TRUSTWORDS_SPACE - 1) {
roker@529
   620
            strncpy(dest, word, _wsize);
vb@0
   621
            free(word);
roker@529
   622
            dest += _wsize;
roker@529
   623
        }
roker@529
   624
        else {
vb@0
   625
            free(word);
roker@529
   626
            break; // buffer full
vb@0
   627
        }
vb@0
   628
roker@529
   629
        if (source < fingerprint + fsize
vb@251
   630
                && dest + _wsize < buffer + MAX_TRUSTWORDS_SPACE - 1)
roker@529
   631
            *dest++ = ' ';
vb@0
   632
roker@529
   633
        ++n_words;
roker@529
   634
        if (max_words && n_words >= max_words)
roker@529
   635
            break;
roker@529
   636
    }
vb@0
   637
roker@529
   638
    *words = buffer;
roker@529
   639
    *wsize = dest - buffer;
roker@529
   640
    return PEP_STATUS_OK;
vb@0
   641
}
vb@0
   642
vb@0
   643
pEp_identity *new_identity(
vb@0
   644
        const char *address, const char *fpr, const char *user_id,
vb@0
   645
        const char *username
vb@0
   646
    )
vb@0
   647
{
vb@0
   648
    pEp_identity *result = calloc(1, sizeof(pEp_identity));
vb@0
   649
    assert(result);
vb@0
   650
    if (result) {
vb@0
   651
        if (address) {
vb@0
   652
            result->address = strdup(address);
vb@0
   653
            assert(result->address);
vb@0
   654
            if (result->address == NULL) {
vb@0
   655
                free(result);
vb@0
   656
                return NULL;
vb@0
   657
            }
vb@0
   658
        }
vb@0
   659
        if (fpr) {
vb@0
   660
            result->fpr = strdup(fpr);
vb@0
   661
            assert(result->fpr);
vb@0
   662
            if (result->fpr == NULL) {
vb@0
   663
                free_identity(result);
vb@0
   664
                return NULL;
vb@0
   665
            }
vb@0
   666
        }
vb@0
   667
        if (user_id) {
vb@0
   668
            result->user_id = strdup(user_id);
vb@0
   669
            assert(result->user_id);
vb@0
   670
            if (result->user_id == NULL) {
vb@0
   671
                free_identity(result);
vb@0
   672
                return NULL;
vb@0
   673
            }
vb@0
   674
        }
vb@0
   675
        if (username) {
vb@0
   676
            result->username = strdup(username);
vb@0
   677
            assert(result->username);
vb@0
   678
            if (result->username == NULL) {
vb@0
   679
                free_identity(result);
vb@0
   680
                return NULL;
vb@0
   681
            }
vb@0
   682
        }
vb@0
   683
    }
vb@0
   684
    return result;
vb@0
   685
}
vb@0
   686
vb@37
   687
pEp_identity *identity_dup(const pEp_identity *src)
vb@37
   688
{
vb@37
   689
    assert(src);
vb@37
   690
vb@37
   691
    pEp_identity *dup = new_identity(src->address, src->fpr, src->user_id, src->username);
vb@37
   692
    assert(dup);
vb@37
   693
    if (dup == NULL)
vb@37
   694
        return NULL;
vb@37
   695
    
vb@37
   696
    dup->comm_type = src->comm_type;
vb@37
   697
    dup->lang[0] = src->lang[0];
vb@37
   698
    dup->lang[1] = src->lang[1];
vb@37
   699
    dup->lang[2] = 0;
vb@37
   700
    dup->me = src->me;
vb@37
   701
vb@37
   702
    return dup;
vb@37
   703
}
vb@37
   704
vb@0
   705
void free_identity(pEp_identity *identity)
vb@0
   706
{
vb@0
   707
    if (identity) {
vb@0
   708
        free(identity->address);
vb@0
   709
        free(identity->fpr);
vb@0
   710
        free(identity->user_id);
vb@0
   711
        free(identity->username);
vb@0
   712
        free(identity);
vb@0
   713
    }
vb@0
   714
}
vb@0
   715
vb@0
   716
DYNAMIC_API PEP_STATUS get_identity(
Edouard@559
   717
        PEP_SESSION session,
Edouard@559
   718
        const char *address,
Edouard@559
   719
        const char *user_id,
vb@0
   720
        pEp_identity **identity
vb@0
   721
    )
vb@0
   722
{
roker@529
   723
    PEP_STATUS status = PEP_STATUS_OK;
roker@529
   724
    static pEp_identity *_identity;
roker@529
   725
    int result;
roker@529
   726
    const char *_lang;
vb@0
   727
roker@529
   728
    assert(session);
roker@529
   729
    assert(address);
vb@8
   730
    assert(address[0]);
vb@632
   731
    assert(identity);
vb@0
   732
vb@632
   733
    if (!(session && address && address[0] && identity))
vb@191
   734
        return PEP_ILLEGAL_VALUE;
vb@191
   735
vb@632
   736
    *identity = NULL;
vb@632
   737
vb@46
   738
    sqlite3_reset(session->get_identity);
vb@46
   739
    sqlite3_bind_text(session->get_identity, 1, address, -1, SQLITE_STATIC);
Edouard@559
   740
    sqlite3_bind_text(session->get_identity, 2, user_id, -1, SQLITE_STATIC);
vb@0
   741
vb@46
   742
    result = sqlite3_step(session->get_identity);
roker@529
   743
    switch (result) {
roker@529
   744
    case SQLITE_ROW:
vb@0
   745
        _identity = new_identity(
vb@0
   746
                address,
vb@46
   747
                (const char *) sqlite3_column_text(session->get_identity, 0),
Edouard@559
   748
                user_id,
Edouard@559
   749
                (const char *) sqlite3_column_text(session->get_identity, 1)
vb@0
   750
                );
vb@0
   751
        assert(_identity);
vb@0
   752
        if (_identity == NULL)
vb@0
   753
            return PEP_OUT_OF_MEMORY;
vb@0
   754
Edouard@559
   755
        _identity->comm_type = (PEP_comm_type) sqlite3_column_int(session->get_identity, 2);
Edouard@559
   756
        _lang = (const char *) sqlite3_column_text(session->get_identity, 3);
vb@0
   757
        if (_lang && _lang[0]) {
roker@529
   758
            assert(_lang[0] >= 'a' && _lang[0] <= 'z');
roker@529
   759
            assert(_lang[1] >= 'a' && _lang[1] <= 'z');
roker@529
   760
            assert(_lang[2] == 0);
roker@529
   761
            _identity->lang[0] = _lang[0];
roker@529
   762
            _identity->lang[1] = _lang[1];
vb@0
   763
            _identity->lang[2] = 0;
roker@529
   764
        }
roker@529
   765
        *identity = _identity;
roker@529
   766
        break;
roker@529
   767
    default:
vb@0
   768
        status = PEP_CANNOT_FIND_IDENTITY;
roker@529
   769
        *identity = NULL;
roker@529
   770
    }
vb@0
   771
vb@46
   772
    sqlite3_reset(session->get_identity);
roker@529
   773
    return status;
vb@0
   774
}
vb@0
   775
vb@0
   776
DYNAMIC_API PEP_STATUS set_identity(
vb@0
   777
        PEP_SESSION session, const pEp_identity *identity
vb@0
   778
    )
vb@0
   779
{
roker@529
   780
    int result;
vb@0
   781
roker@529
   782
    assert(session);
roker@529
   783
    assert(identity);
roker@529
   784
    assert(identity->address);
roker@529
   785
    assert(identity->fpr);
roker@529
   786
    assert(identity->user_id);
roker@529
   787
    assert(identity->username);
vb@0
   788
vb@191
   789
    if (!(session && identity && identity->address && identity->fpr &&
vb@191
   790
                identity->user_id && identity->username))
vb@191
   791
        return PEP_ILLEGAL_VALUE;
vb@191
   792
vb@515
   793
    bool listed;
vb@515
   794
    PEP_STATUS status = blacklist_is_listed(session, identity->fpr, &listed);
vb@515
   795
    assert(status == PEP_STATUS_OK);
vb@515
   796
    if (status != PEP_STATUS_OK)
vb@515
   797
        return status;
vb@515
   798
vb@515
   799
    if (listed)
vb@515
   800
        return PEP_KEY_BLACKLISTED;
vb@515
   801
roker@529
   802
    sqlite3_exec(session->db, "BEGIN ;", NULL, NULL, NULL);
vb@0
   803
roker@529
   804
    sqlite3_reset(session->set_person);
vb@46
   805
    sqlite3_bind_text(session->set_person, 1, identity->user_id, -1,
vb@0
   806
            SQLITE_STATIC);
vb@46
   807
    sqlite3_bind_text(session->set_person, 2, identity->username, -1,
vb@0
   808
            SQLITE_STATIC);
roker@529
   809
    if (identity->lang[0])
vb@46
   810
        sqlite3_bind_text(session->set_person, 3, identity->lang, 1,
vb@0
   811
                SQLITE_STATIC);
roker@529
   812
    else
roker@529
   813
        sqlite3_bind_null(session->set_person, 3);
roker@529
   814
    result = sqlite3_step(session->set_person);
roker@529
   815
    sqlite3_reset(session->set_person);
roker@529
   816
    if (result != SQLITE_DONE) {
roker@529
   817
        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
roker@529
   818
        return PEP_CANNOT_SET_PERSON;
roker@529
   819
    }
vb@0
   820
roker@529
   821
    sqlite3_reset(session->set_pgp_keypair);
vb@46
   822
    sqlite3_bind_text(session->set_pgp_keypair, 1, identity->fpr, -1,
vb@0
   823
            SQLITE_STATIC);
roker@529
   824
    result = sqlite3_step(session->set_pgp_keypair);
roker@529
   825
    sqlite3_reset(session->set_pgp_keypair);
roker@529
   826
    if (result != SQLITE_DONE) {
roker@529
   827
        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
roker@529
   828
        return PEP_CANNOT_SET_PGP_KEYPAIR;
roker@529
   829
    }
vb@0
   830
roker@529
   831
    sqlite3_reset(session->set_identity);
vb@46
   832
    sqlite3_bind_text(session->set_identity, 1, identity->address, -1,
vb@0
   833
            SQLITE_STATIC);
vb@46
   834
    sqlite3_bind_text(session->set_identity, 2, identity->fpr, -1,
vb@0
   835
            SQLITE_STATIC);
vb@46
   836
    sqlite3_bind_text(session->set_identity, 3, identity->user_id, -1,
vb@0
   837
            SQLITE_STATIC);
roker@529
   838
    result = sqlite3_step(session->set_identity);
roker@529
   839
    sqlite3_reset(session->set_identity);
roker@529
   840
    if (result != SQLITE_DONE) {
roker@529
   841
        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
roker@529
   842
        return PEP_CANNOT_SET_IDENTITY;
roker@529
   843
    }
vb@0
   844
roker@529
   845
    sqlite3_reset(session->set_trust);
vb@46
   846
    sqlite3_bind_text(session->set_trust, 1, identity->user_id, -1,
vb@0
   847
            SQLITE_STATIC);
vb@46
   848
    sqlite3_bind_text(session->set_trust, 2, identity->fpr, -1,
vb@0
   849
            SQLITE_STATIC);
roker@529
   850
    sqlite3_bind_int(session->set_trust, 3, identity->comm_type);
roker@529
   851
    result = sqlite3_step(session->set_trust);
roker@529
   852
    sqlite3_reset(session->set_trust);
roker@529
   853
    if (result != SQLITE_DONE) {
roker@529
   854
        sqlite3_exec(session->db, "ROLLBACK ;", NULL, NULL, NULL);
Edouard@584
   855
        return PEP_CANNOT_SET_TRUST;
roker@529
   856
    }
vb@0
   857
vb@46
   858
    result = sqlite3_exec(session->db, "COMMIT ;", NULL, NULL, NULL);
roker@529
   859
    if (result == SQLITE_OK)
roker@529
   860
        return PEP_STATUS_OK;
roker@529
   861
    else
roker@529
   862
        return PEP_COMMIT_FAILED;
vb@0
   863
}
vb@0
   864
vb@357
   865
DYNAMIC_API PEP_STATUS mark_as_compromized(
vb@357
   866
        PEP_SESSION session,
vb@357
   867
        const char *fpr
vb@357
   868
    )
vb@357
   869
{
roker@529
   870
    int result;
vb@357
   871
roker@529
   872
    assert(session);
vb@357
   873
    assert(fpr && fpr[0]);
vb@357
   874
vb@357
   875
    if (!(session && fpr && fpr[0]))
vb@357
   876
        return PEP_ILLEGAL_VALUE;
vb@357
   877
roker@529
   878
    sqlite3_reset(session->mark_compromized);
vb@357
   879
    sqlite3_bind_text(session->mark_compromized, 1, fpr, -1,
vb@357
   880
            SQLITE_STATIC);
vb@357
   881
    result = sqlite3_step(session->mark_compromized);
roker@529
   882
    sqlite3_reset(session->mark_compromized);
vb@357
   883
vb@357
   884
    if (result != SQLITE_DONE)
Edouard@584
   885
        return PEP_CANNOT_SET_TRUST;
vb@357
   886
vb@357
   887
    return PEP_STATUS_OK;
vb@357
   888
}
vb@357
   889
vb@0
   890
void pEp_free(void *p)
vb@0
   891
{
vb@0
   892
    free(p);
vb@0
   893
}
vb@0
   894
vb@8
   895
DYNAMIC_API PEP_STATUS get_trust(PEP_SESSION session, pEp_identity *identity)
vb@8
   896
{
vb@8
   897
    PEP_STATUS status = PEP_STATUS_OK;
vb@8
   898
    int result;
vb@8
   899
vb@8
   900
    assert(session);
vb@8
   901
    assert(identity);
vb@8
   902
    assert(identity->user_id);
vb@8
   903
    assert(identity->user_id[0]);
vb@8
   904
    assert(identity->fpr);
vb@8
   905
    assert(identity->fpr[0]);
vb@8
   906
vb@191
   907
    if (!(session && identity && identity->user_id && identity->user_id[0] &&
vb@191
   908
                identity->fpr && identity->fpr[0]))
vb@191
   909
        return PEP_ILLEGAL_VALUE;
vb@191
   910
vb@8
   911
    identity->comm_type = PEP_ct_unknown;
vb@8
   912
vb@46
   913
    sqlite3_reset(session->get_trust);
vb@46
   914
    sqlite3_bind_text(session->get_trust, 1, identity->user_id, -1, SQLITE_STATIC);
vb@46
   915
    sqlite3_bind_text(session->get_trust, 2, identity->fpr, -1, SQLITE_STATIC);
vb@8
   916
vb@46
   917
    result = sqlite3_step(session->get_trust);
vb@8
   918
    switch (result) {
vb@8
   919
    case SQLITE_ROW: {
Edouard@559
   920
        int comm_type = (PEP_comm_type) sqlite3_column_int(session->get_trust, 0);
vb@8
   921
        identity->comm_type = comm_type;
vb@8
   922
        break;
vb@8
   923
    }
vb@8
   924
 
vb@8
   925
    default:
vb@8
   926
        status = PEP_CANNOT_FIND_IDENTITY;
vb@8
   927
    }
vb@8
   928
vb@46
   929
    sqlite3_reset(session->get_trust);
vb@8
   930
    return status;
vb@9
   931
}
vb@9
   932
vb@251
   933
DYNAMIC_API PEP_STATUS least_trust(
vb@251
   934
        PEP_SESSION session,
vb@251
   935
        const char *fpr,
vb@251
   936
        PEP_comm_type *comm_type
vb@251
   937
    )
vb@251
   938
{
vb@251
   939
    PEP_STATUS status = PEP_STATUS_OK;
vb@251
   940
    int result;
vb@251
   941
vb@251
   942
    assert(session);
vb@251
   943
    assert(fpr);
vb@251
   944
    assert(comm_type);
vb@251
   945
vb@251
   946
    if (!(session && fpr && comm_type))
vb@251
   947
        return PEP_ILLEGAL_VALUE;
vb@251
   948
vb@632
   949
    *comm_type = PEP_ct_unknown;
vb@632
   950
vb@251
   951
    sqlite3_reset(session->least_trust);
vb@251
   952
    sqlite3_bind_text(session->least_trust, 1, fpr, -1, SQLITE_STATIC);
vb@251
   953
vb@251
   954
    result = sqlite3_step(session->least_trust);
vb@251
   955
    switch (result) {
vb@251
   956
        case SQLITE_ROW: {
vb@259
   957
            int _comm_type = sqlite3_column_int(session->least_trust, 0);
vb@259
   958
            *comm_type = (PEP_comm_type) _comm_type;
vb@251
   959
            break;
vb@251
   960
        }
vb@251
   961
        default:
vb@251
   962
            status = PEP_CANNOT_FIND_IDENTITY;
vb@251
   963
    }
vb@251
   964
vb@251
   965
    sqlite3_reset(session->least_trust);
vb@251
   966
    return status;
vb@251
   967
}
vb@251
   968
vb@24
   969
DYNAMIC_API PEP_STATUS decrypt_and_verify(
vb@24
   970
    PEP_SESSION session, const char *ctext, size_t csize,
vb@24
   971
    char **ptext, size_t *psize, stringlist_t **keylist
vb@24
   972
    )
vb@24
   973
{
vb@191
   974
    assert(session);
vb@191
   975
    assert(ctext);
vb@191
   976
    assert(csize);
vb@191
   977
    assert(ptext);
vb@191
   978
    assert(psize);
vb@191
   979
    assert(keylist);
vb@191
   980
vb@191
   981
    if (!(session && ctext && csize && ptext && psize && keylist && keylist))
vb@191
   982
        return PEP_ILLEGAL_VALUE;
vb@191
   983
vb@46
   984
    return session->cryptotech[PEP_crypt_OpenPGP].decrypt_and_verify(session, ctext, csize, ptext, psize, keylist);
vb@24
   985
}
vb@24
   986
vb@24
   987
DYNAMIC_API PEP_STATUS encrypt_and_sign(
vb@24
   988
    PEP_SESSION session, const stringlist_t *keylist, const char *ptext,
vb@24
   989
    size_t psize, char **ctext, size_t *csize
vb@24
   990
    )
vb@24
   991
{
vb@191
   992
    assert(session);
vb@191
   993
    assert(keylist);
vb@191
   994
    assert(ptext);
vb@191
   995
    assert(psize);
vb@191
   996
    assert(ctext);
vb@191
   997
    assert(csize);
vb@191
   998
vb@191
   999
    if (!(session && keylist && ptext && psize && ctext && csize))
vb@191
  1000
        return PEP_ILLEGAL_VALUE;
vb@191
  1001
vb@46
  1002
    return session->cryptotech[PEP_crypt_OpenPGP].encrypt_and_sign(session, keylist, ptext, psize, ctext, csize);
vb@24
  1003
}
vb@24
  1004
vb@24
  1005
DYNAMIC_API PEP_STATUS verify_text(
vb@24
  1006
    PEP_SESSION session, const char *text, size_t size,
vb@24
  1007
    const char *signature, size_t sig_size, stringlist_t **keylist
vb@24
  1008
    )
vb@24
  1009
{
vb@191
  1010
    assert(session);
vb@191
  1011
    assert(text);
vb@191
  1012
    assert(size);
vb@191
  1013
    assert(signature);
vb@191
  1014
    assert(sig_size);
vb@191
  1015
    assert(keylist);
vb@191
  1016
vb@191
  1017
    if (!(session && text && size && signature && sig_size && keylist))
vb@191
  1018
        return PEP_ILLEGAL_VALUE;
vb@191
  1019
vb@46
  1020
    return session->cryptotech[PEP_crypt_OpenPGP].verify_text(session, text, size, signature, sig_size, keylist);
vb@24
  1021
}
vb@24
  1022
vb@24
  1023
DYNAMIC_API PEP_STATUS delete_keypair(PEP_SESSION session, const char *fpr)
vb@24
  1024
{
vb@191
  1025
    assert(session);
vb@191
  1026
    assert(fpr);
vb@191
  1027
vb@191
  1028
    if (!(session && fpr))
vb@191
  1029
        return PEP_ILLEGAL_VALUE;
vb@191
  1030
vb@46
  1031
    return session->cryptotech[PEP_crypt_OpenPGP].delete_keypair(session, fpr);
vb@24
  1032
}
vb@24
  1033
vb@24
  1034
DYNAMIC_API PEP_STATUS export_key(
vb@46
  1035
        PEP_SESSION session, const char *fpr, char **key_data, size_t *size
vb@24
  1036
    )
vb@24
  1037
{
vb@191
  1038
    assert(session);
vb@191
  1039
    assert(fpr);
vb@191
  1040
    assert(key_data);
vb@191
  1041
    assert(size);
vb@191
  1042
vb@191
  1043
    if (!(session && fpr && key_data && size))
vb@191
  1044
        return PEP_ILLEGAL_VALUE;
vb@191
  1045
vb@46
  1046
    return session->cryptotech[PEP_crypt_OpenPGP].export_key(session, fpr, key_data, size);
vb@24
  1047
}
vb@24
  1048
vb@24
  1049
DYNAMIC_API PEP_STATUS find_keys(
vb@46
  1050
        PEP_SESSION session, const char *pattern, stringlist_t **keylist
vb@24
  1051
    )
vb@24
  1052
{
vb@191
  1053
    assert(session);
vb@191
  1054
    assert(pattern);
vb@191
  1055
    assert(keylist);
vb@191
  1056
vb@191
  1057
    if (!(session && pattern && keylist))
vb@191
  1058
        return PEP_ILLEGAL_VALUE;
vb@191
  1059
vb@46
  1060
    return session->cryptotech[PEP_crypt_OpenPGP].find_keys(session, pattern, keylist);
vb@24
  1061
}
vb@24
  1062
vb@24
  1063
DYNAMIC_API PEP_STATUS generate_keypair(
vb@46
  1064
        PEP_SESSION session, pEp_identity *identity
vb@24
  1065
    )
vb@24
  1066
{
vb@191
  1067
    assert(session);
vb@191
  1068
    assert(identity);
vb@191
  1069
    assert(identity->address);
vb@298
  1070
    assert(identity->fpr == NULL || identity->fpr[0] == 0);
vb@191
  1071
    assert(identity->username);
vb@191
  1072
vb@298
  1073
    if (!(session && identity && identity->address &&
vb@298
  1074
        (identity->fpr == NULL || identity->fpr[0] == 0) && identity->username))
vb@191
  1075
        return PEP_ILLEGAL_VALUE;
vb@191
  1076
vb@46
  1077
    return session->cryptotech[PEP_crypt_OpenPGP].generate_keypair(session, identity);
vb@24
  1078
}
vb@24
  1079
vb@9
  1080
DYNAMIC_API PEP_STATUS get_key_rating(
vb@46
  1081
        PEP_SESSION session,
vb@46
  1082
        const char *fpr,
vb@46
  1083
        PEP_comm_type *comm_type
vb@9
  1084
    )
vb@9
  1085
{
vb@191
  1086
    assert(session);
vb@191
  1087
    assert(fpr);
vb@191
  1088
    assert(comm_type);
vb@191
  1089
vb@191
  1090
    if (!(session && fpr && comm_type))
vb@191
  1091
        return PEP_ILLEGAL_VALUE;
vb@191
  1092
vb@46
  1093
    return session->cryptotech[PEP_crypt_OpenPGP].get_key_rating(session, fpr, comm_type);
vb@24
  1094
}
vb@9
  1095
vb@24
  1096
DYNAMIC_API PEP_STATUS import_key(PEP_SESSION session, const char *key_data, size_t size)
vb@24
  1097
{
vb@191
  1098
    assert(session);
vb@191
  1099
    assert(key_data);
vb@191
  1100
vb@191
  1101
    if (!(session && key_data))
vb@191
  1102
        return PEP_ILLEGAL_VALUE;
vb@191
  1103
vb@46
  1104
    return session->cryptotech[PEP_crypt_OpenPGP].import_key(session, key_data, size);
vb@24
  1105
}
vb@9
  1106
vb@24
  1107
DYNAMIC_API PEP_STATUS recv_key(PEP_SESSION session, const char *pattern)
vb@24
  1108
{
vb@191
  1109
    assert(session);
vb@191
  1110
    assert(pattern);
vb@191
  1111
vb@191
  1112
    if (!(session && pattern))
vb@191
  1113
        return PEP_ILLEGAL_VALUE;
vb@191
  1114
vb@46
  1115
    return session->cryptotech[PEP_crypt_OpenPGP].recv_key(session, pattern);
vb@24
  1116
}
vb@9
  1117
vb@24
  1118
DYNAMIC_API PEP_STATUS send_key(PEP_SESSION session, const char *pattern)
vb@24
  1119
{
vb@191
  1120
    assert(session);
vb@191
  1121
    assert(pattern);
vb@191
  1122
vb@191
  1123
    if (!(session && pattern))
vb@191
  1124
        return PEP_ILLEGAL_VALUE;
vb@191
  1125
vb@46
  1126
    return session->cryptotech[PEP_crypt_OpenPGP].send_key(session, pattern);
vb@14
  1127
}
vb@196
  1128
vb@201
  1129
DYNAMIC_API PEP_STATUS renew_key(
vb@201
  1130
        PEP_SESSION session,
vb@201
  1131
        const char *fpr,
vb@201
  1132
        const timestamp *ts
vb@201
  1133
    )
vb@196
  1134
{
vb@196
  1135
    assert(session);
vb@200
  1136
    assert(fpr);
vb@196
  1137
vb@200
  1138
    if (!(session && fpr))
vb@196
  1139
        return PEP_ILLEGAL_VALUE;
vb@196
  1140
vb@201
  1141
    return session->cryptotech[PEP_crypt_OpenPGP].renew_key(session, fpr, ts);
vb@196
  1142
}
vb@196
  1143
vb@211
  1144
DYNAMIC_API PEP_STATUS revoke_key(
vb@211
  1145
        PEP_SESSION session,
vb@211
  1146
        const char *fpr,
vb@211
  1147
        const char *reason
vb@211
  1148
    )
vb@197
  1149
{
vb@197
  1150
    assert(session);
vb@200
  1151
    assert(fpr);
vb@197
  1152
vb@200
  1153
    if (!(session && fpr))
vb@197
  1154
        return PEP_ILLEGAL_VALUE;
vb@197
  1155
vb@214
  1156
    return session->cryptotech[PEP_crypt_OpenPGP].revoke_key(session, fpr,
vb@214
  1157
            reason);
vb@197
  1158
}
vb@197
  1159
vb@214
  1160
DYNAMIC_API PEP_STATUS key_expired(
vb@214
  1161
        PEP_SESSION session,
vb@214
  1162
        const char *fpr,
vb@214
  1163
        bool *expired
vb@214
  1164
    )
vb@214
  1165
{
vb@214
  1166
    assert(session);
vb@214
  1167
    assert(fpr);
vb@214
  1168
    assert(expired);
vb@214
  1169
vb@214
  1170
    if (!(session && fpr && expired))
vb@214
  1171
        return PEP_ILLEGAL_VALUE;
vb@214
  1172
vb@214
  1173
    return session->cryptotech[PEP_crypt_OpenPGP].key_expired(session, fpr,
vb@214
  1174
            expired);
vb@214
  1175
}
vb@214
  1176
vb@451
  1177
static void _clean_log_value(char *text)
vb@451
  1178
{
vb@451
  1179
    if (text) {
vb@451
  1180
        for (char *c = text; *c; c++) {
vb@451
  1181
            if (*c < 32)
vb@451
  1182
                *c = 32;
vb@451
  1183
            else if (*c == '"')
vb@451
  1184
                *c = '\'';
vb@451
  1185
        }
vb@451
  1186
    }
vb@451
  1187
}
vb@451
  1188
vb@450
  1189
static char *_concat_string(char *str1, const char *str2, char delim)
vb@450
  1190
{
vb@454
  1191
    str2 = str2 ? str2 : "";
vb@450
  1192
    size_t len1 = str1 ? strlen(str1) : 0;
vb@450
  1193
    size_t len2 = strlen(str2);
vb@450
  1194
    size_t len = len1 + len2 + 3;
vb@450
  1195
    char * result = realloc(str1, len + 1);
vb@450
  1196
vb@450
  1197
    if (result) {
vb@450
  1198
        result[len1] = '"';
vb@450
  1199
        strcpy(result + len1 + 1, str2);
vb@450
  1200
        _clean_log_value(result + len1 + 1);
vb@450
  1201
        result[len - 2] = '"';
vb@450
  1202
        result[len - 1] = delim;
vb@450
  1203
        result[len] = 0;
vb@450
  1204
    }
vb@450
  1205
    else {
vb@450
  1206
        free(str1);
vb@450
  1207
    }
vb@450
  1208
vb@450
  1209
    return result;
vb@450
  1210
}
vb@450
  1211
vb@450
  1212
DYNAMIC_API PEP_STATUS get_crashdump_log(
vb@450
  1213
        PEP_SESSION session,
vb@450
  1214
        int maxlines,
vb@450
  1215
        char **logdata
vb@450
  1216
    )
vb@450
  1217
{
vb@450
  1218
    PEP_STATUS status = PEP_STATUS_OK;
vb@450
  1219
    char *_logdata= NULL;
vb@450
  1220
vb@450
  1221
    assert(session);
vb@450
  1222
    assert(maxlines >= 0 && maxlines <= CRASHDUMP_MAX_LINES);
vb@450
  1223
    assert(logdata);
vb@450
  1224
vb@450
  1225
    if (!(session && logdata && maxlines >= 0 && maxlines <=
vb@450
  1226
            CRASHDUMP_MAX_LINES))
vb@450
  1227
        return PEP_ILLEGAL_VALUE;
vb@450
  1228
vb@632
  1229
    *logdata = NULL;
vb@632
  1230
vb@450
  1231
    int limit = maxlines ? maxlines : CRASHDUMP_DEFAULT_LINES;
vb@458
  1232
    const char *timestamp = NULL;
vb@458
  1233
    const char *title = NULL;
vb@458
  1234
    const char *entity = NULL;
vb@458
  1235
    const char *desc = NULL;
vb@458
  1236
    const char *comment = NULL;
vb@450
  1237
vb@450
  1238
    sqlite3_reset(session->crashdump);
vb@452
  1239
    sqlite3_bind_int(session->crashdump, 1, limit);
vb@450
  1240
vb@450
  1241
    int result;
vb@450
  1242
vb@450
  1243
    do {
vb@450
  1244
        result = sqlite3_step(session->crashdump);
vb@450
  1245
        switch (result) {
vb@450
  1246
        case SQLITE_ROW:
vb@452
  1247
            timestamp = (const char *) sqlite3_column_text(session->crashdump, 0);
vb@452
  1248
            title   = (const char *) sqlite3_column_text(session->crashdump, 1);
vb@452
  1249
            entity  = (const char *) sqlite3_column_text(session->crashdump, 2);
vb@452
  1250
            desc    = (const char *) sqlite3_column_text(session->crashdump, 3);
vb@452
  1251
            comment = (const char *) sqlite3_column_text(session->crashdump, 4);
vb@452
  1252
vb@452
  1253
            _logdata = _concat_string(_logdata, timestamp, ',');
vb@452
  1254
            if (_logdata == NULL)
vb@452
  1255
                goto enomem;
vb@450
  1256
vb@450
  1257
            _logdata = _concat_string(_logdata, title, ',');
vb@450
  1258
            if (_logdata == NULL)
vb@450
  1259
                goto enomem;
vb@450
  1260
vb@450
  1261
            _logdata = _concat_string(_logdata, entity, ',');
vb@450
  1262
            if (_logdata == NULL)
vb@450
  1263
                goto enomem;
vb@450
  1264
vb@450
  1265
            _logdata = _concat_string(_logdata, desc, ',');
vb@450
  1266
            if (_logdata == NULL)
vb@450
  1267
                goto enomem;
vb@450
  1268
vb@450
  1269
            _logdata = _concat_string(_logdata, comment, '\n');
vb@450
  1270
            if (_logdata == NULL)
vb@450
  1271
                goto enomem;
vb@450
  1272
vb@450
  1273
            break;
vb@450
  1274
vb@450
  1275
        case SQLITE_DONE:
vb@450
  1276
            break;
vb@450
  1277
vb@450
  1278
        default:
vb@450
  1279
            status = PEP_UNKNOWN_ERROR;
vb@450
  1280
            result = SQLITE_DONE;
vb@450
  1281
        }
vb@450
  1282
    } while (result != SQLITE_DONE);
vb@450
  1283
vb@450
  1284
    sqlite3_reset(session->crashdump);
vb@450
  1285
    if (status == PEP_STATUS_OK)
vb@450
  1286
        *logdata = _logdata;
vb@450
  1287
vb@450
  1288
    goto the_end;
vb@450
  1289
vb@450
  1290
enomem:
vb@450
  1291
    status = PEP_OUT_OF_MEMORY;
vb@450
  1292
vb@450
  1293
the_end:
vb@450
  1294
    return status;
vb@450
  1295
}
vb@450
  1296
vb@458
  1297
DYNAMIC_API PEP_STATUS get_languagelist(
vb@458
  1298
        PEP_SESSION session,
vb@458
  1299
        char **languages
vb@458
  1300
    )
vb@458
  1301
{
vb@458
  1302
    PEP_STATUS status = PEP_STATUS_OK;
vb@458
  1303
    char *_languages= NULL;
vb@458
  1304
vb@458
  1305
    assert(session);
vb@458
  1306
    assert(languages);
vb@458
  1307
vb@458
  1308
    if (!(session && languages))
vb@458
  1309
        return PEP_ILLEGAL_VALUE;
vb@458
  1310
vb@632
  1311
    *languages = NULL;
vb@632
  1312
vb@458
  1313
    const char *lang = NULL;
vb@458
  1314
    const char *name = NULL;
vb@617
  1315
    const char *phrase = NULL;
vb@458
  1316
vb@458
  1317
    sqlite3_reset(session->languagelist);
vb@458
  1318
vb@458
  1319
    int result;
vb@458
  1320
vb@458
  1321
    do {
vb@458
  1322
        result = sqlite3_step(session->languagelist);
vb@458
  1323
        switch (result) {
vb@458
  1324
        case SQLITE_ROW:
vb@458
  1325
            lang = (const char *) sqlite3_column_text(session->languagelist, 0);
vb@458
  1326
            name = (const char *) sqlite3_column_text(session->languagelist, 1);
vb@617
  1327
            phrase = (const char *) sqlite3_column_text(session->languagelist, 2);
vb@458
  1328
vb@458
  1329
            _languages = _concat_string(_languages, lang, ',');
vb@458
  1330
            if (_languages == NULL)
vb@458
  1331
                goto enomem;
vb@458
  1332
vb@617
  1333
            _languages = _concat_string(_languages, name, ',');
vb@617
  1334
            if (_languages == NULL)
vb@617
  1335
                goto enomem;
vb@617
  1336
vb@617
  1337
            _languages = _concat_string(_languages, phrase, '\n');
vb@458
  1338
            if (_languages == NULL)
vb@458
  1339
                goto enomem;
vb@458
  1340
vb@458
  1341
            break;
vb@458
  1342
vb@458
  1343
        case SQLITE_DONE:
vb@458
  1344
            break;
vb@458
  1345
vb@458
  1346
        default:
vb@458
  1347
            status = PEP_UNKNOWN_ERROR;
vb@458
  1348
            result = SQLITE_DONE;
vb@458
  1349
        }
vb@458
  1350
    } while (result != SQLITE_DONE);
vb@458
  1351
vb@458
  1352
    sqlite3_reset(session->languagelist);
vb@458
  1353
    if (status == PEP_STATUS_OK)
vb@458
  1354
        *languages = _languages;
vb@458
  1355
vb@458
  1356
    goto the_end;
vb@458
  1357
vb@458
  1358
enomem:
vb@458
  1359
    status = PEP_OUT_OF_MEMORY;
vb@458
  1360
vb@458
  1361
the_end:
vb@458
  1362
    return status;
vb@458
  1363
}
vb@458
  1364
vb@458
  1365
DYNAMIC_API PEP_STATUS get_phrase(
vb@458
  1366
        PEP_SESSION session,
vb@458
  1367
        const char *lang,
vb@458
  1368
        int phrase_id,
vb@458
  1369
        char **phrase
vb@458
  1370
    )
vb@458
  1371
{
vb@458
  1372
    PEP_STATUS status = PEP_STATUS_OK;
vb@458
  1373
vb@479
  1374
    assert(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase);
vb@479
  1375
    if (!(session && lang && lang[0] && lang[1] && lang[2] == 0 && phrase))
vb@458
  1376
        return PEP_ILLEGAL_VALUE;
vb@458
  1377
vb@632
  1378
    *phrase = NULL;
vb@632
  1379
vb@458
  1380
    sqlite3_reset(session->i18n_token);
roker@529
  1381
    sqlite3_bind_text(session->i18n_token, 1, lang, -1, SQLITE_STATIC);
roker@529
  1382
    sqlite3_bind_int(session->i18n_token, 2, phrase_id);
vb@458
  1383
vb@458
  1384
    const char *_phrase = NULL;
vb@458
  1385
    int result;
vb@458
  1386
vb@458
  1387
    result = sqlite3_step(session->i18n_token);
vb@458
  1388
    switch (result) {
vb@458
  1389
    case SQLITE_ROW:
vb@458
  1390
        _phrase = (const char *) sqlite3_column_text(session->i18n_token, 0);
vb@458
  1391
        break;
vb@458
  1392
vb@458
  1393
    case SQLITE_DONE:
vb@458
  1394
        status = PEP_PHRASE_NOT_FOUND;
vb@458
  1395
        break;
vb@458
  1396
vb@458
  1397
    default:
vb@458
  1398
        status = PEP_UNKNOWN_ERROR;
vb@458
  1399
    }
vb@458
  1400
vb@458
  1401
    if (status == PEP_STATUS_OK) {
vb@458
  1402
        *phrase = strdup(_phrase);
vb@458
  1403
        if (*phrase == NULL)
vb@458
  1404
            goto enomem;
vb@458
  1405
    }
vb@459
  1406
vb@459
  1407
    sqlite3_reset(session->i18n_token);
vb@458
  1408
    goto the_end;
vb@458
  1409
vb@458
  1410
enomem:
vb@458
  1411
    status = PEP_OUT_OF_MEMORY;
vb@458
  1412
vb@458
  1413
the_end:
vb@458
  1414
    return status;
vb@458
  1415
}
vb@458
  1416
vb@632
  1417
DYNAMIC_API PEP_STATUS sequence_value(
vb@632
  1418
        PEP_SESSION session,
vb@632
  1419
        const char *name,
vb@632
  1420
        int64_t *value
vb@632
  1421
    )
vb@632
  1422
{
vb@632
  1423
    PEP_STATUS status = PEP_STATUS_OK;
vb@632
  1424
    int result;
vb@632
  1425
vb@632
  1426
    assert(session);
vb@632
  1427
    assert(name);
vb@632
  1428
    assert(value);
vb@632
  1429
vb@632
  1430
    if (!(session && name && value))
vb@632
  1431
        return PEP_ILLEGAL_VALUE;
vb@632
  1432
vb@632
  1433
    *value = 0;
vb@632
  1434
vb@632
  1435
    sqlite3_reset(session->sequence_value);
vb@632
  1436
    sqlite3_bind_text(session->sequence_value, 1, name, -1, SQLITE_STATIC);
vb@632
  1437
vb@632
  1438
    result = sqlite3_step(session->sequence_value);
vb@632
  1439
    switch (result) {
vb@632
  1440
        case SQLITE_ROW: {
vb@632
  1441
            int64_t _value = (int64_t)
vb@632
  1442
                    sqlite3_column_int64(session->sequence_value, 0);
vb@632
  1443
            *value = _value;
vb@632
  1444
            break;
vb@632
  1445
        }
vb@632
  1446
        default:
vb@632
  1447
            status = PEP_CANNOT_FIND_IDENTITY;
vb@632
  1448
    }
vb@632
  1449
vb@632
  1450
    sqlite3_reset(session->sequence_value);
vb@632
  1451
    return status;
vb@632
  1452
}
vb@632
  1453
vb@482
  1454
DYNAMIC_API PEP_STATUS reset_peptest_hack(PEP_SESSION session)
vb@482
  1455
{
vb@482
  1456
    assert(session);
vb@482
  1457
vb@482
  1458
    if (!session)
vb@482
  1459
        return PEP_ILLEGAL_VALUE;
vb@482
  1460
fdik@494
  1461
    int int_result = sqlite3_exec(
fdik@494
  1462
        session->db,
fdik@494
  1463
        "delete from identity where address like '%@peptest.ch' ;",
fdik@494
  1464
        NULL,
fdik@494
  1465
        NULL,
fdik@494
  1466
        NULL
fdik@494
  1467
    );
fdik@494
  1468
    assert(int_result == SQLITE_OK);
vb@482
  1469
fdik@494
  1470
    return PEP_STATUS_OK;
vb@482
  1471
}
vb@482
  1472