1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
WARNING: This file was generated by dkct.
Changes you make here will be lost if dkct is run again!
You should modify the original source and run dkct on it.
Original source: printqd.ctr
*/
/*
Copyright (C) 2016-2017, Dirk Krause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef PRINTQD_H_INCLUDED
/** Avoid multiple inclusions. */
#define PRINTQD_H_INCLUDED 1
#line 10 "printqd.ctr"
/* CORRECT NEXT LINE AFTER REPLACING PRINTQD */
/** @file printqd.h Definitions for printqd.
*/
#ifndef DK4CONF_H_INCLUDED
#include "dk4conf.h"
#endif
#ifndef DK4TYPES_H_INCLUDED
#include "dk4types.h"
#endif
#ifndef DK4STO_H_INCLUDED
#include "dk4sto.h"
#endif
#ifndef DK4SOCK_H_INCLUDED
#include "dk4sock.h"
#endif
/** Limit for one user or group.
*/
typedef struct {
char *name; /**< User or group name */
dk4_um_t limit; /**< Page limit. */
} pqd_limit_t;
/** Printer class (may contain multiple printers).
*/
typedef struct {
char *name; /**< Class name. */
dk4_sto_t *s_u; /**< User limits storage. */
dk4_sto_it_t *i_u; /**< User limits storage iterator. */
dk4_sto_t *s_g; /**< Group limits storage. */
dk4_sto_it_t *i_g; /**< Group limits storage iterator. */
dk4_um_t dl; /**< Default limit. */
int da; /**< Deny action: 1=hold, 0=remove. */
int hdl; /**< Flag: Have default limit. */
} pqd_class_t;
/** Printer.
*/
typedef struct {
char *name; /**< Printer name. */
pqd_class_t *cl; /**< Printer class. */
} pqd_printer_t;
/*
In service the class is not NULL.
If no class is configured for a printer, the program complains
and exits.
*/
/** Printer alias.
*/
typedef struct {
char *name; /**< Alias name. */
pqd_printer_t *pr; /**< The real printer. */
} pqd_printer_alias_t;
/** Printqd configuration.
*/
typedef struct {
char *sname; /**< UNIX domain socket file name. */
char *dname; /**< Database name (including type). */
char *lname; /**< Log file name. */
dk4_sto_t *s_c; /**< Storage for classes. */
dk4_sto_it_t *i_c; /**< Iterator for class storage. */
dk4_sto_t *s_p; /**< Storage for printers. */
dk4_sto_it_t *i_p; /**< Iterator for printers storage. */
dk4_sto_t *s_a; /**< Storage for aliases. */
dk4_sto_it_t *i_a; /**< Iterator for aliases storage. */
dk4_sto_t *s_ai; /**< Storage for peers allowed info rq. */
dk4_sto_it_t *i_ai; /**< Iterator for info peers storage. */
dk4_sto_t *s_ad; /**< Storage for peers allowed data rq. */
dk4_sto_it_t *i_ad; /**< Iterator for data peers storage. */
dk4_sto_t *s_aa; /**< Storage for peers allowed admin rq. */
dk4_sto_it_t *i_aa; /**< Iterator for admin peers storage. */
size_t m_loc; /**< Maximum number of local connections. */
size_t m_tcp; /**< Maximum number of TCP connections. */
uid_t uid; /**< Run as specified user. */
uid_t suid; /**< Local socket owner UID. */
gid_t gid; /**< Run as specified group. */
gid_t sgid; /**< Local socket owner GID. */
int slbl; /**< Backlog for local socket. */
int snbl; /**< Backlog for network socket. */
int iglo; /**< Flag: Globally allow info requests. */
int dglo; /**< Flag: Globally allow data requests. */
int aglo; /**< Flag: Globally allow admin requests. */
int linf; /**< Flag: Log info requests. */
int ldb; /**< Flag: Log database modifications. */
unsigned short ptcp; /**< TCP port (info, data, admin), host repr. */
unsigned short pudp; /**< UDP port (info only), host represent. */
} pqd_conf_t;
/** Connection record for local socket.
*/
typedef struct {
dk4_socket_t sock; /**< Socket. */
} pqd_l_conn_t;
/** Connection record for network socket.
*/
typedef struct {
dk4_sockaddr_storage_t raddr; /**< Remote address. */
dk4_socket_t sock; /**< Socket. */
int pqdpl; /**< Printqd protocol level. */
} pqd_n_conn_t;
/** One request to process.
*/
typedef struct {
void *connptr; /**< Connection record for socket. */
dk4_sto_t *sto; /**< Container for conn records. */
struct sockaddr *soa; /**< Remote address, only UDP. */
size_t *pnconn; /**< Addr of variable, NULL for UDP. */
char *cmdptr; /**< Start of command. */
char *argptr; /**< Command arguments. */
size_t szsoa; /**< Size of rem address, only UDP. */
dk4_socket_t sock; /**< Socket to use for response. */
int protlev; /**< Protocol level. */
int action; /**< Action to take. */
int logthis; /**< Flag: Log request and response. */
} pqd_rq_t;
/** Data for one user in a class.
*/
typedef struct {
dk4_um_t limit; /**< Limit (maximum page number). */
dk4_um_t used; /**< Number of pages used within limit. */
dk4_um_t account; /**< Remaining pages personal print account. */
int da; /**< Deny action: 0=remove, 1=hold. */
} pqd_account_t;
/** Information from one LPRng accounting line.
*/
typedef struct {
char *username; /**< User name. */
char *queuename; /**< Print queue name. */
char *jobtitle; /**< Print job title. */
char *pagecount; /**< Pagecount reported in line. */
} lprng_info_t;
/** Printqd protocol levels.
*/
enum {
PQD_PROTO_NONE = 0 , /**< No requests allowed. */
PQD_PROTO_INFO = 1 , /**< Info requests only. */
PQD_PROTO_DATA = 2 , /**< Info and data requests. */
PQD_PROTO_ADMIN = 3 /**< Info, data and admin requests. */
};
/** Commands in the printqd protocol.
*/
enum {
PQD_CMD_NONE = -1 , /**< Illegal command. */
PQD_CMD_JOBSTART = 0 , /**< Start of print job, response required. */
PQD_CMD_JOBEND = 1 , /**< End of print job. */
PQD_CMD_START = 2 , /**< Start of printing (ignored). */
PQD_CMD_END = 3 , /**< End of printing (ignored). */
PQD_CMD_FILESTART = 4 , /**< Start of file printing (pc). */
PQD_CMD_FILEEND = 5 , /**< End of file printing (pc). */
PQD_CMD_INFO = 6 , /**< Information, response required. */
PQD_CMD_ACCT_CHECK = 7 , /**< Check permission, response required. */
PQD_CMD_ACCT_START = 8 , /**< Start of file printing (pc). */
PQD_CMD_ACCT_END = 9 , /**< End of file printing (pc). */
PQD_CMD_ACCT_CHARGE = 10 , /**< Summary for file printing (pc). */
PQD_CMD_CONTROL = 11 /**< Control request. */
};
#endif
|