• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Client definitions for the CUPS scheduler.
3  *
4  * Copyright © 2020-2024 by OpenPrinting.
5  * Copyright © 2007-2018 by Apple Inc.
6  * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
7  *
8  * Licensed under Apache License v2.0.  See the file "LICENSE" for more
9  * information.
10  */
11 
12 #ifdef HAVE_AUTHORIZATION_H
13 #  include <Security/Authorization.h>
14 #endif /* HAVE_AUTHORIZATION_H */
15 
16 
17 /*
18  * HTTP client structure...
19  */
20 
21 struct cupsd_client_s
22 {
23   int			number;		/* Connection number */
24   http_t		*http;		/* HTTP client connection */
25   ipp_t			*request,	/* IPP request information */
26 			*response;	/* IPP response information */
27   cupsd_location_t	*best;		/* Best match for AAA */
28   struct timeval	start;		/* Request start time */
29   http_state_t		operation;	/* Request operation */
30   off_t			bytes;		/* Bytes transferred for this request */
31   int			is_browser;	/* Is the client a web browser? */
32   int			type;		/* AuthType for username */
33   char			username[HTTP_MAX_VALUE],
34 					/* Username from Authorization: line */
35 			password[HTTP_MAX_VALUE],
36 					/* Password from Authorization: line */
37 			uri[HTTP_MAX_URI],
38 					/* Localized URL/URI for GET/PUT */
39 			*filename,	/* Filename of output file */
40 			*command,	/* Command to run */
41 			*options,	/* Options for command */
42 			*query_string;	/* QUERY_STRING environment variable */
43   int			file;		/* Input/output file */
44   int			file_ready;	/* Input ready on file/pipe? */
45   int			bg_pending;	/* Background response pending? */
46   cupsd_printer_t	*bg_printer;	/* Background printer */
47   int			pipe_pid;	/* Pipe process ID (or 0 if not a pipe) */
48   http_status_t		pipe_status;	/* HTTP status from pipe process */
49   int			sent_header,	/* Non-zero if sent HTTP header */
50 			got_fields,	/* Non-zero if all fields seen */
51 			header_used;	/* Number of header bytes used */
52   char			header[2048];	/* Header from CGI program */
53   cups_lang_t		*language;	/* Language to use */
54 #ifdef HAVE_TLS
55   int			auto_ssl;	/* Automatic test for SSL/TLS */
56 #endif /* HAVE_TLS */
57   http_addr_t		clientaddr;	/* Client's server address */
58   char			clientname[256];/* Client's server name for connection */
59   int			clientport;	/* Client's server port for connection */
60   char			servername[256];/* Server name for connection */
61   int			serverport;	/* Server port for connection */
62 #ifdef HAVE_GSSAPI
63   int			have_gss;	/* Have GSS credentials? */
64   uid_t			gss_uid;	/* User ID for local prints */
65 #endif /* HAVE_GSSAPI */
66 #ifdef HAVE_AUTHORIZATION_H
67   AuthorizationRef	authref;	/* Authorization ref */
68 #endif /* HAVE_AUTHORIZATION_H */
69 };
70 
71 #define HTTP(con) ((con)->http)
72 
73 
74 /*
75  * HTTP listener structure...
76  */
77 
78 typedef struct
79 {
80   int			fd;		/* File descriptor for this server */
81   http_addr_t		address;	/* Bind address of socket */
82   http_encryption_t	encryption;	/* To encrypt or not to encrypt... */
83 #ifdef HAVE_ONDEMAND
84   int			on_demand;	/* Is this a socket from launchd/systemd/upstart? */
85 #endif /* HAVE_ONDEMAND */
86 } cupsd_listener_t;
87 
88 
89 /*
90  * Globals...
91  */
92 
93 VAR int			LastClientNumber VALUE(0),
94 					/* Last client connection number */
95 			LocalPort	VALUE(631),
96 					/* Local port to use */
97 			RemotePort	VALUE(0);
98 					/* Remote port to use */
99 VAR http_encryption_t	LocalEncryption	VALUE(HTTP_ENCRYPT_IF_REQUESTED);
100 					/* Local port encryption to use */
101 VAR cups_array_t	*Listeners	VALUE(NULL);
102 					/* Listening sockets */
103 VAR time_t		ListeningPaused	VALUE(0);
104 					/* Time when listening was paused */
105 VAR cups_array_t	*Clients	VALUE(NULL),
106 					/* HTTP clients */
107 			*ActiveClients	VALUE(NULL);
108 					/* Active HTTP clients */
109 VAR char		*ServerHeader	VALUE(NULL);
110 					/* Server header in requests */
111 VAR int			CGIPipes[2]	VALUE2(-1,-1);
112 					/* Pipes for CGI error/debug output */
113 VAR cupsd_statbuf_t	*CGIStatusBuffer VALUE(NULL);
114 					/* Status buffer for pipes */
115 
116 
117 /*
118  * Prototypes...
119  */
120 
121 extern void	cupsdAcceptClient(cupsd_listener_t *lis);
122 extern void	cupsdCloseAllClients(void);
123 extern int	cupsdCloseClient(cupsd_client_t *con);
124 extern void	cupsdDeleteAllListeners(void);
125 extern void	cupsdPauseListening(void);
126 extern int	cupsdProcessIPPRequest(cupsd_client_t *con);
127 extern void	cupsdReadClient(cupsd_client_t *con);
128 extern void	cupsdResumeListening(void);
129 extern int	cupsdSendCommand(cupsd_client_t *con, char *command,
130 		                 char *options, int root);
131 extern int	cupsdSendError(cupsd_client_t *con, http_status_t code,
132 		               int auth_type);
133 extern int	cupsdSendHeader(cupsd_client_t *con, http_status_t code,
134 		                char *type, int auth_type);
135 extern void	cupsdShutdownClient(cupsd_client_t *con);
136 extern void	cupsdStartListening(void);
137 extern void	cupsdStopListening(void);
138 extern void	cupsdUpdateCGI(void);
139 extern void	cupsdWriteClient(cupsd_client_t *con);
140 
141 #ifdef HAVE_TLS
142 extern int	cupsdEndTLS(cupsd_client_t *con);
143 extern int	cupsdStartTLS(cupsd_client_t *con);
144 #endif /* HAVE_TLS */
145