io.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <ip.h>
  13. #include <plumb.h>
  14. #include <thread.h>
  15. #include <fcall.h>
  16. #include <9p.h>
  17. #include <mp.h>
  18. #include <libsec.h>
  19. #include "dat.h"
  20. #include "fns.h"
  21. static int32_t
  22. _iovfprint(va_list *arg)
  23. {
  24. int fd;
  25. char *fmt;
  26. va_list arg2;
  27. fd = va_arg(*arg, int);
  28. fmt = va_arg(*arg, char*);
  29. arg2 = va_arg(*arg, va_list);
  30. return vfprint(fd, fmt, arg2);
  31. }
  32. int
  33. iovfprint(Ioproc *io, int fd, char *fmt, va_list arg)
  34. {
  35. return iocall(io, _iovfprint, fd, fmt, arg);
  36. }
  37. int
  38. ioprint(Ioproc *io, int fd, char *fmt, ...)
  39. {
  40. int n;
  41. va_list arg;
  42. va_start(arg, fmt);
  43. n = iovfprint(io, fd, fmt, arg);
  44. va_end(arg);
  45. return n;
  46. }
  47. static int32_t
  48. _iotlsdial(va_list *arg)
  49. {
  50. char *addr, *local, *dir;
  51. int *cfdp, fd, tfd, usetls;
  52. TLSconn conn;
  53. addr = va_arg(*arg, char*);
  54. local = va_arg(*arg, char*);
  55. dir = va_arg(*arg, char*);
  56. cfdp = va_arg(*arg, int*);
  57. usetls = va_arg(*arg, int);
  58. fd = dial(addr, local, dir, cfdp);
  59. if(fd < 0)
  60. return -1;
  61. if(!usetls)
  62. return fd;
  63. memset(&conn, 0, sizeof conn);
  64. /* does no good, so far anyway */
  65. // conn.chain = readcertchain("/sys/lib/ssl/vsignss.pem");
  66. tfd = tlsClient(fd, &conn);
  67. close(fd);
  68. if(tfd < 0)
  69. fprint(2, "%s: tlsClient: %r\n", argv0);
  70. else {
  71. /* BUG: check cert here? */
  72. if(conn.cert)
  73. free(conn.cert);
  74. }
  75. return tfd;
  76. }
  77. int
  78. iotlsdial(Ioproc *io, char *addr, char *local, char *dir, int *cfdp,
  79. int usetls)
  80. {
  81. return iocall(io, _iotlsdial, addr, local, dir, cfdp, usetls);
  82. }