OpenDNSSEC-enforcer  1.4.1
ksm_import.c
Go to the documentation of this file.
1 /*
2  * $Id: ksm_import.c 7028 2013-02-13 11:41:17Z sion $
3  *
4  * Copyright (c) 2008-2009 Nominet UK. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 /*
30  * ksm_import.c - Import/update configuration data in kasp database
31  */
32 
33 #include <assert.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <time.h>
38 
39 #include "ksm/database.h"
40 #include "ksm/database_statement.h"
41 #include "ksm/datetime.h"
42 #include "ksm/db_fields.h"
43 #include "ksm/debug.h"
44 #include "ksm/ksmdef.h"
45 #include "ksm/ksm.h"
46 #include "ksm/ksm_internal.h"
47 #include "ksm/message.h"
48 #include "ksm/string_util.h"
49 #include "ksm/string_util2.h"
50 
51 /*+
52  * KsmImportRepository - Insert or update a repository
53  *
54  *
55  * Arguments:
56  *
57  * const char* repo_name
58  * Name of the repository
59  *
60  * const char* repo_capacity
61  * Capacity for that repository
62  *
63  * int require_backup
64  * flag to indicate if keys in this repo need to be backed up before they can be used
65  *
66  * Returns:
67  * int
68  * Status return. 0 on success.
69  * -1 if an unexpected count value was returned
70 -*/
71 
72 int KsmImportRepository(const char* repo_name, const char* repo_capacity, int require_backup)
73 {
74  char* sql = NULL; /* SQL query */
75  int status = 0; /* Status return */
76  int count = 0; /* Do we already have a repository with this name? */
77 
78  /* check the main argument (capacity may be NULL) */
79  if (repo_name == NULL) {
80  return MsgLog(KSM_INVARG, "NULL repository name");
81  }
82 
83  /*
84  * First see if this repository exists
85  */
87  DqsConditionString(&sql, "NAME", DQS_COMPARE_EQ, repo_name, 0);
88  DqsEnd(&sql);
89 
90  /* Execute query and free up the query string */
91  status = DbIntQuery(DbHandle(), &count, sql);
92  DqsFree(sql);
93 
94  if (status != 0)
95  {
96  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
97  return status;
98  }
99 
100  /* If the count was 0 then we do an insert, otherwise we do an update */
101  if (count == 0)
102  {
103  sql = DisSpecifyInit(DB_SECURITY_MODULE_TABLE, "name, capacity, requirebackup");
104  DisAppendString(&sql, repo_name);
105  DisAppendString(&sql, repo_capacity);
106  DisAppendInt(&sql, require_backup);
107  DisEnd(&sql);
108 
109  status = DbExecuteSqlNoResult(DbHandle(), sql);
110  DisFree(sql);
111  }
112  else if (count == 1)
113  {
115  DusSetString(&sql, "capacity", repo_capacity, 0);
116  DusSetInt(&sql, "requirebackup", require_backup, 1);
117  DusConditionString(&sql, "name", DQS_COMPARE_EQ, repo_name, 0);
118  DusEnd(&sql);
119 
120  status = DbExecuteSqlNoResult(DbHandle(), sql);
121  DusFree(sql);
122  }
123  else
124  {
125  return -1;
126  }
127 
128  return status;
129 }
130 
131 /*+
132  * KsmImportPolicy - Insert a policy (will not be called if policy exists, unlike above
133  *
134  *
135  * Arguments:
136  *
137  * const char* policy_name
138  * Name of the policy
139  *
140  * const char* policy_description
141  * Description for that policy
142  *
143  * Returns:
144  * int
145  * Status return. 0 on success.
146  * -1 if an unexpected count value was returned
147 -*/
148 
149 int KsmImportPolicy(const char* policy_name, const char* policy_description)
150 {
151  char* sql = NULL; /* SQL query */
152  int status = 0; /* Status return */
153 
154  char quoted_desc[KSM_POLICY_DESC_LENGTH]; /* with bad chars quoted */
155 
156  /* check the main argument (description may be NULL) */
157  if (policy_name == NULL) {
158  return MsgLog(KSM_INVARG, "NULL policy name");
159  }
160 
161  /* Quote description */
162  status = DbQuoteString(DbHandle(), policy_description, quoted_desc, KSM_POLICY_DESC_LENGTH);
163 
164  if (status != 0) {
165  return status;
166  }
167 
168  /* Insert policy */
169  sql = DisSpecifyInit("policies", "name, description");
170  DisAppendString(&sql, policy_name);
171  DisAppendString(&sql, quoted_desc);
172  DisEnd(&sql);
173 
174  status = DbExecuteSqlNoResult(DbHandle(), sql);
175  DisFree(sql);
176 
177  return status;
178 }
179 
180 /*+
181  * KsmImportZone - Insert or update a zone
182  *
183  *
184  * Arguments:
185  *
186  * const char* zone_name
187  * Name of the repository
188  *
189  * int policy_id
190  * Policy for the zone
191  *
192  * int fail_if_exists
193  * Set to 1 if you don't want to update existing zones
194  *
195  * int *new_zone
196  * (returned) indicate if the zone was new to the database
197  *
198  * const char* signconf
199  * Where is the signconf saved
200  *
201  * const char* input
202  * Where is the input
203  *
204  * const char* output
205  * Where is the output
206  *
207  * const char* input_type
208  * What adapter type is the input
209  *
210  * const char* output_type
211  * What adapter type is the output
212  *
213  * Returns:
214  * int
215  * Status return. 0 on success.
216  * -1 if an unexpected count value was returned
217  * -2 if the zone exists and fail_if_exists == 1
218  * -3 if the zone exists with and without a trailing dot
219 -*/
220 int KsmImportZone(const char* zone_name, int policy_id, int fail_if_exists, int *new_zone, const char* signconf, const char* input, const char* output, const char* input_type, const char* output_type)
221 {
222  char* sql = NULL; /* SQL query */
223  int status = 0; /* Status return */
224  int count = 0; /* Do we already have a zone with this name? */
225  char* zone_name_td = NULL; /* zone name with td swapped */
226  char in_clause[KSM_SQL_SIZE]; /* in part of where clause */
227 
228  /* check the arguments */
229  if (zone_name == NULL || policy_id == 0) {
230  return MsgLog(KSM_INVARG, "NULL zone name or policy");
231  }
232 
233  /* make copy of zone_name with opposite td to original (unless original is
234  "."; in which case the copy is identical */
235  zone_name_td = StrStrdup(zone_name);
236  if (strlen(zone_name_td) > 1 && zone_name_td[strlen(zone_name_td)-1] == '.') {
237  zone_name_td[strlen(zone_name_td)-1] = '\0';
238  }
239  else if (strlen(zone_name_td) > 1) {
240  StrAppend(&zone_name_td, ".");
241  }
242 
243  snprintf(in_clause, KSM_SQL_SIZE, "(\"%s\",\"%s\")", zone_name, zone_name_td);
244 
245  /*
246  * First see if this zone exists
247  */
249  DqsConditionKeyword(&sql, "NAME", DQS_COMPARE_IN, in_clause, 0);
250  DqsEnd(&sql);
251 
252  /* Execute query and free up the query string */
253  status = DbIntQuery(DbHandle(), &count, sql);
254  DqsFree(sql);
255 
256  if (status != 0)
257  {
258  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
259  return status;
260  }
261 
262  /* If the count was 0 then we do an insert, otherwise we do an update */
263  if (count == 0)
264  {
265  sql = DisSpecifyInit(DB_ZONE_TABLE, "name, policy_id, signconf, input, output, in_type, out_type");
266  DisAppendString(&sql, zone_name);
267  DisAppendInt(&sql, policy_id);
268  DisAppendString(&sql, signconf);
269  DisAppendString(&sql, input);
270  DisAppendString(&sql, output);
271  DisAppendString(&sql, input_type);
272  DisAppendString(&sql, output_type);
273  DisEnd(&sql);
274 
275  status = DbExecuteSqlNoResult(DbHandle(), sql);
276  DisFree(sql);
277 
278  *new_zone = 1;
279  }
280  else if (count == 1)
281  {
282  if (fail_if_exists == 1) {
283  return -2;
284  }
285  sql = DusInit(DB_ZONE_TABLE);
286  DusSetInt(&sql, "policy_id", policy_id, 0);
287  DusSetString(&sql, "signconf", signconf, 1);
288  DusSetString(&sql, "input", input, 2);
289  DusSetString(&sql, "output", output, 3);
290  DusSetString(&sql, "in_type", input_type, 4);
291  DusSetString(&sql, "out_type", output_type, 5);
292  DusConditionString(&sql, "name", DQS_COMPARE_EQ, zone_name, 0);
293  DusEnd(&sql);
294 
295  status = DbExecuteSqlNoResult(DbHandle(), sql);
296  DusFree(sql);
297 
298  *new_zone = 0;
299  }
300  else if (count == 2)
301  {
302  return -3;
303  }
304  else
305  {
306  return -1;
307  }
308 
309  StrFree(zone_name_td);
310 
311  return status;
312 }
313 
314 /*+
315  * KsmImportKeyPair - Create Entry in the KeyPairs table for an existing key
316  *
317  * Description:
318  * Creates a key in the database. If the retire time is set then it is marked as
319  * fixed (I.e. it will not be changed to fit the policy timings.)
320  *
321  * Arguments:
322  * policy_id
323  * policy that the key is created for
324  * HSMKeyID
325  * ID the key is refered to in the HSM
326  * smID
327  * security module ID
328  * size
329  * size of key
330  * alg
331  * algorithm used
332  * state
333  * state to set key to
334  * time
335  * timestamp of entry into state given
336  * fixDate
337  * set to 1 if the retire date should be fixed
338  *
339  * DB_ID* id (returned)
340  * ID of the created entry. This will be undefined on error.
341  *
342  * Returns:
343  * int
344  * Status return. 0=> Success, non-zero => error.
345 -*/
346 int KsmImportKeyPair(int policy_id, const char* HSMKeyID, int smID, int size, int alg, int state, const char* time, int fixDate, DB_ID* id)
347 {
348  unsigned long rowid; /* ID of last inserted row */
349  int status = 0; /* Status return */
350  char* sql = NULL; /* SQL Statement */
351  char* columns = NULL; /* what columns are we setting */
352 
353  /* Check arguments */
354  if (id == NULL) {
355  return MsgLog(KSM_INVARG, "NULL id");
356  }
357 
358  StrAppend(&columns, "policy_id, HSMkey_id, securitymodule_id, size, algorithm");
359  if (state == KSM_STATE_GENERATE) {
360  StrAppend(&columns, ", ");
361  StrAppend(&columns, KsmKeywordStateValueToName(state));
362  }
363  if (state == KSM_STATE_ACTIVE && fixDate == 1) {
364  StrAppend(&columns, ", fixedDate");
365  }
366 
367  sql = DisSpecifyInit("keypairs", columns);
368  DisAppendInt(&sql, policy_id);
369  DisAppendString(&sql, HSMKeyID);
370  DisAppendInt(&sql, smID);
371  DisAppendInt(&sql, size);
372  DisAppendInt(&sql, alg);
373  if (state == KSM_STATE_GENERATE) {
374  DisAppendString(&sql, time);
375  }
376  if (state == KSM_STATE_ACTIVE && fixDate == 1) {
377  DisAppendInt(&sql, fixDate);
378  }
379  DisEnd(&sql);
380 
381  /* Execute the statement */
382 
383  status = DbExecuteSqlNoResult(DbHandle(), sql);
384  DisFree(sql);
385  StrFree(columns);
386 
387  if (status == 0) {
388 
389  /* Succcess, get the ID of the inserted record */
390 
391  status = DbLastRowId(DbHandle(), &rowid);
392  if (status == 0) {
393  *id = (DB_ID) rowid;
394  }
395  }
396 
397  return status;
398 }
399 
400 int KsmSmIdFromName(const char* name, int *id)
401 {
402  char* sql = NULL; /* SQL query */
403  int status = 0; /* Status return */
404 
405  /* check the argument */
406  if (name == NULL) {
407  return MsgLog(KSM_INVARG, "NULL name");
408  }
409 
410  /* Construct the query */
411 
413  DqsConditionString(&sql, "name", DQS_COMPARE_EQ, name, 0);
414  DqsEnd(&sql);
415 
416  /* Execute query and free up the query string */
417  status = DbIntQuery(DbHandle(), id, sql);
418  DqsFree(sql);
419 
420  if (status != 0)
421  {
422  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
423  return status;
424  }
425 
426  return status;
427 }
428 
429 int KsmSerialIdFromName(const char* name, int *id)
430 {
431  char* sql = NULL; /* SQL query */
432  int status = 0; /* Status return */
433 
434  /* check the argument */
435  if (name == NULL) {
436  return MsgLog(KSM_INVARG, "NULL name");
437  }
438 
439  /* Construct the query */
440 
441  sql = DqsSpecifyInit("serialmodes","id");
442  DqsConditionString(&sql, "name", DQS_COMPARE_EQ, name, 0);
443  DqsEnd(&sql);
444 
445  /* Execute query and free up the query string */
446  status = DbIntQuery(DbHandle(), id, sql);
447  DqsFree(sql);
448 
449  if (status != 0)
450  {
451  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
452  return status;
453  }
454 
455  return status;
456 }
457 
458 /*+
459  * KsmPolicyIdFromName - Given a policy name return the id
460  *
461  *
462  * Arguments:
463  *
464  * Name of the policy.
465  *
466  *
467  * Returns:
468  * int
469  * 0 Success, value found
470  * Other Error
471 -*/
472 int KsmPolicyIdFromName(const char* name, int *id)
473 {
474  char* sql = NULL; /* SQL query */
475  int status = 0; /* Status return */
476 
477  /* check the argument */
478  if (name == NULL) {
479  return MsgLog(KSM_INVARG, "NULL name");
480  }
481 
482  /* Construct the query */
483 
484  sql = DqsSpecifyInit("policies","id");
485  DqsConditionString(&sql, "name", DQS_COMPARE_EQ, name, 0);
486  DqsEnd(&sql);
487 
488  /* Execute query and free up the query string */
489  status = DbIntQuery(DbHandle(), id, sql);
490  DqsFree(sql);
491 
492  if (status != 0)
493  {
494  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
495  return status;
496  }
497 
498  return status;
499 }
500 
501 /*+
502  * KsmMarkPreBackup - Mark a backup as having been prepared
503  *
504  *
505  * Arguments:
506  *
507  * int repo_id
508  * ID of the repository (-1 for all)
509  *
510  * const char* datetime
511  * When the pre backup was done
512  *
513  * Returns:
514  * int
515  * Status return. 0 on success.
516  * other on fail
517  */
518 
519 int KsmMarkPreBackup(int repo_id, const char* datetime)
520 {
521  char* sql = NULL; /* SQL query */
522  int status = 0; /* Status return */
523  int count = -1; /* How many keys get marked */
524 
525  /* Count how many we will mark */
526  sql = DqsCountInit("keypairs");
527  if (repo_id != -1) {
528  DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
529  StrAppend(&sql, " and pre_backup is null");
530  } else {
531  StrAppend(&sql, " where pre_backup is null");
532  }
533  DqsEnd(&sql);
534 
535  /* Execute query and free up the query string */
536  status = DbIntQuery(DbHandle(), &count, sql);
537  DqsFree(sql);
538 
539  if (status != 0)
540  {
541  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
542  return status;
543  }
544 
545  if (count == 0) {
546  /* No work to do */
547  return -1;
548  }
549 
550  /* Update rows */
551  sql = DusInit("keypairs");
552  DusSetString(&sql, "PRE_BACKUP", datetime, 0);
553  if (repo_id != -1) {
554  DusConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
555  StrAppend(&sql, " and pre_backup is null");
556  } else {
557  StrAppend(&sql, " where pre_backup is null");
558  }
559  DusEnd(&sql);
560 
561  status = DbExecuteSqlNoResult(DbHandle(), sql);
562  DusFree(sql);
563 
564  return status;
565 }
566 
567 /*+
568  * KsmRollbackPreBackup - Rollback a backup prepare step
569  *
570  *
571  * Arguments:
572  *
573  * int repo_id
574  * ID of the repository (-1 for all)
575  *
576  * Returns:
577  * int
578  * Status return. 0 on success.
579  * other on fail
580  */
581 
582 int KsmRollbackMarkPreBackup(int repo_id)
583 {
584  char* sql = NULL; /* SQL query */
585  int status = 0; /* Status return */
586  int count = -1; /* How many keys get marked */
587 
588  /* Count how many we will mark */
589  sql = DqsCountInit("keypairs");
590  if (repo_id != -1) {
591  DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
592  StrAppend(&sql, " and pre_backup is not null");
593  StrAppend(&sql, " and backup is null");
594  } else {
595  StrAppend(&sql, " where pre_backup is not null");
596  StrAppend(&sql, " and backup is null");
597  }
598  DqsEnd(&sql);
599 
600  /* Execute query and free up the query string */
601  status = DbIntQuery(DbHandle(), &count, sql);
602  DqsFree(sql);
603 
604  if (status != 0)
605  {
606  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
607  return status;
608  }
609 
610  if (count == 0) {
611  /* No work to do */
612  return -1;
613  }
614 
615  /* Update rows */
616  sql = DusInit("keypairs");
617  DusSetString(&sql, "PRE_BACKUP", NULL, 0);
618  if (repo_id != -1) {
619  DusConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
620  StrAppend(&sql, " and pre_backup is not null");
621  StrAppend(&sql, " and backup is null");
622  } else {
623  StrAppend(&sql, " where pre_backup is null");
624  StrAppend(&sql, " and backup is null");
625  }
626  DusEnd(&sql);
627 
628  status = DbExecuteSqlNoResult(DbHandle(), sql);
629  DusFree(sql);
630 
631  return status;
632 }
633 
634 /*+
635  * KsmMarkBackup - Mark a backup as having been done
636  *
637  *
638  * Arguments:
639  *
640  * int repo_id
641  * ID of the repository (-1 for all)
642  *
643  * const char* datetime
644  * When the backup was done
645  *
646  * Returns:
647  * int
648  * Status return. 0 on success.
649  * other on fail
650  */
651 
652 int KsmMarkBackup(int repo_id, const char* datetime)
653 {
654  char* sql = NULL; /* SQL query */
655  int status = 0; /* Status return */
656  int count = -1; /* How many keys get marked */
657 
658  /* Count how many we will mark */
659  sql = DqsCountInit("keypairs");
660  if (repo_id != -1) {
661  DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
662  StrAppend(&sql, " and pre_backup is not null");
663  StrAppend(&sql, " and backup is null");
664  } else {
665  StrAppend(&sql, " where pre_backup is not null");
666  StrAppend(&sql, " and backup is null");
667  }
668  DqsEnd(&sql);
669 
670  /* Execute query and free up the query string */
671  status = DbIntQuery(DbHandle(), &count, sql);
672  DqsFree(sql);
673 
674  if (status != 0)
675  {
676  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
677  return status;
678  }
679 
680  if (count == 0) {
681  /* No work to do */
682  return -1;
683  }
684 
685  /* Update rows */
686  sql = DusInit("keypairs");
687  DusSetString(&sql, "BACKUP", datetime, 0);
688  if (repo_id != -1) {
689  DusConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 0);
690  StrAppend(&sql, " and backup is null");
691  StrAppend(&sql, " and pre_backup is not null");
692  } else {
693  StrAppend(&sql, " where backup is null");
694  StrAppend(&sql, " and pre_backup is not null");
695  }
696  DusEnd(&sql);
697 
698  status = DbExecuteSqlNoResult(DbHandle(), sql);
699  DusFree(sql);
700 
701  return status;
702 }
703 
704 /*+
705  * KsmCheckHSMkeyID - Checks if the cka_id exists in the hsm specified
706  *
707  *
708  * Arguments:
709  *
710  * int repo_id
711  * ID of the repository (-1 for all)
712  *
713  * const char* cka_id
714  * ID to look for
715  *
716  * int *exists
717  * Flag to say if the ID exists
718  *
719  * Returns:
720  * int
721  * Status return. 0 on success.
722  * -1 if an unexpected count value was returned
723 -*/
724 
725 int KsmCheckHSMkeyID(int repo_id, const char* cka_id, int *exists)
726 {
727  char* sql = NULL; /* SQL query */
728  int status = 0; /* Status return */
729  int count = 0; /* Do we already have a key with this ID? */
730 
731  /* check the arguments */
732  if (cka_id == NULL) {
733  return MsgLog(KSM_INVARG, "NULL cka_id");
734  }
735 
736  /*
737  * Set up the count
738  */
739  sql = DqsCountInit("keypairs");
740  DqsConditionString(&sql, "HSMkey_id", DQS_COMPARE_EQ, cka_id, 0);
741  if (repo_id != -1) {
742  DqsConditionInt(&sql, "securitymodule_id", DQS_COMPARE_EQ, repo_id, 1);
743  }
744  DqsEnd(&sql);
745 
746  /* Execute query and free up the query string */
747  status = DbIntQuery(DbHandle(), &count, sql);
748  DqsFree(sql);
749 
750  if (status != 0)
751  {
752  status = MsgLog(KSM_SQLFAIL, DbErrmsg(DbHandle()));
753  return status;
754  }
755 
756  if (count > 0) {
757  *exists = 1;
758  }
759  else {
760  *exists = 0;
761  }
762 
763  return 0;
764 }
765 
int KsmCheckHSMkeyID(int repo_id, const char *cka_id, int *exists)
Definition: ksm_import.c:725
#define StrFree(x)
Definition: string_util.h:68
#define KSM_INVARG
Definition: ksmdef.h:68
#define KSM_SQLFAIL
Definition: ksmdef.h:69
char * DqsSpecifyInit(const char *table, const char *fields)
Definition: dq_string.c:119
#define KSM_STATE_ACTIVE
Definition: ksm.h:368
#define DB_SECURITY_MODULE_TABLE
Definition: db_fields.h:92
int KsmMarkPreBackup(int repo_id, const char *datetime)
Definition: ksm_import.c:519
void DusFree(char *sql)
Definition: du_string.c:225
int KsmSerialIdFromName(const char *name, int *id)
Definition: ksm_import.c:429
void DusConditionString(char **query, const char *field, DQS_COMPARISON compare, const char *value, int clause)
Definition: du_string.c:178
void DqsConditionKeyword(char **query, const char *field, DQS_COMPARISON compare, const char *value, int index)
Definition: dq_string.c:253
char * DisSpecifyInit(const char *table, const char *cols)
Definition: di_string.c:101
int KsmImportZone(const char *zone_name, int policy_id, int fail_if_exists, int *new_zone, const char *signconf, const char *input, const char *output, const char *input_type, const char *output_type)
Definition: ksm_import.c:220
int MsgLog(int status,...)
Definition: message.c:337
int KsmRollbackMarkPreBackup(int repo_id)
Definition: ksm_import.c:582
void DusSetInt(char **sql, const char *field, int data, int clause)
Definition: du_string.c:99
void DqsFree(char *query)
Definition: dq_string.c:322
void DusConditionInt(char **query, const char *field, DQS_COMPARISON compare, int value, int clause)
Definition: du_string.c:172
const char * KsmKeywordStateValueToName(int value)
Definition: ksm_keyword.c:244
char * DqsCountInit(const char *table)
Definition: dq_string.c:92
int KsmPolicyIdFromName(const char *name, int *id)
Definition: ksm_import.c:472
DB_HANDLE DbHandle(void)
int KsmSmIdFromName(const char *name, int *id)
Definition: ksm_import.c:400
char * StrStrdup(const char *string)
Definition: string_util.c:126
void DqsConditionInt(char **query, const char *field, DQS_COMPARISON compare, int value, int index)
Definition: dq_string.c:226
int DbQuoteString(DB_HANDLE handle, const char *in, char *buffer, size_t buflen)
int DbLastRowId(DB_HANDLE handle, DB_ID *id)
unsigned long DB_ID
Definition: database.h:80
const char * DbErrmsg(DB_HANDLE handle)
int KsmImportPolicy(const char *policy_name, const char *policy_description)
Definition: ksm_import.c:149
void DisAppendString(char **sql, const char *what)
Definition: di_string.c:144
void DisEnd(char **sql)
Definition: di_string.c:172
#define KSM_SQL_SIZE
Definition: ksm.h:65
#define KSM_POLICY_DESC_LENGTH
Definition: ksm.h:62
void StrAppend(char **str1, const char *str2)
Definition: string_util2.c:78
void DusEnd(char **sql)
Definition: du_string.c:204
int DbIntQuery(DB_HANDLE handle, int *value, const char *query)
char * DusInit(const char *table)
Definition: du_string.c:62
void DisFree(char *sql)
Definition: di_string.c:193
int KsmImportKeyPair(int policy_id, const char *HSMKeyID, int smID, int size, int alg, int state, const char *time, int fixDate, DB_ID *id)
Definition: ksm_import.c:346
#define DB_ZONE_TABLE
Definition: db_fields.h:99
int KsmImportRepository(const char *repo_name, const char *repo_capacity, int require_backup)
Definition: ksm_import.c:72
void DisAppendInt(char **sql, int what)
Definition: di_string.c:133
int KsmMarkBackup(int repo_id, const char *datetime)
Definition: ksm_import.c:652
#define KSM_STATE_GENERATE
Definition: ksm.h:362
void DusSetString(char **sql, const char *field, const char *data, int clause)
Definition: du_string.c:115
void DqsEnd(char **query)
Definition: dq_string.c:301
int DbExecuteSqlNoResult(DB_HANDLE handle, const char *stmt_str)
void DqsConditionString(char **query, const char *field, DQS_COMPARISON compare, const char *value, int index)
Definition: dq_string.c:240