diff options
| author | Lars Magne Ingebrigtsen | 2010-09-29 14:48:29 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2010-09-29 14:48:29 +0200 |
| commit | df7fcafff05c4002f35e507c65518f4b20ba5382 (patch) | |
| tree | dff32dbafc674846a125fd1d28a6ea79db90c522 /src | |
| parent | af7ef32d8e12d07c4a37df1685d997ac76641dd7 (diff) | |
| download | emacs-df7fcafff05c4002f35e507c65518f4b20ba5382.tar.gz emacs-df7fcafff05c4002f35e507c65518f4b20ba5382.zip | |
Make sure all reads/writes to gnutls streams go via the gnutls functions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 14 | ||||
| -rw-r--r-- | src/gnutls.c | 21 | ||||
| -rw-r--r-- | src/gnutls.h | 4 | ||||
| -rw-r--r-- | src/process.c | 13 | ||||
| -rw-r--r-- | src/process.h | 1 |
5 files changed, 39 insertions, 14 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index b14ed34b26d..ee6e8f6ce90 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | 2010-09-29 Lars Magne Ingebrigtsen <larsi@gnus.org> | ||
| 2 | |||
| 3 | * process.h (Lisp_Process): Add a gnutls_p field to Lisp_Process. | ||
| 4 | |||
| 5 | * process.c (make_process): Set the gnutls_p field to zero by | ||
| 6 | default. | ||
| 7 | (read_process_output): Always call the gnutls_read function if the | ||
| 8 | stream is a gnutls stream. | ||
| 9 | (send_process): Ditto for writes. | ||
| 10 | |||
| 11 | * gnutls.c (emacs_gnutls_write, emacs_gnutls_read): Refuse to read | ||
| 12 | or write anything until the state is GNUTLS_STAGE_READY. | ||
| 13 | (Fgnutls_boot): Mark the stream as being a gnutls stream. | ||
| 14 | |||
| 1 | 2010-09-29 Eli Zaretskii <eliz@gnu.org> | 15 | 2010-09-29 Eli Zaretskii <eliz@gnu.org> |
| 2 | 16 | ||
| 3 | * xdisp.c (reseat_1): Initialize bidi_it.paragraph_dir to | 17 | * xdisp.c (reseat_1): Initialize bidi_it.paragraph_dir to |
diff --git a/src/gnutls.c b/src/gnutls.c index 4b8016aab37..2d1aa3247f8 100644 --- a/src/gnutls.c +++ b/src/gnutls.c | |||
| @@ -33,10 +33,14 @@ Lisp_Object Qgnutls_e_interrupted, Qgnutls_e_again, | |||
| 33 | int global_initialized; | 33 | int global_initialized; |
| 34 | 34 | ||
| 35 | int | 35 | int |
| 36 | emacs_gnutls_write (int fildes, gnutls_session_t state, char *buf, | 36 | emacs_gnutls_write (int fildes, struct Lisp_Process *proc, char *buf, |
| 37 | unsigned int nbyte) | 37 | unsigned int nbyte) |
| 38 | { | 38 | { |
| 39 | register int rtnval, bytes_written; | 39 | register int rtnval, bytes_written; |
| 40 | gnutls_session_t state = proc->gnutls_state; | ||
| 41 | |||
| 42 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) | ||
| 43 | return 0; | ||
| 40 | 44 | ||
| 41 | bytes_written = 0; | 45 | bytes_written = 0; |
| 42 | 46 | ||
| @@ -62,16 +66,20 @@ emacs_gnutls_write (int fildes, gnutls_session_t state, char *buf, | |||
| 62 | } | 66 | } |
| 63 | 67 | ||
| 64 | int | 68 | int |
| 65 | emacs_gnutls_read (int fildes, gnutls_session_t state, char *buf, | 69 | emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, |
| 66 | unsigned int nbyte) | 70 | unsigned int nbyte) |
| 67 | { | 71 | { |
| 68 | register int rtnval; | 72 | register int rtnval; |
| 73 | gnutls_session_t state = proc->gnutls_state; | ||
| 74 | |||
| 75 | if (proc->gnutls_initstage != GNUTLS_STAGE_READY) | ||
| 76 | return 0; | ||
| 69 | 77 | ||
| 70 | rtnval = gnutls_read (state, buf, nbyte); | 78 | rtnval = gnutls_read (state, buf, nbyte); |
| 71 | if (rtnval >= 0) | 79 | if (rtnval >= 0) |
| 72 | return rtnval; | 80 | return rtnval; |
| 73 | else | 81 | else |
| 74 | return -1; | 82 | return 0; |
| 75 | } | 83 | } |
| 76 | 84 | ||
| 77 | /* convert an integer error to a Lisp_Object; it will be either a | 85 | /* convert an integer error to a Lisp_Object; it will be either a |
| @@ -272,6 +280,7 @@ KEYFILE and optionally CALLBACK. */) | |||
| 272 | CHECK_STRING (priority_string); | 280 | CHECK_STRING (priority_string); |
| 273 | 281 | ||
| 274 | state = XPROCESS (proc)->gnutls_state; | 282 | state = XPROCESS (proc)->gnutls_state; |
| 283 | XPROCESS (proc)->gnutls_p = 1; | ||
| 275 | 284 | ||
| 276 | if (NUMBERP (loglevel)) | 285 | if (NUMBERP (loglevel)) |
| 277 | { | 286 | { |
| @@ -281,7 +290,7 @@ KEYFILE and optionally CALLBACK. */) | |||
| 281 | max_log_level = XINT (loglevel); | 290 | max_log_level = XINT (loglevel); |
| 282 | XPROCESS (proc)->gnutls_log_level = max_log_level; | 291 | XPROCESS (proc)->gnutls_log_level = max_log_level; |
| 283 | } | 292 | } |
| 284 | 293 | ||
| 285 | /* always initialize globals. */ | 294 | /* always initialize globals. */ |
| 286 | global_init = gnutls_emacs_global_init (); | 295 | global_init = gnutls_emacs_global_init (); |
| 287 | if (! NILP (Fgnutls_errorp (global_init))) | 296 | if (! NILP (Fgnutls_errorp (global_init))) |
| @@ -483,7 +492,7 @@ or `gnutls-e-interrupted'. In that case you may resume the handshake | |||
| 483 | if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_HANDSHAKE_CANDO) | 492 | if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_HANDSHAKE_CANDO) |
| 484 | return Qgnutls_e_not_ready_for_handshake; | 493 | return Qgnutls_e_not_ready_for_handshake; |
| 485 | 494 | ||
| 486 | 495 | ||
| 487 | if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_TRANSPORT_POINTERS_SET) | 496 | if (GNUTLS_INITSTAGE (proc) < GNUTLS_STAGE_TRANSPORT_POINTERS_SET) |
| 488 | { | 497 | { |
| 489 | /* for a network process in Emacs infd and outfd are the same | 498 | /* for a network process in Emacs infd and outfd are the same |
| @@ -502,7 +511,7 @@ or `gnutls-e-interrupted'. In that case you may resume the handshake | |||
| 502 | ret = gnutls_handshake (state); | 511 | ret = gnutls_handshake (state); |
| 503 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; | 512 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_HANDSHAKE_TRIED; |
| 504 | 513 | ||
| 505 | if (GNUTLS_E_SUCCESS == ret) | 514 | if (ret == GNUTLS_E_SUCCESS) |
| 506 | { | 515 | { |
| 507 | /* here we're finally done. */ | 516 | /* here we're finally done. */ |
| 508 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; | 517 | GNUTLS_INITSTAGE (proc) = GNUTLS_STAGE_READY; |
diff --git a/src/gnutls.h b/src/gnutls.h index d63555a8a94..bcf9776963f 100644 --- a/src/gnutls.h +++ b/src/gnutls.h | |||
| @@ -49,10 +49,10 @@ typedef enum | |||
| 49 | #define GNUTLS_LOG(level, max, string) if (level <= max) { gnutls_log_function (level, "(Emacs) " string); } | 49 | #define GNUTLS_LOG(level, max, string) if (level <= max) { gnutls_log_function (level, "(Emacs) " string); } |
| 50 | 50 | ||
| 51 | int | 51 | int |
| 52 | emacs_gnutls_write (int fildes, gnutls_session_t state, char *buf, | 52 | emacs_gnutls_write (int fildes, struct Lisp_Process *proc, char *buf, |
| 53 | unsigned int nbyte); | 53 | unsigned int nbyte); |
| 54 | int | 54 | int |
| 55 | emacs_gnutls_read (int fildes, gnutls_session_t state, char *buf, | 55 | emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, |
| 56 | unsigned int nbyte); | 56 | unsigned int nbyte); |
| 57 | 57 | ||
| 58 | extern void syms_of_gnutls (void); | 58 | extern void syms_of_gnutls (void); |
diff --git a/src/process.c b/src/process.c index 4536dcc2a8e..a698e56fe39 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -672,6 +672,7 @@ make_process (Lisp_Object name) | |||
| 672 | #ifdef HAVE_GNUTLS | 672 | #ifdef HAVE_GNUTLS |
| 673 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; | 673 | p->gnutls_initstage = GNUTLS_STAGE_EMPTY; |
| 674 | p->gnutls_log_level = 0; | 674 | p->gnutls_log_level = 0; |
| 675 | p->gnutls_p = 0; | ||
| 675 | #endif | 676 | #endif |
| 676 | 677 | ||
| 677 | /* If name is already in use, modify it until it is unused. */ | 678 | /* If name is already in use, modify it until it is unused. */ |
| @@ -5203,8 +5204,8 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5203 | if (proc_buffered_char[channel] < 0) | 5204 | if (proc_buffered_char[channel] < 0) |
| 5204 | { | 5205 | { |
| 5205 | #ifdef HAVE_GNUTLS | 5206 | #ifdef HAVE_GNUTLS |
| 5206 | if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc)) | 5207 | if (XPROCESS (proc)->gnutls_p) |
| 5207 | nbytes = emacs_gnutls_read (channel, XPROCESS (proc)->gnutls_state, | 5208 | nbytes = emacs_gnutls_read (channel, XPROCESS (proc), |
| 5208 | chars + carryover, readmax); | 5209 | chars + carryover, readmax); |
| 5209 | else | 5210 | else |
| 5210 | #endif | 5211 | #endif |
| @@ -5242,8 +5243,8 @@ read_process_output (Lisp_Object proc, register int channel) | |||
| 5242 | chars[carryover] = proc_buffered_char[channel]; | 5243 | chars[carryover] = proc_buffered_char[channel]; |
| 5243 | proc_buffered_char[channel] = -1; | 5244 | proc_buffered_char[channel] = -1; |
| 5244 | #ifdef HAVE_GNUTLS | 5245 | #ifdef HAVE_GNUTLS |
| 5245 | if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc)) | 5246 | if (XPROCESS (proc)->gnutls_p) |
| 5246 | nbytes = emacs_gnutls_read (channel, XPROCESS (proc)->gnutls_state, | 5247 | nbytes = emacs_gnutls_read (channel, XPROCESS (proc), |
| 5247 | chars + carryover + 1, readmax - 1); | 5248 | chars + carryover + 1, readmax - 1); |
| 5248 | else | 5249 | else |
| 5249 | #endif | 5250 | #endif |
| @@ -5658,9 +5659,9 @@ send_process (volatile Lisp_Object proc, const unsigned char *volatile buf, | |||
| 5658 | #endif | 5659 | #endif |
| 5659 | { | 5660 | { |
| 5660 | #ifdef HAVE_GNUTLS | 5661 | #ifdef HAVE_GNUTLS |
| 5661 | if (NETCONN_P(proc) && GNUTLS_PROCESS_USABLE (proc)) | 5662 | if (XPROCESS (proc)->gnutls_p) |
| 5662 | rv = emacs_gnutls_write (outfd, | 5663 | rv = emacs_gnutls_write (outfd, |
| 5663 | XPROCESS (proc)->gnutls_state, | 5664 | XPROCESS (proc), |
| 5664 | (char *) buf, this); | 5665 | (char *) buf, this); |
| 5665 | else | 5666 | else |
| 5666 | #endif | 5667 | #endif |
diff --git a/src/process.h b/src/process.h index a28bf090ba9..0350e95310d 100644 --- a/src/process.h +++ b/src/process.h | |||
| @@ -136,6 +136,7 @@ struct Lisp_Process | |||
| 136 | gnutls_certificate_client_credentials gnutls_x509_cred; | 136 | gnutls_certificate_client_credentials gnutls_x509_cred; |
| 137 | gnutls_anon_client_credentials_t gnutls_anon_cred; | 137 | gnutls_anon_client_credentials_t gnutls_anon_cred; |
| 138 | int gnutls_log_level; | 138 | int gnutls_log_level; |
| 139 | int gnutls_p; | ||
| 139 | #endif | 140 | #endif |
| 140 | }; | 141 | }; |
| 141 | 142 | ||