Changeset 1cda4f3 for protocols/ssl_sspi.c
- Timestamp:
- 2006-05-26T15:02:09Z (18 years ago)
- Branches:
- master
- Children:
- 6fb6410
- Parents:
- eecccf1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/ssl_sspi.c
reecccf1 r1cda4f3 32 32 #include <sspi.h> 33 33 #include <schannel.h> 34 #include "sock.h" 34 35 35 36 static gboolean initialized = FALSE; … … 42 43 gpointer data; 43 44 gboolean established; 44 int inpa;45 45 CredHandle cred; /* SSL credentials */ 46 46 CtxtHandle context; /* SSL context */ 47 47 SecPkgContext_StreamSizes sizes; 48 49 char *host; 50 51 char *pending_raw_data; 52 gsize pending_raw_data_len; 53 char *pending_data; 54 gsize pending_data_len; 48 55 }; 49 56 50 57 static void ssl_connected(gpointer, gint, GaimInputCondition); 51 58 52 void sspi_global_init( void)59 void sspi_global_init(void) 53 60 { 54 61 /* FIXME */ 55 62 } 56 63 57 void sspi_global_deinit( void)64 void sspi_global_deinit(void) 58 65 { 59 66 /* FIXME */ 60 67 } 61 68 62 void *ssl_connect( char *host, int port, ssl_input_function func, gpointer data)63 { 64 struct scd *conn = g_new0( struct scd, 1);69 void *ssl_connect(char *host, int port, ssl_input_function func, gpointer data) 70 { 71 struct scd *conn = g_new0(struct scd, 1); 65 72 66 conn->fd = proxy_connect( host, port, ssl_connected, conn ); 73 conn->fd = proxy_connect(host, port, ssl_connected, conn); 74 sock_make_nonblocking(conn->fd); 67 75 conn->func = func; 68 76 conn->data = data; 69 conn-> inpa = -1;70 71 if ( conn->fd < 0)77 conn->host = g_strdup(host); 78 79 if (conn->fd < 0) 72 80 { 73 g_free( conn);74 return ( NULL );75 } 76 77 if ( !initialized)81 g_free(conn); 82 return NULL; 83 } 84 85 if (!initialized) 78 86 { 79 87 sspi_global_init(); 80 88 initialized = TRUE; 81 atexit( sspi_global_deinit);89 atexit(sspi_global_deinit); 82 90 } 83 91 … … 85 93 } 86 94 87 static void ssl_connected(gpointer data, gint fd, GaimInputCondition cond)88 { 89 struct scd *conn = data;95 static void ssl_connected(gpointer _conn, gint fd, GaimInputCondition cond) 96 { 97 struct scd *conn = _conn; 90 98 SCHANNEL_CRED ssl_cred; 91 99 TimeStamp timestamp; … … 97 105 ISC_REQ_MANUAL_CRED_VALIDATION; 98 106 ULONG a; 107 gsize size = 0; 108 gchar *data = NULL; 99 109 100 110 memset(&ssl_cred, 0, sizeof(SCHANNEL_CRED)); … … 105 115 106 116 if (st != SEC_E_OK) { 107 conn->func( conn->data, NULL, cond);117 conn->func(conn->data, NULL, cond); 108 118 return; 109 119 } 110 120 111 121 do { 112 122 /* initialize buffers */ 113 ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = buf;123 ibuf[0].cbBuffer = size; ibuf[0].pvBuffer = data; 114 124 ibuf[1].cbBuffer = 0; ibuf[1].pvBuffer = NULL; 115 125 obuf[0].cbBuffer = 0; obuf[0].pvBuffer = NULL; … … 122 132 ibufs.pBuffers = ibuf; obufs.pBuffers = obuf; 123 133 124 st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp);134 st = InitializeSecurityContext(&conn->cred, size?&conn->context:NULL, conn->host, req, 0, SECURITY_NETWORK_DREP, size?&ibufs:NULL, 0, &conn->context, &obufs, &a, ×tamp); 125 135 if (obuf[0].pvBuffer && obuf[0].cbBuffer) { 136 /* FIXME: Check return value */ 126 137 send(conn->fd, obuf[0].pvBuffer, obuf[0].cbBuffer, 0); 127 138 } … … 131 142 break; 132 143 case SEC_I_CONTINUE_NEEDED: 133 144 break; 145 case SEC_E_INCOMPLETE_MESSAGE: 146 break; 147 case SEC_E_OK: 148 break; 134 149 } 135 150 136 137 151 QueryContextAttributes(&conn->context, SECPKG_ATTR_STREAM_SIZES, &conn->sizes); 138 152 } while (1); 139 153 140 conn->func( conn->data, conn, cond);141 } 142 143 int ssl_read( void *conn, char *retdata, int len)154 conn->func(conn->data, conn, cond); 155 } 156 157 int ssl_read(void *conn, char *retdata, int len) 144 158 { 145 159 struct scd *scd = conn; … … 165 179 SECURITY_STATUS st = DecryptMessage(&scd->context, &msg, 0, NULL); 166 180 181 if (st != SEC_E_OK) { 182 /* FIXME */ 183 return -1; 184 } 185 167 186 for (i = 0; i < 4; i++) { 168 187 if (buf[i].BufferType == SECBUFFER_DATA) { … … 173 192 174 193 g_free(data); 175 return ( -1 );176 } 177 178 int ssl_write( void *conn, const char *userdata, int len)194 return -1; 195 } 196 197 int ssl_write(void *conn, const char *userdata, int len) 179 198 { 180 199 struct scd *scd = conn; … … 214 233 } 215 234 216 void ssl_disconnect( void *conn)235 void ssl_disconnect(void *conn) 217 236 { 218 237 struct scd *scd = conn; … … 244 263 FreeCredentialsHandle(&scd->cred); 245 264 246 closesocket( scd->fd ); 265 closesocket(scd->fd); 266 g_free(scd->host); 247 267 g_free(scd); 248 268 } 249 269 250 int ssl_getfd( void *conn ) 251 { 252 return( ((struct scd*)conn)->fd ); 253 } 270 int ssl_getfd(void *conn) 271 { 272 return ((struct scd*)conn)->fd; 273 } 274 275 GaimInputCondition ssl_getdirection( void *conn ) 276 { 277 return GAIM_INPUT_WRITE; /* FIXME: or GAIM_INPUT_READ */ 278 }
Note: See TracChangeset
for help on using the changeset viewer.