PuttyIntf.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //---------------------------------------------------------------------------
  2. #include <stdarg.h>
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5. #include <putty.h>
  6. // Suppress Parameter 'xxx' is never used warning.
  7. // It cannot be suppressed by not using param name, beacuse it is not possible in C
  8. #pragma option push -w-par
  9. #pragma option push -w-pch
  10. #include <windows.h>
  11. #pragma option pop /* -w-pch */
  12. #define C_ONLY
  13. #include "Net.h"
  14. #include "Common.h"
  15. #undef C_ONLY
  16. #include <misc.h>
  17. #include <storage.h>
  18. //---------------------------------------------------------------------------
  19. char sshver[50];
  20. //---------------------------------------------------------------------------
  21. void SSHLogEvent(void * frontend, const char * string);
  22. void SSHFatalError(char * string);
  23. void SSHConnectionFatal(void * frontend, char * string);
  24. void SSHVerifyHostKey(void * frontend, char *host, int port, char * keytype,
  25. char * keystr, char * fingerprint);
  26. void SSHOldKeyfileWarning(void);
  27. void SSHDisplayBanner(void * frontend, const char * banner, int size, int * log);
  28. void SSHAskAlg(void * frontend, const char * AlgType, const char * AlgName);
  29. long RegOpenWinSCPKey(HKEY hKey, const char * lpSubKey, HKEY * phkResult);
  30. long RegCreateWinSCPKey(HKEY hKey, const char * lpSubKey, HKEY * phkResult);
  31. long RegQueryWinSCPValueEx(HKEY Key, const char * ValueName, unsigned long * Reserved,
  32. unsigned long * Type, unsigned char * Data, unsigned long * DataSize);
  33. long RegSetWinSCPValueEx(HKEY Key, const char * ValueName, unsigned long Reserved,
  34. unsigned long Type, const unsigned char * Data, unsigned long DataSize);
  35. long RegCloseWinSCPKey(HKEY Key);
  36. //---------------------------------------------------------------------------
  37. #define FATAL_MSG(FMT) \
  38. va_list ap; \
  39. char stuff[200]; \
  40. va_start(ap, FMT); \
  41. vsnprintf(stuff, sizeof(stuff), FMT, ap); \
  42. stuff[sizeof(stuff) - 1] = '\0'; \
  43. va_end(ap);
  44. #define FATAL_BOX(FMT) \
  45. FATAL_MSG(FMT); \
  46. SSHFatalError(stuff);
  47. //---------------------------------------------------------------------------
  48. void fatalbox(char *fmt, ...)
  49. {
  50. FATAL_BOX(fmt);
  51. }
  52. //---------------------------------------------------------------------------
  53. void modalfatalbox(char *fmt, ...)
  54. {
  55. FATAL_BOX(fmt);
  56. }
  57. //---------------------------------------------------------------------------
  58. /*void begin_session(void)
  59. {
  60. // Maybe this is good point for showing main window
  61. } */
  62. //---------------------------------------------------------------------------
  63. void logevent(void * frontend, const char * string)
  64. {
  65. SSHLogEvent(frontend, string);
  66. }
  67. //---------------------------------------------------------------------------
  68. void connection_fatal(void * frontend, char * fmt, ...)
  69. {
  70. FATAL_MSG(fmt);
  71. SSHConnectionFatal(frontend, stuff);
  72. }
  73. //---------------------------------------------------------------------------
  74. int verify_ssh_host_key(void * frontend, char * host, int port, char * keytype,
  75. char * keystr, char * fingerprint, void (*callback)(void * ctx, int result),
  76. void * ctx)
  77. {
  78. SSHVerifyHostKey(frontend, host, port, keytype, keystr, fingerprint);
  79. // We should return 0 when key was not confirmed, we throw exception instead.
  80. return 1;
  81. }
  82. //---------------------------------------------------------------------------
  83. int askappend(void * frontend, Filename filename,
  84. void (*callback)(void * ctx, int result), void * ctx)
  85. {
  86. // this is called from logging.c of putty, which is never used with WinSCP
  87. assert(0);
  88. return 0;
  89. }
  90. //---------------------------------------------------------------------------
  91. void old_keyfile_warning(void)
  92. {
  93. SSHOldKeyfileWarning();
  94. }
  95. //---------------------------------------------------------------------------
  96. int askalg(void * frontend, const char * algtype, const char * algname,
  97. void (*callback)(void * ctx, int result), void * ctx)
  98. {
  99. SSHAskAlg(frontend, algtype, algname);
  100. // We should return 0 when key was not confirmed, we throw exception instead.
  101. return 1;
  102. }
  103. //---------------------------------------------------------------------------
  104. void cleanup_exit(int code)
  105. {
  106. SSHFatalError("");
  107. }
  108. //---------------------------------------------------------------------------
  109. void ldisc_send(void * handle, char * buf, int len, int interactive)
  110. {
  111. /*
  112. * This is only here because of the calls to ldisc_send(NULL,
  113. * 0) in ssh.c. Nothing in PSCP actually needs to use the ldisc
  114. * as an ldisc. So if we get called with any real data, I want
  115. * to know about it.
  116. */
  117. assert(len == 0);
  118. }
  119. //---------------------------------------------------------------------------
  120. long reg_open_winscp_key(HKEY Key, const char * SubKey, HKEY * Result)
  121. {
  122. return RegOpenWinSCPKey(Key, SubKey, Result);
  123. }
  124. //---------------------------------------------------------------------------
  125. long reg_create_winscp_key(HKEY Key, const char * SubKey, HKEY * Result)
  126. {
  127. return RegCreateWinSCPKey(Key, SubKey, Result);
  128. }
  129. //---------------------------------------------------------------------------
  130. long reg_query_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long * Reserved,
  131. unsigned long * Type, unsigned char * Data, unsigned long * DataSize)
  132. {
  133. return RegQueryWinSCPValueEx(Key, ValueName, Reserved, Type, Data, DataSize);
  134. }
  135. //---------------------------------------------------------------------------
  136. long reg_set_winscp_value_ex(HKEY Key, const char * ValueName, unsigned long Reserved,
  137. unsigned long Type, const unsigned char * Data, unsigned long DataSize)
  138. {
  139. return RegSetWinSCPValueEx(Key, ValueName, Reserved, Type, Data, DataSize);
  140. }
  141. //---------------------------------------------------------------------------
  142. long reg_close_winscp_key(HKEY Key)
  143. {
  144. return RegCloseWinSCPKey(Key);
  145. }
  146. //---------------------------------------------------------------------------
  147. void agent_schedule_callback(void (* callback)(void *, void *, int),
  148. void * callback_ctx, void * data, int len)
  149. {
  150. assert(0);
  151. }
  152. //---------------------------------------------------------------------------
  153. void notify_remote_exit(void *frontend)
  154. {
  155. // nothing
  156. }
  157. //---------------------------------------------------------------------------
  158. void update_specials_menu(void * frontend)
  159. {
  160. // nothing
  161. }
  162. //---------------------------------------------------------------------------
  163. typedef void (*timer_fn_t)(void *ctx, long now);
  164. long schedule_timer(int ticks, timer_fn_t fn, void * ctx)
  165. {
  166. return ticks + GetTickCount();
  167. }
  168. //---------------------------------------------------------------------------
  169. void expire_timer_context(void * ctx)
  170. {
  171. // nothing
  172. }
  173. //---------------------------------------------------------------------------
  174. Pinger pinger_new(Config * cfg, Backend * back, void * backhandle)
  175. {
  176. return NULL;
  177. }
  178. //---------------------------------------------------------------------------
  179. void pinger_reconfig(Pinger pinger, Config * oldcfg, Config * newcfg)
  180. {
  181. // nothing
  182. }
  183. //---------------------------------------------------------------------------
  184. void pinger_free(Pinger pinger)
  185. {
  186. // nothing
  187. }
  188. //---------------------------------------------------------------------------
  189. void set_busy_status(void * frontend, int status)
  190. {
  191. // nothing
  192. }
  193. //---------------------------------------------------------------------------
  194. void display_banner(void * frontend, const char * banner, int size, int * log)
  195. {
  196. SSHDisplayBanner(frontend, banner, size, log);
  197. }
  198. //---------------------------------------------------------------------------
  199. #pragma option pop // -w-par