storage.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * storage.h: interface defining functions for storage and recovery
  3. * of PuTTY's persistent data.
  4. */
  5. #ifndef PUTTY_STORAGE_H
  6. #define PUTTY_STORAGE_H
  7. #include "defs.h"
  8. /* ----------------------------------------------------------------------
  9. * Functions to save and restore PuTTY sessions. Note that this is
  10. * only the low-level code to do the reading and writing. The
  11. * higher-level code that translates an internal Conf structure into
  12. * a set of (key,value) pairs in their external storage format is
  13. * elsewhere, since it doesn't (mostly) change between platforms.
  14. */
  15. /*
  16. * Write a saved session. The caller is expected to call
  17. * open_setting_w() to get a `void *' handle, then pass that to a
  18. * number of calls to write_setting_s() and write_setting_i(), and
  19. * then close it using close_settings_w(). At the end of this call
  20. * sequence the settings should have been written to the PuTTY
  21. * persistent storage area.
  22. *
  23. * A given key will be written at most once while saving a session.
  24. * Keys may be up to 255 characters long. String values have no length
  25. * limit.
  26. *
  27. * Any returned error message must be freed after use.
  28. */
  29. settings_w *open_settings_w(const char *sessionname, char **errmsg);
  30. void write_setting_s(settings_w *handle, const char *key, const char *value);
  31. void write_setting_i(settings_w *handle, const char *key, int value);
  32. void write_setting_filename(settings_w *handle,
  33. const char *key, Filename *value);
  34. void write_setting_fontspec(settings_w *handle,
  35. const char *key, FontSpec *font);
  36. void close_settings_w(settings_w *handle);
  37. /*
  38. * Read a saved session. The caller is expected to call
  39. * open_setting_r() to get a `void *' handle, then pass that to a
  40. * number of calls to read_setting_s() and read_setting_i(), and
  41. * then close it using close_settings_r().
  42. *
  43. * read_setting_s() returns a dynamically allocated string which the
  44. * caller must free. read_setting_filename() and
  45. * read_setting_fontspec() likewise return dynamically allocated
  46. * structures.
  47. *
  48. * If a particular string setting is not present in the session,
  49. * read_setting_s() can return NULL, in which case the caller
  50. * should invent a sensible default. If an integer setting is not
  51. * present, read_setting_i() returns its provided default.
  52. */
  53. settings_r *open_settings_r(const char *sessionname);
  54. char *read_setting_s(settings_r *handle, const char *key);
  55. int read_setting_i(settings_r *handle, const char *key, int defvalue);
  56. Filename *read_setting_filename(settings_r *handle, const char *key);
  57. FontSpec *read_setting_fontspec(settings_r *handle, const char *key);
  58. void close_settings_r(settings_r *handle);
  59. /*
  60. * Delete a whole saved session.
  61. */
  62. void del_settings(const char *sessionname);
  63. /*
  64. * Enumerate all saved sessions.
  65. */
  66. settings_e *enum_settings_start(void);
  67. bool enum_settings_next(settings_e *handle, strbuf *out);
  68. void enum_settings_finish(settings_e *handle);
  69. /* ----------------------------------------------------------------------
  70. * Functions to access PuTTY's host key database.
  71. */
  72. /*
  73. * See if a host key matches the database entry. Return values can
  74. * be 0 (entry matches database), 1 (entry is absent in database),
  75. * or 2 (entry exists in database and is different).
  76. */
  77. int check_stored_host_key(const char *hostname, int port,
  78. const char *keytype, const char *key);
  79. /*
  80. * Write a host key into the database, overwriting any previous
  81. * entry that might have been there.
  82. *
  83. * A Seat is provided for error-reporting purposes.
  84. */
  85. void store_host_key(Seat *seat, const char *hostname, int port,
  86. const char *keytype, const char *key);
  87. /* ----------------------------------------------------------------------
  88. * Functions to access PuTTY's configuration for trusted host
  89. * certification authorities. This must be stored separately from the
  90. * saved-session data, because the whole point is to avoid having to
  91. * configure CAs separately per session.
  92. */
  93. struct host_ca {
  94. char *name;
  95. strbuf *ca_public_key;
  96. char *validity_expression;
  97. ca_options opts;
  98. };
  99. host_ca_enum *enum_host_ca_start(void);
  100. bool enum_host_ca_next(host_ca_enum *handle, strbuf *out);
  101. void enum_host_ca_finish(host_ca_enum *handle);
  102. host_ca *host_ca_load(const char *name);
  103. char *host_ca_save(host_ca *); /* NULL on success, or dynamic error msg */
  104. char *host_ca_delete(const char *name); /* likewise */
  105. host_ca *host_ca_new(void); /* initialises to default settings */
  106. void host_ca_free(host_ca *);
  107. /* ----------------------------------------------------------------------
  108. * Functions to access PuTTY's random number seed file.
  109. */
  110. typedef void (*noise_consumer_t) (void *data, int len);
  111. /*
  112. * Read PuTTY's random seed file and pass its contents to a noise
  113. * consumer function.
  114. */
  115. void read_random_seed(noise_consumer_t consumer);
  116. /*
  117. * Write PuTTY's random seed file from a given chunk of noise.
  118. */
  119. void write_random_seed(void *data, int len);
  120. /* ----------------------------------------------------------------------
  121. * Cleanup function: remove all of PuTTY's persistent state.
  122. */
  123. void cleanup_all(void);
  124. #endif