2 * "$Id: client.c,v 1.91.2.39 2003/01/24 19:19:43 mike Exp $"
4 * Client routines for the Common UNIX Printing System (CUPS) scheduler.
6 * Copyright 1997-2003 by Easy Software Products, all rights reserved.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636-3111 USA
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * AcceptClient() - Accept a new client.
27 * CloseAllClients() - Close all remote clients immediately.
28 * CloseClient() - Close a remote client.
29 * EncryptClient() - Enable encryption for the client...
30 * ReadClient() - Read data from a client.
31 * SendCommand() - Send output from a command via HTTP.
32 * SendError() - Send an error message via HTTP.
33 * SendFile() - Send a file via HTTP.
34 * SendHeader() - Send an HTTP request.
35 * ShutdownClient() - Shutdown the receiving end of a connection.
36 * WriteClient() - Write data to a client as needed.
37 * check_if_modified() - Decode an "If-Modified-Since" line.
38 * decode_auth() - Decode an authorization string.
39 * get_file() - Get a filename and state info.
40 * install_conf_file() - Install a configuration file.
41 * pipe_command() - Pipe the output of a command to the remote client.
42 * CDSAReadFunc() - Read function for CDSA decryption code.
43 * CDSAWriteFunc() - Write function for CDSA encryption code.
47 * Include necessary headers...
52 #include <cups/http-private.h>
59 static int check_if_modified(client_t
*con
,
60 struct stat
*filestats
);
61 static void decode_auth(client_t
*con
);
62 static char *get_file(client_t
*con
, struct stat
*filestats
);
63 static http_status_t
install_conf_file(client_t
*con
);
64 static int pipe_command(client_t
*con
, int infile
, int *outfile
,
65 char *command
, char *options
);
68 OSStatus
CDSAReadFunc(SSLConnectionRef connection
, void *data
,
70 OSStatus
CDSAWriteFunc(SSLConnectionRef connection
,
71 const void *data
, size_t *dataLength
);
72 #endif /* HAVE_CDSASSL */
76 * 'AcceptClient()' - Accept a new client.
80 AcceptClient(listener_t
*lis
) /* I - Listener socket */
82 int i
; /* Looping var */
83 int count
; /* Count of connections on a host */
84 int val
; /* Parameter value */
85 client_t
*con
; /* New client pointer */
86 const struct hostent
*host
; /* Host entry for address */
87 char *hostname
;/* Hostname for address */
88 http_addr_t temp
; /* Temporary address variable */
89 static time_t last_dos
= 0;
90 /* Time of last DoS attack */
93 LogMessage(L_DEBUG2
, "AcceptClient(%p) %d NumClients = %d",
94 lis
, lis
->fd
, NumClients
);
97 * Make sure we don't have a full set of clients already...
100 if (NumClients
== MaxClients
)
104 * Get a pointer to the next available client...
107 con
= Clients
+ NumClients
;
109 memset(con
, 0, sizeof(client_t
));
110 con
->http
.activity
= time(NULL
);
113 * Accept the client and get the remote address...
116 val
= sizeof(struct sockaddr_in
);
118 if ((con
->http
.fd
= accept(lis
->fd
, (struct sockaddr
*)&(con
->http
.hostaddr
),
121 LogMessage(L_ERROR
, "Unable to accept client connection - %s.",
127 if (lis
->address
.addr
.sa_family
== AF_INET6
)
128 con
->http
.hostaddr
.ipv6
.sin6_port
= lis
->address
.ipv6
.sin6_port
;
130 #endif /* AF_INET6 */
131 con
->http
.hostaddr
.ipv4
.sin_port
= lis
->address
.ipv4
.sin_port
;
134 * Check the number of clients on the same address...
137 for (i
= 0, count
= 0; i
< NumClients
; i
++)
138 if (memcmp(&(Clients
[i
].http
.hostaddr
), &(con
->http
.hostaddr
),
139 sizeof(con
->http
.hostaddr
)) == 0)
142 if (count
>= MaxClientsPerHost
)
146 if (count
>= MaxClientsPerHost
)
148 if ((time(NULL
) - last_dos
) >= 60)
150 last_dos
= time(NULL
);
151 LogMessage(L_WARN
, "Possible DoS attack - more than %d clients connecting from %s!",
152 MaxClientsPerHost
, Clients
[i
].http
.hostname
);
156 closesocket(con
->http
.fd
);
165 * Get the hostname or format the IP address as needed...
169 hostname
= httpAddrLookup(&(con
->http
.hostaddr
), con
->http
.hostname
,
170 sizeof(con
->http
.hostname
));
174 httpAddrString(&(con
->http
.hostaddr
), con
->http
.hostname
,
175 sizeof(con
->http
.hostname
));
178 if (httpAddrLocalhost(&(con
->http
.hostaddr
)))
181 * Map accesses from the loopback interface to "localhost"...
184 strlcpy(con
->http
.hostname
, "localhost", sizeof(con
->http
.hostname
));
186 else if (httpAddrEqual(&(con
->http
.hostaddr
), &ServerAddr
))
189 * Map accesses from the same host to the server name.
192 strlcpy(con
->http
.hostname
, ServerName
, sizeof(con
->http
.hostname
));
195 if (hostname
== NULL
&& HostNameLookups
== 2)
198 * Can't have an unresolved IP address with double-lookups enabled...
201 LogMessage(L_DEBUG2
, "AcceptClient: Closing connection %d...",
205 closesocket(con
->http
.fd
);
210 LogMessage(L_WARN
, "Name lookup failed - connection from %s closed!",
215 if (HostNameLookups
== 2)
218 * Do double lookups as needed...
221 if ((host
= httpGetHostByName(con
->http
.hostname
)) != NULL
)
224 * See if the hostname maps to the same IP address...
227 if (host
->h_addrtype
!= con
->http
.hostaddr
.addr
.sa_family
)
230 * Not the right type of address...
238 * Compare all of the addresses against this one...
241 for (i
= 0; host
->h_addr_list
[i
]; i
++)
243 httpAddrLoad(host
, 0, i
, &temp
);
245 if (httpAddrEqual(&(con
->http
.hostaddr
), &temp
))
249 if (!host
->h_addr_list
[i
])
257 * Can't have a hostname that doesn't resolve to the same IP address
258 * with double-lookups enabled...
261 LogMessage(L_DEBUG2
, "AcceptClient: Closing connection %d...",
265 closesocket(con
->http
.fd
);
270 LogMessage(L_WARN
, "IP lookup failed - connection from %s closed!",
277 if (con
->http
.hostaddr
.addr
.sa_family
== AF_INET6
)
278 LogMessage(L_DEBUG
, "AcceptClient: %d from %s:%d.", con
->http
.fd
,
279 con
->http
.hostname
, ntohs(con
->http
.hostaddr
.ipv6
.sin6_port
));
281 #endif /* AF_INET6 */
282 LogMessage(L_DEBUG
, "AcceptClient: %d from %s:%d.", con
->http
.fd
,
283 con
->http
.hostname
, ntohs(con
->http
.hostaddr
.ipv4
.sin_port
));
286 * Using TCP_NODELAY improves responsiveness, especially on systems
287 * with a slow loopback interface... Since we write large buffers
288 * when sending print files and requests, there shouldn't be any
289 * performance penalty for this...
293 setsockopt(con
->http
.fd
, IPPROTO_TCP
, TCP_NODELAY
, &val
, sizeof(val
));
296 * Add the socket to the select() input mask.
299 fcntl(con
->http
.fd
, F_SETFD
, fcntl(con
->http
.fd
, F_GETFD
) | FD_CLOEXEC
);
301 LogMessage(L_DEBUG2
, "AcceptClient: Adding fd %d to InputSet...",
303 FD_SET(con
->http
.fd
, &InputSet
);
308 * Temporarily suspend accept()'s until we lose a client...
311 if (NumClients
== MaxClients
)
316 * See if we are connecting on a secure port...
319 if (lis
->encryption
== HTTP_ENCRYPT_ALWAYS
)
322 * https connection; go secure...
325 con
->http
.encryption
= HTTP_ENCRYPT_ALWAYS
;
329 #endif /* HAVE_SSL */
334 * 'CloseAllClients()' - Close all remote clients immediately.
338 CloseAllClients(void)
340 while (NumClients
> 0)
341 CloseClient(Clients
);
346 * 'CloseClient()' - Close a remote client.
350 CloseClient(client_t
*con
) /* I - Client to close */
352 int status
; /* Exit status of pipe command */
353 #if defined(HAVE_LIBSSL)
354 SSL_CTX
*context
; /* Context for encryption */
355 SSL
*conn
; /* Connection for encryption */
356 unsigned long error
; /* Error code */
357 #elif defined(HAVE_GNUTLS)
358 http_tls_t
*conn
; /* TLS connection information */
359 int error
; /* Error code */
360 gnutls_certificate_server_credentials
*credentials
;
361 /* TLS credentials */
362 #endif /* HAVE_GNUTLS */
365 LogMessage(L_DEBUG
, "CloseClient() %d", con
->http
.fd
);
369 * Shutdown encryption as needed...
375 conn
= (SSL
*)(con
->http
.tls
);
376 context
= SSL_get_SSL_CTX(conn
);
378 switch (SSL_shutdown(conn
))
381 LogMessage(L_INFO
, "CloseClient: SSL shutdown successful!");
384 LogMessage(L_ERROR
, "CloseClient: Fatal error during SSL shutdown!");
386 while ((error
= ERR_get_error()) != 0)
387 LogMessage(L_ERROR
, "CloseClient: %s", ERR_error_string(error
, NULL
));
391 SSL_CTX_free(context
);
394 # elif defined(HAVE_GNUTLS)
395 conn
= (http_tls_t
*)(con
->http
.tls
);
396 credentials
= (gnutls_certificate_server_credentials
*)(conn
->credentials
);
398 error
= gnutls_bye(conn
->session
, GNUTLS_SHUT_WR
);
401 case GNUTLS_E_SUCCESS
:
402 LogMessage(L_INFO
, "CloseClient: SSL shutdown successful!");
405 LogMessage(L_ERROR
, "CloseClient: %s", gnutls_strerror(error
));
409 gnutls_deinit(conn
->session
);
410 gnutls_certificate_free_credentials(*credentials
);
414 # elif defined(HAVE_CDSASSL)
415 status
= SSLClose((SSLContextRef
)con
->http
.tls
);
416 SSLDisposeContext((SSLContextRef
)con
->http
.tls
);
417 # endif /* HAVE_LIBSSL */
419 con
->http
.tls
= NULL
;
421 #endif /* HAVE_SSL */
424 * Close the socket and clear the file from the input set for select()...
427 if (con
->http
.fd
>= 0)
429 LogMessage(L_DEBUG2
, "CloseClient: Removing fd %d from InputSet and OutputSet...",
432 FD_CLR(con
->http
.fd
, &InputSet
);
433 FD_CLR(con
->http
.fd
, &OutputSet
);
437 if (con
->pipe_pid
!= 0)
439 LogMessage(L_DEBUG2
, "CloseClient: Removing fd %d from InputSet...",
441 FD_CLR(con
->file
, &InputSet
);
447 * Close the open data file...
452 kill(con
->pipe_pid
, SIGKILL
);
453 waitpid(con
->pipe_pid
, &status
, WNOHANG
);
456 LogMessage(L_DEBUG2
, "CloseClient() %d Closing data file %d.",
457 con
->http
.fd
, con
->file
);
458 LogMessage(L_DEBUG2
, "CloseClient() %d Removing fd %d from InputSet.",
459 con
->http
.fd
, con
->file
);
461 FD_CLR(con
->file
, &InputSet
);
468 ippDelete(con
->request
);
474 ippDelete(con
->response
);
475 con
->response
= NULL
;
480 cupsLangFree(con
->language
);
481 con
->language
= NULL
;
485 * Re-enable new client connections if we are going back under the
489 if (NumClients
== MaxClients
)
493 * Compact the list of clients as necessary...
498 if (con
< (Clients
+ NumClients
))
499 memcpy(con
, con
+ 1, (Clients
+ NumClients
- con
) * sizeof(client_t
));
504 * 'EncryptClient()' - Enable encryption for the client...
507 int /* O - 1 on success, 0 on error */
508 EncryptClient(client_t
*con
) /* I - Client to encrypt */
510 #if defined HAVE_LIBSSL
511 SSL_CTX
*context
; /* Context for encryption */
512 SSL
*conn
; /* Connection for encryption */
513 unsigned long error
; /* Error code */
517 * Create the SSL context and accept the connection...
520 context
= SSL_CTX_new(SSLv23_server_method());
522 SSL_CTX_use_PrivateKey_file(context
, ServerKey
, SSL_FILETYPE_PEM
);
523 SSL_CTX_use_certificate_file(context
, ServerCertificate
, SSL_FILETYPE_PEM
);
525 conn
= SSL_new(context
);
527 SSL_set_fd(conn
, con
->http
.fd
);
528 if (SSL_accept(conn
) != 1)
530 while ((error
= ERR_get_error()) != 0)
531 LogMessage(L_ERROR
, "EncryptClient: %s", ERR_error_string(error
, NULL
));
533 SSL_CTX_free(context
);
538 con
->http
.tls
= conn
;
541 #elif defined(HAVE_GNUTLS)
542 http_tls_t
*conn
; /* TLS session object */
543 int error
; /* Error code */
544 gnutls_certificate_server_credentials
*credentials
;
545 /* TLS credentials */
548 * Create the SSL object and perform the SSL handshake...
551 conn
= (http_tls_t
*)malloc(sizeof(gnutls_session
));
556 credentials
= (gnutls_certificate_server_credentials
*)
557 malloc(sizeof(gnutls_certificate_server_credentials
));
558 if (credentials
== NULL
)
564 gnutls_certificate_allocate_credentials(credentials
);
565 gnutls_certificate_set_x509_key_file(*credentials
, ServerCertificate
,
566 ServerKey
, GNUTLS_X509_FMT_PEM
);
568 gnutls_init(&(conn
->session
), GNUTLS_SERVER
);
569 gnutls_set_default_priority(conn
->session
);
570 gnutls_credentials_set(conn
->session
, GNUTLS_CRD_CERTIFICATE
, *credentials
);
571 gnutls_transport_set_ptr(conn
->session
, con
->http
.fd
);
573 error
= gnutls_handshake(conn
->session
);
575 if (error
!= GNUTLS_E_SUCCESS
)
577 LogMessage(L_ERROR
, "EncryptClient: %s", gnutls_strerror(error
));
578 gnutls_deinit(conn
->session
);
579 gnutls_certificate_free_credentials(*credentials
);
585 LogMessage(L_DEBUG
, "EncryptClient() %d Connection now encrypted.",
588 conn
->credentials
= credentials
;
589 con
->http
.tls
= conn
;
592 #elif defined(HAVE_CDSASSL)
593 OSStatus error
; /* Error info */
594 SSLContextRef conn
; /* New connection */
595 SSLProtocol tryVersion
; /* Protocol version */
596 const char *hostName
; /* Local hostname */
597 int allowExpired
; /* Allow expired certificates? */
598 int allowAnyRoot
; /* Allow any root certificate? */
599 SSLProtocol
*negVersion
; /* Negotiated protocol version */
600 SSLCipherSuite
*negCipher
; /* Negotiated cypher */
601 CFArrayRef
*peerCerts
; /* Certificates */
605 error
= SSLNewContext(true, &conn
);
610 error
= SSLSetIOFuncs(conn
, CDSAReadFunc
, CDSAWriteFunc
);
613 error
= SSLSetProtocolVersion(conn
, kSSLProtocol3
);
616 error
= SSLSetConnection(conn
, (SSLConnectionRef
)con
->http
.fd
);
620 hostName
= ServerName
; /* MRS: ??? */
621 error
= SSLSetPeerDomainName(conn
, hostName
, strlen(hostName
) + 1);
624 /* have to do these options befor setting server certs */
625 if (!error
&& allowExpired
)
626 error
= SSLSetAllowsExpiredCerts(conn
, true);
628 if (!error
&& allowAnyRoot
)
629 error
= SSLSetAllowsAnyRoot(conn
, true);
631 if (!error
&& ServerCertificatesArray
!= NULL
)
632 error
= SSLSetCertificate(conn
, ServerCertificatesArray
);
635 * Perform SSL/TLS handshake
640 error
= SSLHandshake(conn
);
642 while (error
== errSSLWouldBlock
);
646 LogMessage(L_ERROR
, "EncryptClient: %d", error
);
648 con
->http
.error
= error
;
649 con
->http
.status
= HTTP_ERROR
;
652 SSLDisposeContext(conn
);
657 LogMessage(L_DEBUG
, "EncryptClient() %d Connection now encrypted.",
659 con
->http
.tls
= conn
;
664 #endif /* HAVE_GNUTLS */
669 * 'ReadClient()' - Read data from a client.
672 int /* O - 1 on success, 0 on error */
673 ReadClient(client_t
*con
) /* I - Client to read from */
675 char line
[32768], /* Line from client... */
676 operation
[64], /* Operation code from socket */
677 version
[64]; /* HTTP version number string */
678 int major
, minor
; /* HTTP version numbers */
679 http_status_t status
; /* Transfer status */
680 ipp_state_t ipp_state
; /* State of IPP transfer */
681 int bytes
; /* Number of bytes to POST */
682 char *filename
; /* Name of file for GET/HEAD */
683 struct stat filestats
; /* File information */
684 mime_type_t
*type
; /* MIME type of file */
685 printer_t
*p
; /* Printer */
686 location_t
*best
; /* Best match for authentication */
687 static unsigned request_id
= 0;/* Request ID for temp files */
690 status
= HTTP_CONTINUE
;
692 LogMessage(L_DEBUG2
, "ReadClient() %d, used=%d", con
->http
.fd
,
701 switch (con
->http
.state
)
705 * See if we've received a request line...
708 if (httpGets(line
, sizeof(line
) - 1, HTTP(con
)) == NULL
)
715 * Ignore blank request lines...
722 * Clear other state variables...
725 httpClearFields(HTTP(con
));
727 con
->http
.activity
= time(NULL
);
728 con
->http
.version
= HTTP_1_0
;
729 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
730 con
->http
.data_encoding
= HTTP_ENCODE_LENGTH
;
731 con
->http
.data_remaining
= 0;
732 con
->operation
= HTTP_WAITING
;
736 con
->command
[0] = '\0';
737 con
->username
[0] = '\0';
738 con
->password
[0] = '\0';
741 if (con
->language
!= NULL
)
743 cupsLangFree(con
->language
);
744 con
->language
= NULL
;
748 * Grab the request line...
751 switch (sscanf(line
, "%63s%1023s%63s", operation
, con
->uri
, version
))
754 LogMessage(L_ERROR
, "Bad request line \"%s\"!", line
);
755 SendError(con
, HTTP_BAD_REQUEST
);
759 con
->http
.version
= HTTP_0_9
;
762 if (sscanf(version
, "HTTP/%d.%d", &major
, &minor
) != 2)
764 LogMessage(L_ERROR
, "Bad request line \"%s\"!", line
);
765 SendError(con
, HTTP_BAD_REQUEST
);
772 con
->http
.version
= (http_version_t
)(major
* 100 + minor
);
773 if (con
->http
.version
== HTTP_1_1
&& KeepAlive
)
774 con
->http
.keep_alive
= HTTP_KEEPALIVE_ON
;
776 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
780 SendError(con
, HTTP_NOT_SUPPORTED
);
788 * Handle full URLs in the request line...
791 if (con
->uri
[0] != '/')
793 char method
[HTTP_MAX_URI
], /* Method/scheme */
794 userpass
[HTTP_MAX_URI
], /* Username:password */
795 hostname
[HTTP_MAX_URI
], /* Hostname */
796 resource
[HTTP_MAX_URI
]; /* Resource path */
797 int port
; /* Port number */
801 * Separate the URI into its components...
804 httpSeparate(con
->uri
, method
, userpass
, hostname
, &port
, resource
);
807 * Only allow URIs with the servername, localhost, or an IP
811 if (strcasecmp(hostname
, ServerName
) &&
812 strcasecmp(hostname
, "localhost") &&
813 !isdigit(hostname
[0]))
816 * Nope, we don't do proxies...
819 LogMessage(L_ERROR
, "Bad URI \"%s\" in request!", con
->uri
);
820 SendError(con
, HTTP_METHOD_NOT_ALLOWED
);
826 * Copy the resource portion back into the URI; both resource and
827 * con->uri are HTTP_MAX_URI bytes in size...
830 strcpy(con
->uri
, resource
);
834 * Process the request...
837 if (strcmp(operation
, "GET") == 0)
838 con
->http
.state
= HTTP_GET
;
839 else if (strcmp(operation
, "PUT") == 0)
840 con
->http
.state
= HTTP_PUT
;
841 else if (strcmp(operation
, "POST") == 0)
842 con
->http
.state
= HTTP_POST
;
843 else if (strcmp(operation
, "DELETE") == 0)
844 con
->http
.state
= HTTP_DELETE
;
845 else if (strcmp(operation
, "TRACE") == 0)
846 con
->http
.state
= HTTP_TRACE
;
847 else if (strcmp(operation
, "OPTIONS") == 0)
848 con
->http
.state
= HTTP_OPTIONS
;
849 else if (strcmp(operation
, "HEAD") == 0)
850 con
->http
.state
= HTTP_HEAD
;
853 LogMessage(L_ERROR
, "Bad operation \"%s\"!", operation
);
854 SendError(con
, HTTP_BAD_REQUEST
);
859 con
->start
= time(NULL
);
860 con
->operation
= con
->http
.state
;
862 LogMessage(L_DEBUG
, "ReadClient() %d %s %s HTTP/%d.%d", con
->http
.fd
,
864 con
->http
.version
/ 100, con
->http
.version
% 100);
866 con
->http
.status
= HTTP_OK
;
876 * Parse incoming parameters until the status changes...
879 status
= httpUpdate(HTTP(con
));
881 if (status
!= HTTP_OK
&& status
!= HTTP_CONTINUE
)
883 SendError(con
, HTTP_BAD_REQUEST
);
890 break; /* Anti-compiler-warning-code */
894 * Handle new transfers...
897 if (status
== HTTP_OK
)
899 con
->language
= cupsLangGet(con
->http
.fields
[HTTP_FIELD_ACCEPT_LANGUAGE
]);
903 if (strncmp(con
->http
.fields
[HTTP_FIELD_CONNECTION
], "Keep-Alive", 10) == 0 &&
905 con
->http
.keep_alive
= HTTP_KEEPALIVE_ON
;
907 if (con
->http
.fields
[HTTP_FIELD_HOST
][0] == '\0' &&
908 con
->http
.version
>= HTTP_1_1
)
911 * HTTP/1.1 and higher require the "Host:" field...
914 if (!SendError(con
, HTTP_BAD_REQUEST
))
920 else if (con
->operation
== HTTP_OPTIONS
)
923 * Do OPTIONS command...
926 if ((best
= FindBest(con
->uri
, con
->http
.state
)) != NULL
&&
927 best
->type
!= AUTH_NONE
)
929 if (!SendHeader(con
, HTTP_UNAUTHORIZED
, NULL
))
936 if (strcasecmp(con
->http
.fields
[HTTP_FIELD_CONNECTION
], "Upgrade") == 0 &&
937 con
->http
.tls
== NULL
)
941 * Do encryption stuff...
944 if (!SendHeader(con
, HTTP_SWITCHING_PROTOCOLS
, NULL
))
950 httpPrintf(HTTP(con
), "Connection: Upgrade\r\n");
951 httpPrintf(HTTP(con
), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
952 httpPrintf(HTTP(con
), "Content-Length: 0\r\n");
953 httpPrintf(HTTP(con
), "\r\n");
957 if (!SendError(con
, HTTP_NOT_IMPLEMENTED
))
962 #endif /* HAVE_SSL */
965 if (con
->http
.expect
)
967 /**** TODO: send expected header ****/
970 if (!SendHeader(con
, HTTP_OK
, NULL
))
976 httpPrintf(HTTP(con
), "Allow: GET, HEAD, OPTIONS, POST, PUT\r\n");
977 httpPrintf(HTTP(con
), "Content-Length: 0\r\n");
978 httpPrintf(HTTP(con
), "\r\n");
980 else if (strstr(con
->uri
, "..") != NULL
)
983 * Protect against malicious users!
986 if (!SendError(con
, HTTP_FORBIDDEN
))
994 if (strcasecmp(con
->http
.fields
[HTTP_FIELD_CONNECTION
], "Upgrade") == 0 &&
995 con
->http
.tls
== NULL
)
999 * Do encryption stuff...
1002 if (!SendHeader(con
, HTTP_SWITCHING_PROTOCOLS
, NULL
))
1008 httpPrintf(HTTP(con
), "Connection: Upgrade\r\n");
1009 httpPrintf(HTTP(con
), "Upgrade: TLS/1.0,HTTP/1.1\r\n");
1010 httpPrintf(HTTP(con
), "Content-Length: 0\r\n");
1011 httpPrintf(HTTP(con
), "\r\n");
1015 status
= IsAuthorized(con
);
1017 if (!SendError(con
, HTTP_NOT_IMPLEMENTED
))
1022 #endif /* HAVE_SSL */
1025 if (status
!= HTTP_OK
)
1027 LogMessage(L_DEBUG2
, "ReadClient: Unauthorized request for %s...\n",
1029 SendError(con
, status
);
1030 ShutdownClient(con
);
1034 if (con
->http
.expect
)
1036 /**** TODO: send expected header ****/
1039 switch (con
->http
.state
)
1041 case HTTP_GET_SEND
:
1042 if (strncmp(con
->uri
, "/printers/", 10) == 0 &&
1043 strcmp(con
->uri
+ strlen(con
->uri
) - 4, ".ppd") == 0)
1046 * Send PPD file - get the real printer name since printer
1047 * names are not case sensitive but filenames can be...
1050 con
->uri
[strlen(con
->uri
) - 4] = '\0'; /* Drop ".ppd" */
1052 if ((p
= FindPrinter(con
->uri
+ 10)) != NULL
)
1053 snprintf(con
->uri
, sizeof(con
->uri
), "/ppd/%s.ppd", p
->name
);
1056 if (!SendError(con
, HTTP_NOT_FOUND
))
1066 if ((strncmp(con
->uri
, "/admin", 6) == 0 &&
1067 strncmp(con
->uri
, "/admin/conf/", 12) != 0) ||
1068 strncmp(con
->uri
, "/printers", 9) == 0 ||
1069 strncmp(con
->uri
, "/classes", 8) == 0 ||
1070 strncmp(con
->uri
, "/jobs", 5) == 0)
1073 * Send CGI output...
1076 if (strncmp(con
->uri
, "/admin", 6) == 0)
1078 snprintf(con
->command
, sizeof(con
->command
),
1079 "%s/cgi-bin/admin.cgi", ServerBin
);
1080 con
->options
= con
->uri
+ 6;
1082 else if (strncmp(con
->uri
, "/printers", 9) == 0)
1084 snprintf(con
->command
, sizeof(con
->command
),
1085 "%s/cgi-bin/printers.cgi", ServerBin
);
1086 con
->options
= con
->uri
+ 9;
1088 else if (strncmp(con
->uri
, "/classes", 8) == 0)
1090 snprintf(con
->command
, sizeof(con
->command
),
1091 "%s/cgi-bin/classes.cgi", ServerBin
);
1092 con
->options
= con
->uri
+ 8;
1096 snprintf(con
->command
, sizeof(con
->command
),
1097 "%s/cgi-bin/jobs.cgi", ServerBin
);
1098 con
->options
= con
->uri
+ 5;
1101 if (con
->options
[0] == '/')
1104 if (!SendCommand(con
, con
->command
, con
->options
))
1106 if (!SendError(con
, HTTP_NOT_FOUND
))
1113 LogRequest(con
, HTTP_OK
);
1115 if (con
->http
.version
<= HTTP_1_0
)
1116 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
1118 else if (strncmp(con
->uri
, "/admin/conf/", 12) == 0 &&
1119 (strchr(con
->uri
+ 12, '/') != NULL
||
1120 strlen(con
->uri
) == 12))
1123 * GET can only be done to configuration files under
1127 if (!SendError(con
, HTTP_FORBIDDEN
))
1141 if ((filename
= get_file(con
, &filestats
)) == NULL
)
1143 if (!SendError(con
, HTTP_NOT_FOUND
))
1149 else if (!check_if_modified(con
, &filestats
))
1151 if (!SendError(con
, HTTP_NOT_MODIFIED
))
1159 type
= mimeFileType(MimeDatabase
, filename
);
1161 strcpy(line
, "text/plain");
1163 snprintf(line
, sizeof(line
), "%s/%s", type
->super
, type
->type
);
1165 if (!SendFile(con
, HTTP_OK
, filename
, line
, &filestats
))
1174 case HTTP_POST_RECV
:
1176 * See if the POST request includes a Content-Length field, and if
1177 * so check the length against any limits that are set...
1180 LogMessage(L_DEBUG2
, "POST %s", con
->uri
);
1181 LogMessage(L_DEBUG2
, "CONTENT_TYPE = %s", con
->http
.fields
[HTTP_FIELD_CONTENT_TYPE
]);
1183 if (con
->http
.fields
[HTTP_FIELD_CONTENT_LENGTH
][0] &&
1184 atoi(con
->http
.fields
[HTTP_FIELD_CONTENT_LENGTH
]) > MaxRequestSize
&&
1188 * Request too large...
1191 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1199 else if (atoi(con
->http
.fields
[HTTP_FIELD_CONTENT_LENGTH
]) < 0)
1202 * Negative content lengths are invalid!
1205 if (!SendError(con
, HTTP_BAD_REQUEST
))
1215 * See what kind of POST request this is; for IPP requests the
1216 * content-type field will be "application/ipp"...
1219 if (strcmp(con
->http
.fields
[HTTP_FIELD_CONTENT_TYPE
], "application/ipp") == 0)
1220 con
->request
= ippNew();
1221 else if ((strncmp(con
->uri
, "/admin", 6) == 0 &&
1222 strncmp(con
->uri
, "/admin/conf/", 12) != 0) ||
1223 strncmp(con
->uri
, "/printers", 9) == 0 ||
1224 strncmp(con
->uri
, "/classes", 8) == 0 ||
1225 strncmp(con
->uri
, "/jobs", 5) == 0)
1231 if (strncmp(con
->uri
, "/admin", 6) == 0)
1233 snprintf(con
->command
, sizeof(con
->command
),
1234 "%s/cgi-bin/admin.cgi", ServerBin
);
1235 con
->options
= con
->uri
+ 6;
1237 else if (strncmp(con
->uri
, "/printers", 9) == 0)
1239 snprintf(con
->command
, sizeof(con
->command
),
1240 "%s/cgi-bin/printers.cgi", ServerBin
);
1241 con
->options
= con
->uri
+ 9;
1243 else if (strncmp(con
->uri
, "/classes", 8) == 0)
1245 snprintf(con
->command
, sizeof(con
->command
),
1246 "%s/cgi-bin/classes.cgi", ServerBin
);
1247 con
->options
= con
->uri
+ 8;
1251 snprintf(con
->command
, sizeof(con
->command
),
1252 "%s/cgi-bin/jobs.cgi", ServerBin
);
1253 con
->options
= con
->uri
+ 5;
1256 if (con
->options
[0] == '/')
1259 LogMessage(L_DEBUG2
, "ReadClient() %d command=\"%s\", options = \"%s\"",
1260 con
->http
.fd
, con
->command
, con
->options
);
1262 if (con
->http
.version
<= HTTP_1_0
)
1263 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
1265 else if (!SendError(con
, HTTP_UNAUTHORIZED
))
1272 case HTTP_PUT_RECV
:
1274 * Validate the resource name...
1277 if (strncmp(con
->uri
, "/admin/conf/", 12) != 0 ||
1278 strchr(con
->uri
+ 12, '/') != NULL
||
1279 strlen(con
->uri
) == 12)
1282 * PUT can only be done to configuration files under
1286 if (!SendError(con
, HTTP_FORBIDDEN
))
1296 * See if the PUT request includes a Content-Length field, and if
1297 * so check the length against any limits that are set...
1300 LogMessage(L_DEBUG2
, "PUT %s", con
->uri
);
1301 LogMessage(L_DEBUG2
, "CONTENT_TYPE = %s", con
->http
.fields
[HTTP_FIELD_CONTENT_TYPE
]);
1303 if (con
->http
.fields
[HTTP_FIELD_CONTENT_LENGTH
][0] &&
1304 atoi(con
->http
.fields
[HTTP_FIELD_CONTENT_LENGTH
]) > MaxRequestSize
&&
1308 * Request too large...
1311 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1321 * Open a temporary file to hold the request...
1324 snprintf(con
->filename
, sizeof(con
->filename
), "%s/%08x",
1325 RequestRoot
, request_id
++);
1326 con
->file
= open(con
->filename
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0640);
1327 fchmod(con
->file
, 0640);
1328 fchown(con
->file
, User
, Group
);
1330 LogMessage(L_DEBUG2
, "ReadClient() %d REQUEST %s=%d", con
->http
.fd
,
1331 con
->filename
, con
->file
);
1335 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1345 SendError(con
, HTTP_NOT_IMPLEMENTED
);
1346 ShutdownClient(con
);
1350 if (strncmp(con
->uri
, "/printers/", 10) == 0 &&
1351 strcmp(con
->uri
+ strlen(con
->uri
) - 4, ".ppd") == 0)
1354 * Send PPD file - get the real printer name since printer
1355 * names are not case sensitive but filenames can be...
1358 con
->uri
[strlen(con
->uri
) - 4] = '\0'; /* Drop ".ppd" */
1360 if ((p
= FindPrinter(con
->uri
+ 10)) != NULL
)
1361 snprintf(con
->uri
, sizeof(con
->uri
), "/ppd/%s.ppd", p
->name
);
1364 if (!SendError(con
, HTTP_NOT_FOUND
))
1374 if ((strncmp(con
->uri
, "/admin/", 7) == 0 &&
1375 strncmp(con
->uri
, "/admin/conf/", 12) != 0) ||
1376 strncmp(con
->uri
, "/printers/", 10) == 0 ||
1377 strncmp(con
->uri
, "/classes/", 9) == 0 ||
1378 strncmp(con
->uri
, "/jobs/", 6) == 0)
1384 if (!SendHeader(con
, HTTP_OK
, "text/html"))
1390 if (httpPrintf(HTTP(con
), "\r\n") < 0)
1396 LogRequest(con
, HTTP_OK
);
1398 else if (strncmp(con
->uri
, "/admin/conf/", 12) == 0 &&
1399 (strchr(con
->uri
+ 12, '/') != NULL
||
1400 strlen(con
->uri
) == 12))
1403 * HEAD can only be done to configuration files under
1407 if (!SendError(con
, HTTP_FORBIDDEN
))
1415 else if ((filename
= get_file(con
, &filestats
)) == NULL
)
1417 if (!SendHeader(con
, HTTP_NOT_FOUND
, "text/html"))
1423 LogRequest(con
, HTTP_NOT_FOUND
);
1425 else if (!check_if_modified(con
, &filestats
))
1427 if (!SendError(con
, HTTP_NOT_MODIFIED
))
1433 LogRequest(con
, HTTP_NOT_MODIFIED
);
1441 type
= mimeFileType(MimeDatabase
, filename
);
1443 strcpy(line
, "text/plain");
1445 snprintf(line
, sizeof(line
), "%s/%s", type
->super
, type
->type
);
1447 if (!SendHeader(con
, HTTP_OK
, line
))
1453 if (httpPrintf(HTTP(con
), "Last-Modified: %s\r\n",
1454 httpGetDateString(filestats
.st_mtime
)) < 0)
1460 if (httpPrintf(HTTP(con
), "Content-Length: %lu\r\n",
1461 (unsigned long)filestats
.st_size
) < 0)
1467 LogRequest(con
, HTTP_OK
);
1470 if (httpPrintf(HTTP(con
), "\r\n") < 0)
1476 con
->http
.state
= HTTP_WAITING
;
1480 break; /* Anti-compiler-warning-code */
1486 * Handle any incoming data...
1489 switch (con
->http
.state
)
1491 case HTTP_PUT_RECV
:
1492 LogMessage(L_DEBUG2
, "ReadClient() %d con->data_encoding = %s, con->data_remaining = %d, con->file = %d",
1494 con
->http
.data_encoding
== HTTP_ENCODE_CHUNKED
? "chunked" : "length",
1495 con
->http
.data_remaining
, con
->file
);
1497 if ((bytes
= httpRead(HTTP(con
), line
, sizeof(line
))) < 0)
1504 con
->bytes
+= bytes
;
1506 LogMessage(L_DEBUG2
, "ReadClient() %d writing %d bytes to %d",
1507 con
->http
.fd
, bytes
, con
->file
);
1509 if (write(con
->file
, line
, bytes
) < bytes
)
1511 LogMessage(L_ERROR
, "ReadClient: Unable to write %d bytes to %s: %s",
1512 bytes
, con
->filename
, strerror(errno
));
1514 LogMessage(L_DEBUG2
, "ReadClient: Closing data file %d...",
1519 unlink(con
->filename
);
1520 con
->filename
[0] = '\0';
1522 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1530 if (con
->http
.state
== HTTP_WAITING
)
1533 * End of file, see how big it is...
1536 fstat(con
->file
, &filestats
);
1538 LogMessage(L_DEBUG2
, "ReadClient() %d Closing data file %d, size = %d.",
1539 con
->http
.fd
, con
->file
, (int)filestats
.st_size
);
1544 if (filestats
.st_size
> MaxRequestSize
&&
1548 * Request is too big; remove it and send an error...
1551 LogMessage(L_DEBUG2
, "ReadClient() %d Removing temp file %s",
1552 con
->http
.fd
, con
->filename
);
1553 unlink(con
->filename
);
1554 con
->filename
[0] = '\0';
1556 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1564 * Install the configuration file...
1567 status
= install_conf_file(con
);
1570 * Return the status to the client...
1573 if (!SendError(con
, status
))
1581 case HTTP_POST_RECV
:
1582 LogMessage(L_DEBUG2
, "ReadClient() %d con->data_encoding = %s, con->data_remaining = %d, con->file = %d",
1584 con
->http
.data_encoding
== HTTP_ENCODE_CHUNKED
? "chunked" : "length",
1585 con
->http
.data_remaining
, con
->file
);
1587 if (con
->request
!= NULL
)
1590 * Grab any request data from the connection...
1593 if ((ipp_state
= ippRead(&(con
->http
), con
->request
)) == IPP_ERROR
)
1595 LogMessage(L_ERROR
, "ReadClient() %d IPP Read Error!",
1598 if (!SendError(con
, HTTP_BAD_REQUEST
))
1604 ShutdownClient(con
);
1607 else if (ipp_state
!= IPP_DATA
)
1610 con
->bytes
+= ippLength(con
->request
);
1613 if (con
->file
== 0 && con
->http
.state
!= HTTP_POST_SEND
)
1616 * Create a file as needed for the request data...
1619 snprintf(con
->filename
, sizeof(con
->filename
), "%s/%08x",
1620 RequestRoot
, request_id
++);
1621 con
->file
= open(con
->filename
, O_WRONLY
| O_CREAT
| O_TRUNC
, 0640);
1622 fchmod(con
->file
, 0640);
1623 fchown(con
->file
, User
, Group
);
1625 LogMessage(L_DEBUG2
, "ReadClient() %d REQUEST %s=%d", con
->http
.fd
,
1626 con
->filename
, con
->file
);
1630 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1638 if (con
->http
.state
!= HTTP_POST_SEND
)
1640 if ((bytes
= httpRead(HTTP(con
), line
, sizeof(line
))) < 0)
1647 con
->bytes
+= bytes
;
1649 LogMessage(L_DEBUG2
, "ReadClient() %d writing %d bytes to %d",
1650 con
->http
.fd
, bytes
, con
->file
);
1652 if (write(con
->file
, line
, bytes
) < bytes
)
1654 LogMessage(L_ERROR
, "ReadClient: Unable to write %d bytes to %s: %s",
1655 bytes
, con
->filename
, strerror(errno
));
1657 LogMessage(L_DEBUG2
, "ReadClient: Closing file %d...",
1662 unlink(con
->filename
);
1663 con
->filename
[0] = '\0';
1665 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1672 else if (con
->http
.state
!= HTTP_POST_SEND
)
1679 if (con
->http
.state
== HTTP_POST_SEND
)
1683 fstat(con
->file
, &filestats
);
1685 LogMessage(L_DEBUG2
, "ReadClient() %d Closing data file %d, size = %d.",
1686 con
->http
.fd
, con
->file
, (int)filestats
.st_size
);
1691 if (filestats
.st_size
> MaxRequestSize
&&
1695 * Request is too big; remove it and send an error...
1698 LogMessage(L_DEBUG2
, "ReadClient() %d Removing temp file %s",
1699 con
->http
.fd
, con
->filename
);
1700 unlink(con
->filename
);
1701 con
->filename
[0] = '\0';
1706 * Delete any IPP request data...
1709 ippDelete(con
->request
);
1710 con
->request
= NULL
;
1713 if (!SendError(con
, HTTP_REQUEST_TOO_LARGE
))
1720 if (con
->command
[0])
1722 if (!SendCommand(con
, con
->command
, con
->options
))
1724 if (!SendError(con
, HTTP_NOT_FOUND
))
1731 LogRequest(con
, HTTP_OK
);
1736 return (ProcessIPPRequest(con
));
1741 break; /* Anti-compiler-warning-code */
1744 if (!con
->http
.keep_alive
&& con
->http
.state
== HTTP_WAITING
)
1755 * 'SendCommand()' - Send output from a command via HTTP.
1759 SendCommand(client_t
*con
,
1766 if (con
->filename
[0])
1767 fd
= open(con
->filename
, O_RDONLY
);
1769 fd
= open("/dev/null", O_RDONLY
);
1771 con
->pipe_pid
= pipe_command(con
, fd
, &(con
->file
), command
, options
);
1775 LogMessage(L_INFO
, "Started \"%s\" (pid=%d)", command
, con
->pipe_pid
);
1777 LogMessage(L_DEBUG
, "SendCommand() %d file=%d", con
->http
.fd
, con
->file
);
1779 if (con
->pipe_pid
== 0)
1782 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
1784 LogMessage(L_DEBUG2
, "SendCommand: Adding fd %d to InputSet...", con
->file
);
1785 LogMessage(L_DEBUG2
, "SendCommand: Adding fd %d to OutputSet...",
1788 FD_SET(con
->file
, &InputSet
);
1789 FD_SET(con
->http
.fd
, &OutputSet
);
1791 if (!SendHeader(con
, HTTP_OK
, NULL
))
1794 if (con
->http
.version
== HTTP_1_1
)
1796 con
->http
.data_encoding
= HTTP_ENCODE_CHUNKED
;
1798 if (httpPrintf(HTTP(con
), "Transfer-Encoding: chunked\r\n") < 0)
1802 con
->got_fields
= 0;
1810 * 'SendError()' - Send an error message via HTTP.
1813 int /* O - 1 if successful, 0 otherwise */
1814 SendError(client_t
*con
, /* I - Connection */
1815 http_status_t code
) /* I - Error code */
1817 char message
[1024]; /* Message for user */
1821 * Put the request in the access_log file...
1824 if (con
->operation
> HTTP_WAITING
)
1825 LogRequest(con
, code
);
1827 LogMessage(L_DEBUG
, "SendError() %d code=%d", con
->http
.fd
, code
);
1830 * To work around bugs in some proxies, don't use Keep-Alive for some
1834 if (code
>= HTTP_BAD_REQUEST
)
1835 con
->http
.keep_alive
= HTTP_KEEPALIVE_OFF
;
1838 * Send an error message back to the client. If the error code is a
1839 * 400 or 500 series, make sure the message contains some text, too!
1842 if (!SendHeader(con
, code
, NULL
))
1846 if (code
== HTTP_UPGRADE_REQUIRED
)
1847 if (httpPrintf(HTTP(con
), "Connection: Upgrade\r\n") < 0)
1850 if (httpPrintf(HTTP(con
), "Upgrade: TLS/1.0,HTTP/1.1\r\n") < 0)
1852 #endif /* HAVE_SSL */
1854 if ((con
->http
.version
>= HTTP_1_1
&& !con
->http
.keep_alive
) ||
1855 (code
>= HTTP_BAD_REQUEST
&& code
!= HTTP_UPGRADE_REQUIRED
))
1857 if (httpPrintf(HTTP(con
), "Connection: close\r\n") < 0)
1861 if (code
>= HTTP_BAD_REQUEST
)
1864 * Send a human-readable error message.
1867 snprintf(message
, sizeof(message
),
1868 "<HTML><HEAD><TITLE>%d %s</TITLE></HEAD>"
1869 "<BODY><H1>%s</H1>%s</BODY></HTML>\n",
1870 code
, httpStatus(code
), httpStatus(code
),
1871 con
->language
? con
->language
->messages
[code
] :
1874 if (httpPrintf(HTTP(con
), "Content-Type: text/html\r\n") < 0)
1876 if (httpPrintf(HTTP(con
), "Content-Length: %d\r\n",
1877 (int)strlen(message
)) < 0)
1879 if (httpPrintf(HTTP(con
), "\r\n") < 0)
1881 if (httpPrintf(HTTP(con
), "%s", message
) < 0)
1884 else if (httpPrintf(HTTP(con
), "\r\n") < 0)
1887 con
->http
.state
= HTTP_WAITING
;
1894 * 'SendFile()' - Send a file via HTTP.
1898 SendFile(client_t
*con
,
1902 struct stat
*filestats
)
1904 con
->file
= open(filename
, O_RDONLY
);
1906 LogMessage(L_DEBUG
, "SendFile() %d file=%d", con
->http
.fd
, con
->file
);
1911 fcntl(con
->file
, F_SETFD
, fcntl(con
->file
, F_GETFD
) | FD_CLOEXEC
);
1915 if (!SendHeader(con
, code
, type
))
1918 if (httpPrintf(HTTP(con
), "Last-Modified: %s\r\n", httpGetDateString(filestats
->st_mtime
)) < 0)
1920 if (httpPrintf(HTTP(con
), "Content-Length: %lu\r\n",
1921 (unsigned long)filestats
->st_size
) < 0)
1923 if (httpPrintf(HTTP(con
), "\r\n") < 0)
1926 LogMessage(L_DEBUG2
, "SendFile: Adding fd %d to OutputSet...", con
->http
.fd
);
1928 FD_SET(con
->http
.fd
, &OutputSet
);
1935 * 'SendHeader()' - Send an HTTP request.
1938 int /* O - 1 on success, 0 on failure */
1939 SendHeader(client_t
*con
, /* I - Client to send to */
1940 http_status_t code
, /* I - HTTP status code */
1941 char *type
) /* I - MIME type of document */
1943 location_t
*loc
; /* Authentication location */
1946 if (httpPrintf(HTTP(con
), "HTTP/%d.%d %d %s\r\n", con
->http
.version
/ 100,
1947 con
->http
.version
% 100, code
, httpStatus(code
)) < 0)
1949 if (httpPrintf(HTTP(con
), "Date: %s\r\n", httpGetDateString(time(NULL
))) < 0)
1951 if (httpPrintf(HTTP(con
), "Server: CUPS/1.1\r\n") < 0)
1953 if (con
->http
.keep_alive
&& con
->http
.version
>= HTTP_1_0
)
1955 if (httpPrintf(HTTP(con
), "Connection: Keep-Alive\r\n") < 0)
1957 if (httpPrintf(HTTP(con
), "Keep-Alive: timeout=%d\r\n", KeepAliveTimeout
) < 0)
1960 if (code
== HTTP_METHOD_NOT_ALLOWED
)
1961 if (httpPrintf(HTTP(con
), "Allow: GET, HEAD, OPTIONS, POST\r\n") < 0)
1964 if (code
== HTTP_UNAUTHORIZED
)
1967 * This already succeeded in IsAuthorized...
1970 loc
= FindBest(con
->uri
, con
->http
.state
);
1972 if (loc
->type
!= AUTH_DIGEST
)
1974 if (httpPrintf(HTTP(con
), "WWW-Authenticate: Basic realm=\"CUPS\"\r\n") < 0)
1979 if (httpPrintf(HTTP(con
), "WWW-Authenticate: Digest realm=\"CUPS\" "
1980 "nonce=\"%s\"\r\n", con
->http
.hostname
) < 0)
1984 if (con
->language
!= NULL
)
1986 if (httpPrintf(HTTP(con
), "Content-Language: %s\r\n",
1987 con
->language
->language
) < 0)
1991 if (httpPrintf(HTTP(con
), "Content-Type: %s; charset=%s\r\n", type
,
1992 cupsLangEncoding(con
->language
)) < 0)
1995 else if (type
!= NULL
)
1996 if (httpPrintf(HTTP(con
), "Content-Type: %s\r\n", type
) < 0)
2004 * 'ShutdownClient()' - Shutdown the receiving end of a connection.
2008 ShutdownClient(client_t
*con
) /* I - Client connection */
2011 * Shutdown the receiving end of the socket, since the client
2012 * still needs to read the error message...
2015 shutdown(con
->http
.fd
, 0);
2019 * Update the activity time so that we timeout after 30 seconds rather
2020 * then the current Timeout setting (300 by default). This prevents
2021 * some DoS situations...
2024 con
->http
.activity
= time(NULL
) - Timeout
+ 30;
2026 LogMessage(L_DEBUG2
, "ShutdownClient: Removing fd %d from InputSet...",
2029 FD_CLR(con
->http
.fd
, &InputSet
);
2034 * 'WriteClient()' - Write data to a client as needed.
2037 int /* O - 1 if success, 0 if fail */
2038 WriteClient(client_t
*con
) /* I - Client connection */
2040 int bytes
; /* Number of bytes written */
2041 char buf
[HTTP_MAX_BUFFER
+ 1];/* Data buffer */
2042 char *bufptr
; /* Pointer into buffer */
2043 ipp_state_t ipp_state
; /* IPP state value */
2046 if (con
->http
.state
!= HTTP_GET_SEND
&&
2047 con
->http
.state
!= HTTP_POST_SEND
)
2050 if (con
->response
!= NULL
)
2052 ipp_state
= ippWrite(&(con
->http
), con
->response
);
2053 bytes
= ipp_state
!= IPP_ERROR
&& ipp_state
!= IPP_DATA
;
2055 else if ((bytes
= read(con
->file
, buf
, HTTP_MAX_BUFFER
)) > 0)
2057 if (con
->pipe_pid
&& !con
->got_fields
)
2060 * Inspect the data for Content-Type and other fields.
2065 for (bufptr
= buf
; !con
->got_fields
&& *bufptr
; bufptr
++)
2066 if (*bufptr
== '\n')
2069 * Send line to client...
2072 if (bufptr
> buf
&& bufptr
[-1] == '\r')
2076 httpPrintf(HTTP(con
), "%s\r\n", buf
);
2077 LogMessage(L_DEBUG2
, "WriteClient() %d %s", con
->http
.fd
, buf
);
2083 bytes
-= (bufptr
- buf
);
2084 memcpy(buf
, bufptr
, bytes
+ 1);
2088 * See if the line was empty...
2091 if (con
->field_col
== 0)
2092 con
->got_fields
= 1;
2096 else if (*bufptr
!= '\r')
2099 if (bytes
> 0 && !con
->got_fields
)
2102 * Remaining text needs to go out...
2105 httpPrintf(HTTP(con
), "%s", buf
);
2107 con
->http
.activity
= time(NULL
);
2110 else if (bytes
== 0)
2112 con
->http
.activity
= time(NULL
);
2117 if (httpWrite(HTTP(con
), buf
, bytes
) < 0)
2123 con
->bytes
+= bytes
;
2128 LogRequest(con
, HTTP_OK
);
2130 if (con
->http
.data_encoding
== HTTP_ENCODE_CHUNKED
)
2132 if (httpPrintf(HTTP(con
), "0\r\n\r\n") < 0)
2139 con
->http
.state
= HTTP_WAITING
;
2141 LogMessage(L_DEBUG2
, "WriteClient() Removing fd %d from OutputSet...",
2144 FD_CLR(con
->http
.fd
, &OutputSet
);
2148 LogMessage(L_DEBUG2
, "WriteClient() Removing fd %d from InputSet...",
2150 FD_CLR(con
->file
, &InputSet
);
2153 kill(con
->pipe_pid
, SIGTERM
);
2155 LogMessage(L_DEBUG2
, "WriteClient() %d Closing data file %d.",
2156 con
->http
.fd
, con
->file
);
2163 if (con
->filename
[0])
2165 LogMessage(L_DEBUG2
, "WriteClient() %d Removing temp file %s",
2166 con
->http
.fd
, con
->filename
);
2167 unlink(con
->filename
);
2168 con
->filename
[0] = '\0';
2171 if (con
->request
!= NULL
)
2173 ippDelete(con
->request
);
2174 con
->request
= NULL
;
2177 if (con
->response
!= NULL
)
2179 ippDelete(con
->response
);
2180 con
->response
= NULL
;
2183 if (!con
->http
.keep_alive
)
2191 LogMessage(L_DEBUG2
, "WriteClient() %d %d bytes", con
->http
.fd
, bytes
);
2193 con
->http
.activity
= time(NULL
);
2200 * 'check_if_modified()' - Decode an "If-Modified-Since" line.
2203 static int /* O - 1 if modified since */
2204 check_if_modified(client_t
*con
, /* I - Client connection */
2205 struct stat
*filestats
) /* I - File information */
2207 char *ptr
; /* Pointer into field */
2208 time_t date
; /* Time/date value */
2209 int size
; /* Size/length value */
2214 ptr
= con
->http
.fields
[HTTP_FIELD_IF_MODIFIED_SINCE
];
2219 LogMessage(L_DEBUG2
, "check_if_modified() %d If-Modified-Since=\"%s\"",
2222 while (*ptr
!= '\0')
2224 while (isspace(*ptr
) || *ptr
== ';')
2227 if (strncasecmp(ptr
, "length=", 7) == 0)
2232 while (isdigit(*ptr
))
2235 else if (isalpha(*ptr
))
2237 date
= httpGetDateTime(ptr
);
2238 while (*ptr
!= '\0' && *ptr
!= ';')
2243 LogMessage(L_DEBUG2
, "check_if_modified() %d sizes=%d,%d dates=%d,%d",
2244 con
->http
.fd
, size
, (int)filestats
->st_size
, (int)date
,
2245 (int)filestats
->st_mtime
);
2247 return ((size
!= filestats
->st_size
&& size
!= 0) ||
2248 (date
< filestats
->st_mtime
&& date
!= 0) ||
2249 (size
== 0 && date
== 0));
2254 * 'decode_auth()' - Decode an authorization string.
2258 decode_auth(client_t
*con
) /* I - Client to decode to */
2260 char *s
, /* Authorization string */
2261 value
[1024]; /* Value string */
2262 const char *username
; /* Certificate username */
2266 * Decode the string...
2269 s
= con
->http
.fields
[HTTP_FIELD_AUTHORIZATION
];
2271 LogMessage(L_DEBUG2
, "decode_auth(%p): Authorization string = \"%s\"",
2274 if (strncmp(s
, "Basic", 5) == 0)
2280 httpDecode64(value
, s
);
2283 * Pull the username and password out...
2286 if ((s
= strchr(value
, ':')) == NULL
)
2288 LogMessage(L_DEBUG
, "decode_auth() %d no colon in auth string \"%s\"",
2289 con
->http
.fd
, value
);
2295 strlcpy(con
->username
, value
, sizeof(con
->username
));
2296 strlcpy(con
->password
, s
, sizeof(con
->password
));
2298 else if (strncmp(s
, "Local", 5) == 0)
2304 if ((username
= FindCert(s
)) != NULL
)
2305 strlcpy(con
->username
, username
, sizeof(con
->username
));
2307 else if (strncmp(s
, "Digest", 5) == 0)
2310 * Get the username and password from the Digest attributes...
2313 if (httpGetSubField(&(con
->http
), HTTP_FIELD_WWW_AUTHENTICATE
, "username",
2315 strlcpy(con
->username
, value
, sizeof(con
->username
));
2317 if (httpGetSubField(&(con
->http
), HTTP_FIELD_WWW_AUTHENTICATE
, "response",
2319 strlcpy(con
->password
, value
, sizeof(con
->password
) - 1);
2322 LogMessage(L_DEBUG2
, "decode_auth() %d username=\"%s\"",
2323 con
->http
.fd
, con
->username
);
2328 * 'get_file()' - Get a filename and state info.
2331 static char * /* O - Real filename */
2332 get_file(client_t
*con
, /* I - Client connection */
2333 struct stat
*filestats
)/* O - File information */
2335 int status
; /* Status of filesystem calls */
2336 char *params
; /* Pointer to parameters in URI */
2337 static char filename
[1024]; /* Filename buffer */
2341 * Need to add DocumentRoot global...
2344 if (strncmp(con
->uri
, "/ppd/", 5) == 0)
2345 snprintf(filename
, sizeof(filename
), "%s%s", ServerRoot
, con
->uri
);
2346 else if (strncmp(con
->uri
, "/admin/conf/", 12) == 0)
2347 snprintf(filename
, sizeof(filename
), "%s%s", ServerRoot
, con
->uri
+ 11);
2348 else if (con
->language
!= NULL
)
2349 snprintf(filename
, sizeof(filename
), "%s/%s%s", DocumentRoot
, con
->language
->language
,
2352 snprintf(filename
, sizeof(filename
), "%s%s", DocumentRoot
, con
->uri
);
2354 if ((params
= strchr(filename
, '?')) != NULL
)
2358 * Grab the status for this language; if there isn't a language-specific file
2359 * then fallback to the default one...
2362 if ((status
= stat(filename
, filestats
)) != 0 && con
->language
!= NULL
)
2365 * Drop the language prefix and try the current directory...
2368 if (strncmp(con
->uri
, "/ppd/", 5) != 0 &&
2369 strncmp(con
->uri
, "/admin/conf/", 12) != 0)
2371 snprintf(filename
, sizeof(filename
), "%s%s", DocumentRoot
, con
->uri
);
2373 status
= stat(filename
, filestats
);
2378 * If we're found a directory, get the index.html file instead...
2381 if (!status
&& S_ISDIR(filestats
->st_mode
))
2383 if (filename
[strlen(filename
) - 1] == '/')
2384 strlcat(filename
, "index.html", sizeof(filename
));
2386 strlcat(filename
, "/index.html", sizeof(filename
));
2388 status
= stat(filename
, filestats
);
2391 LogMessage(L_DEBUG2
, "get_file() %d filename=%s size=%d",
2392 con
->http
.fd
, filename
, status
? -1 : (int)filestats
->st_size
);
2402 * 'install_conf_file()' - Install a configuration file.
2405 static http_status_t
/* O - Status */
2406 install_conf_file(client_t
*con
) /* I - Connection */
2408 FILE *in
, /* Input file */
2409 *out
; /* Output file */
2410 char buffer
[1024]; /* Copy buffer */
2411 int bytes
; /* Number of bytes */
2412 char conffile
[1024], /* Configuration filename */
2413 newfile
[1024], /* New config filename */
2414 oldfile
[1024]; /* Old config filename */
2415 struct stat confinfo
; /* Config file info */
2419 * First construct the filenames...
2422 snprintf(conffile
, sizeof(conffile
), "%s%s", ServerRoot
, con
->uri
+ 11);
2423 snprintf(newfile
, sizeof(newfile
), "%s%s.N", ServerRoot
, con
->uri
+ 11);
2424 snprintf(oldfile
, sizeof(oldfile
), "%s%s.O", ServerRoot
, con
->uri
+ 11);
2426 LogMessage(L_INFO
, "Installing config file \"%s\"...", conffile
);
2429 * Get the owner, group, and permissions of the configuration file.
2430 * If it doesn't exist, assign it to the User and Group in the
2431 * cupsd.conf file with mode 0640 permissions.
2434 if (stat(conffile
, &confinfo
))
2436 confinfo
.st_uid
= User
;
2437 confinfo
.st_gid
= Group
;
2438 confinfo
.st_mode
= 0640;
2442 * Open the request file and new config file...
2445 if ((in
= fopen(con
->filename
, "rb")) == NULL
)
2447 LogMessage(L_ERROR
, "Unable to open request file \"%s\" - %s",
2448 con
->filename
, strerror(errno
));
2449 return (HTTP_SERVER_ERROR
);
2452 if ((out
= fopen(newfile
, "wb")) == NULL
)
2455 LogMessage(L_ERROR
, "Unable to open config file \"%s\" - %s",
2456 newfile
, strerror(errno
));
2457 return (HTTP_SERVER_ERROR
);
2460 fchmod(fileno(out
), confinfo
.st_mode
);
2461 fchown(fileno(out
), confinfo
.st_uid
, confinfo
.st_gid
);
2464 * Copy from the request to the new config file...
2467 while ((bytes
= fread(buffer
, 1, sizeof(buffer
), in
)) > 0)
2468 if (fwrite(buffer
, 1, bytes
, out
) < bytes
)
2470 LogMessage(L_ERROR
, "Unable to copy to config file \"%s\" - %s",
2471 newfile
, strerror(errno
));
2477 return (HTTP_SERVER_ERROR
);
2481 * Close the files...
2487 LogMessage(L_ERROR
, "Error file closing config file \"%s\" - %s",
2488 newfile
, strerror(errno
));
2492 return (HTTP_SERVER_ERROR
);
2496 * Remove the request file...
2499 unlink(con
->filename
);
2500 con
->filename
[0] = '\0';
2503 * Unlink the old backup, rename the current config file to the backup
2504 * filename, and rename the new config file to the config file name...
2507 if (unlink(oldfile
))
2508 if (errno
!= ENOENT
)
2510 LogMessage(L_ERROR
, "Unable to remove backup config file \"%s\" - %s",
2511 oldfile
, strerror(errno
));
2515 return (HTTP_SERVER_ERROR
);
2518 if (rename(conffile
, oldfile
))
2519 if (errno
!= ENOENT
)
2521 LogMessage(L_ERROR
, "Unable to rename old config file \"%s\" - %s",
2522 conffile
, strerror(errno
));
2526 return (HTTP_SERVER_ERROR
);
2529 if (rename(newfile
, conffile
))
2531 LogMessage(L_ERROR
, "Unable to rename new config file \"%s\" - %s",
2532 newfile
, strerror(errno
));
2534 rename(oldfile
, conffile
);
2537 return (HTTP_SERVER_ERROR
);
2541 * If the cupsd.conf file was updated, set the NeedReload flag...
2544 if (strcmp(con
->uri
, "/admin/conf/cupsd.conf") == 0)
2548 * Return that the file was created successfully...
2551 return (HTTP_CREATED
);
2556 * 'pipe_command()' - Pipe the output of a command to the remote client.
2559 static int /* O - Process ID */
2560 pipe_command(client_t
*con
, /* I - Client connection */
2561 int infile
, /* I - Standard input for command */
2562 int *outfile
, /* O - Standard output for command */
2563 char *command
, /* I - Command to run */
2564 char *options
) /* I - Options for command */
2566 int pid
; /* Process ID */
2567 char *commptr
; /* Command string pointer */
2568 int fd
; /* Looping var */
2569 int fds
[2]; /* Pipe FDs */
2570 int argc
; /* Number of arguments */
2571 int envc
; /* Number of environment variables */
2572 char argbuf
[10240], /* Argument buffer */
2573 *argv
[100], /* Argument strings */
2574 *envp
[100]; /* Environment variables */
2575 char lang
[1024], /* LANG env variable */
2576 content_length
[1024], /* CONTENT_LENGTH env variable */
2577 content_type
[1024], /* CONTENT_TYPE env variable */
2578 ipp_port
[1024], /* Default listen port */
2579 server_port
[1024], /* Default server port */
2580 server_name
[1024], /* Default listen hostname */
2581 remote_host
[1024], /* REMOTE_HOST env variable */
2582 remote_user
[1024], /* REMOTE_USER env variable */
2583 tmpdir
[1024], /* TMPDIR environment variable */
2584 ldpath
[1024], /* LD_LIBRARY_PATH environment variable */
2585 nlspath
[1024], /* NLSPATH environment variable */
2586 datadir
[1024], /* CUPS_DATADIR environment variable */
2587 root
[1024], /* CUPS_SERVERROOT environment variable */
2588 query_string
[10240]; /* QUERY_STRING env variable */
2589 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
2590 sigset_t oldmask
, /* POSIX signal masks */
2592 struct sigaction action
; /* POSIX signal handler */
2593 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
2597 * Copy the command string...
2600 strlcpy(argbuf
, options
, sizeof(argbuf
));
2603 * Parse the string; arguments can be separated by + and are terminated
2609 for (commptr
= argbuf
, argc
= 1; *commptr
!= '\0' && argc
< 99; commptr
++)
2610 if (*commptr
== ' ' || *commptr
== '+')
2614 while (*commptr
== ' ')
2617 if (*commptr
!= '\0')
2619 argv
[argc
] = commptr
;
2625 else if (*commptr
== '%')
2627 if (commptr
[1] >= '0' && commptr
[1] <= '9')
2628 *commptr
= (commptr
[1] - '0') << 4;
2630 *commptr
= (tolower(commptr
[1]) - 'a' + 10) << 4;
2632 if (commptr
[2] >= '0' && commptr
[2] <= '9')
2633 *commptr
|= commptr
[2] - '0';
2635 *commptr
|= tolower(commptr
[2]) - 'a' + 10;
2637 strcpy(commptr
+ 1, commptr
+ 3);
2639 else if (*commptr
== '?')
2644 if (argv
[0][0] == '\0')
2645 argv
[0] = strrchr(command
, '/') + 1;
2648 * Setup the environment variables as needed...
2651 snprintf(lang
, sizeof(lang
), "LANG=%s",
2652 con
->language
? con
->language
->language
: "C");
2654 if (con
->http
.hostaddr
.addr
.sa_family
== AF_INET6
)
2656 sprintf(ipp_port
, "IPP_PORT=%d", ntohs(con
->http
.hostaddr
.ipv6
.sin6_port
));
2657 sprintf(server_port
, "SERVER_PORT=%d",
2658 ntohs(con
->http
.hostaddr
.ipv6
.sin6_port
));
2661 #endif /* AF_INET6 */
2663 sprintf(ipp_port
, "IPP_PORT=%d", ntohs(con
->http
.hostaddr
.ipv4
.sin_port
));
2664 sprintf(server_port
, "SERVER_PORT=%d",
2665 ntohs(con
->http
.hostaddr
.ipv4
.sin_port
));
2668 if (strcmp(con
->http
.hostname
, "localhost") == 0)
2669 strlcpy(server_name
, "SERVER_NAME=localhost", sizeof(server_name
));
2671 snprintf(server_name
, sizeof(server_name
), "SERVER_NAME=%s", ServerName
);
2672 snprintf(remote_host
, sizeof(remote_host
), "REMOTE_HOST=%s", con
->http
.hostname
);
2673 snprintf(remote_user
, sizeof(remote_user
), "REMOTE_USER=%s", con
->username
);
2674 snprintf(tmpdir
, sizeof(tmpdir
), "TMPDIR=%s", TempDir
);
2675 snprintf(datadir
, sizeof(datadir
), "CUPS_DATADIR=%s", DataDir
);
2676 snprintf(root
, sizeof(root
), "CUPS_SERVERROOT=%s", ServerRoot
);
2678 if (getenv("LD_LIBRARY_PATH") != NULL
)
2679 snprintf(ldpath
, sizeof(ldpath
), "LD_LIBRARY_PATH=%s",
2680 getenv("LD_LIBRARY_PATH"));
2681 else if (getenv("DYLD_LIBRARY_PATH") != NULL
)
2682 snprintf(ldpath
, sizeof(ldpath
), "DYLD_LIBRARY_PATH=%s",
2683 getenv("DYLD_LIBRARY_PATH"));
2684 else if (getenv("SHLIB_PATH") != NULL
)
2685 snprintf(ldpath
, sizeof(ldpath
), "SHLIB_PATH=%s",
2686 getenv("SHLIB_PATH"));
2690 if (getenv("NLSPATH") != NULL
)
2691 snprintf(nlspath
, sizeof(nlspath
), "NLSPATH=%s", getenv("NLSPATH"));
2695 envp
[0] = "PATH=/bin:/usr/bin";
2696 envp
[1] = "SERVER_SOFTWARE=CUPS/1.2";
2697 envp
[2] = "GATEWAY_INTERFACE=CGI/1.1";
2698 envp
[3] = "SERVER_PROTOCOL=HTTP/1.1";
2700 envp
[5] = server_name
;
2701 envp
[6] = server_port
;
2702 envp
[7] = remote_host
;
2703 envp
[8] = remote_user
;
2713 envp
[envc
++] = ldpath
;
2716 envp
[envc
++] = nlspath
;
2718 if (con
->operation
== HTTP_GET
)
2720 envp
[envc
++] = "REQUEST_METHOD=GET";
2725 * Add GET form variables after ?...
2730 snprintf(query_string
, sizeof(query_string
), "QUERY_STRING=%s", commptr
);
2731 envp
[envc
++] = query_string
;
2736 sprintf(content_length
, "CONTENT_LENGTH=%d", con
->bytes
);
2737 snprintf(content_type
, sizeof(content_type
), "CONTENT_TYPE=%s",
2738 con
->http
.fields
[HTTP_FIELD_CONTENT_TYPE
]);
2740 envp
[envc
++] = "REQUEST_METHOD=POST";
2741 envp
[envc
++] = content_length
;
2742 envp
[envc
++] = content_type
;
2746 * Tell the CGI if we are using encryption...
2749 if (con
->http
.encryption
== HTTP_ENCRYPT_ALWAYS
)
2751 envp
[envc
++] = "HTTPS=ON";
2752 envp
[envc
++] = "CUPS_ENCRYPTION=Always";
2758 * Create a pipe for the output...
2763 LogMessage(L_ERROR
, "Unable to create pipes for CGI %s - %s",
2764 argv
[0], strerror(errno
));
2769 * Block signals before forking...
2775 #elif defined(HAVE_SIGACTION)
2776 sigemptyset(&newmask
);
2777 sigaddset(&newmask
, SIGTERM
);
2778 sigaddset(&newmask
, SIGCHLD
);
2779 sigprocmask(SIG_BLOCK
, &newmask
, &oldmask
);
2780 #endif /* HAVE_SIGSET */
2783 * Then execute the command...
2786 if ((pid
= fork()) == 0)
2789 * Child comes here... Close stdin if necessary and dup the pipe to stdout.
2795 * Running as root, so change to a non-priviledged user...
2806 * Reset group membership to just the main one we belong to.
2812 * Update stdin/stdout/stderr...
2818 if (dup(infile
) < 0)
2823 if (dup(fds
[1]) < 0)
2827 open("/dev/null", O_WRONLY
);
2830 * Close extra file descriptors...
2833 for (fd
= 3; fd
< MaxFDs
; fd
++)
2837 * Change umask to restrict permissions on created files...
2843 * Unblock signals before doing the exec...
2847 sigset(SIGTERM
, SIG_DFL
);
2848 sigset(SIGCHLD
, SIG_DFL
);
2852 #elif defined(HAVE_SIGACTION)
2853 memset(&action
, 0, sizeof(action
));
2855 sigemptyset(&action
.sa_mask
);
2856 action
.sa_handler
= SIG_DFL
;
2858 sigaction(SIGTERM
, &action
, NULL
);
2859 sigaction(SIGCHLD
, &action
, NULL
);
2861 sigprocmask(SIG_SETMASK
, &oldmask
, NULL
);
2863 signal(SIGTERM
, SIG_DFL
);
2864 signal(SIGCHLD
, SIG_DFL
);
2865 #endif /* HAVE_SIGSET */
2869 * Execute the pipe program; if an error occurs, exit with status 1...
2872 execve(command
, argv
, envp
);
2879 * Error - can't fork!
2882 LogMessage(L_ERROR
, "Unable to fork for CGI %s - %s", argv
[0],
2892 * Fork successful - return the PID...
2895 AddCert(pid
, con
->username
);
2897 LogMessage(L_DEBUG
, "CGI %s started - PID = %d", command
, pid
);
2906 #elif defined(HAVE_SIGACTION)
2907 sigprocmask(SIG_SETMASK
, &oldmask
, NULL
);
2908 #endif /* HAVE_SIGSET */
2914 #if defined(HAVE_CDSASSL)
2916 * 'CDSAReadFunc()' - Read function for CDSA decryption code.
2919 static OSStatus
/* O - -1 on error, 0 on success */
2920 CDSAReadFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2921 void *data
, /* I - Data buffer */
2922 size_t *dataLength
) /* IO - Number of bytes */
2924 ssize_t bytes
; /* Number of bytes read */
2927 bytes
= recv((int)connection
, data
, *dataLength
, 0);
2930 *dataLength
= bytes
;
2939 * 'CDSAWriteFunc()' - Write function for CDSA encryption code.
2942 static OSStatus
/* O - -1 on error, 0 on success */
2943 CDSAWriteFunc(SSLConnectionRef connection
, /* I - SSL/TLS connection */
2944 const void *data
, /* I - Data buffer */
2945 size_t *dataLength
) /* IO - Number of bytes */
2950 bytes
= write((int)connection
, data
, *dataLength
);
2953 *dataLength
= bytes
;
2959 #endif /* HAVE_CDSASSL */
2963 * End of "$Id: client.c,v 1.91.2.39 2003/01/24 19:19:43 mike Exp $".