]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/policy.c
2 * "$Id: policy.c 5247 2006-03-08 13:43:38Z mike $"
4 * Policy routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 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 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * cupsdAddPolicy() - Add a policy to the system.
27 * cupsdAddPolicyOp() - Add an operation to a policy.
28 * cupsdCheckPolicy() - Check the IPP operation and username against
30 * cupsdDeleteAllPolicies() - Delete all policies in memory.
31 * cupsdFindPolicy() - Find a named policy.
32 * cupsdFindPolicyOp() - Find a policy operation.
36 * Include necessary headers...
43 * 'AddPolicy()' - Add a policy to the system.
46 cupsd_policy_t
* /* O - Policy */
47 cupsdAddPolicy(const char *policy
) /* I - Name of policy */
49 cupsd_policy_t
*temp
, /* Pointer to policy */
50 **tempa
; /* Pointer to policy array */
57 tempa
= malloc(sizeof(cupsd_policy_t
*));
59 tempa
= realloc(Policies
, sizeof(cupsd_policy_t
*) * (NumPolicies
+ 1));
67 if ((temp
= calloc(1, sizeof(cupsd_policy_t
))) != NULL
)
69 temp
->name
= strdup(policy
);
80 * 'cupsdAddPolicyOp()' - Add an operation to a policy.
83 cupsd_location_t
* /* O - New policy operation */
84 cupsdAddPolicyOp(cupsd_policy_t
*p
, /* I - Policy */
85 cupsd_location_t
*po
, /* I - Policy operation to copy */
86 ipp_op_t op
) /* I - IPP operation code */
88 int i
; /* Looping var */
89 cupsd_location_t
*temp
, /* New policy operation */
90 **tempa
; /* New policy operation array */
91 char name
[1024]; /* Interface name */
94 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPolicyOp(p=%p, po=%p, op=%x(%s))",
95 p
, po
, op
, ippOpString(op
));
101 tempa
= malloc(sizeof(cupsd_location_t
*));
103 tempa
= realloc(p
->ops
, sizeof(cupsd_location_t
*) * (p
->num_ops
+ 1));
110 if ((temp
= calloc(1, sizeof(cupsd_location_t
))) != NULL
)
113 tempa
[p
->num_ops
] = temp
;
117 temp
->limit
= AUTH_LIMIT_IPP
;
122 * Copy the specified policy to the new one...
125 temp
->order_type
= po
->order_type
;
126 temp
->type
= po
->type
;
127 temp
->level
= po
->level
;
128 temp
->satisfy
= po
->satisfy
;
129 temp
->encryption
= po
->encryption
;
131 for (i
= 0; i
< po
->num_names
; i
++)
132 cupsdAddName(temp
, po
->names
[i
]);
134 for (i
= 0; i
< po
->num_allow
; i
++)
135 switch (po
->allow
[i
].type
)
138 cupsdAllowIP(temp
, po
->allow
[i
].mask
.ip
.address
,
139 po
->allow
[i
].mask
.ip
.netmask
);
142 case AUTH_INTERFACE
:
143 snprintf(name
, sizeof(name
), "@IF(%s)",
144 po
->allow
[i
].mask
.name
.name
);
145 cupsdAllowHost(temp
, name
);
149 cupsdAllowHost(temp
, po
->allow
[i
].mask
.name
.name
);
153 for (i
= 0; i
< po
->num_deny
; i
++)
154 switch (po
->deny
[i
].type
)
157 cupsdDenyIP(temp
, po
->deny
[i
].mask
.ip
.address
,
158 po
->deny
[i
].mask
.ip
.netmask
);
161 case AUTH_INTERFACE
:
162 snprintf(name
, sizeof(name
), "@IF(%s)",
163 po
->deny
[i
].mask
.name
.name
);
164 cupsdDenyHost(temp
, name
);
168 cupsdDenyHost(temp
, po
->deny
[i
].mask
.name
.name
);
179 * 'cupsdCheckPolicy()' - Check the IPP operation and username against a policy.
182 http_status_t
/* I - 1 if OK, 0 otherwise */
183 cupsdCheckPolicy(cupsd_policy_t
*p
, /* I - Policy */
184 cupsd_client_t
*con
, /* I - Client connection */
185 const char *owner
) /* I - Owner of object */
187 cupsd_location_t
*po
; /* Current policy operation */
196 cupsdLogMessage(CUPSD_LOG_CRIT
, "cupsdCheckPolicy: p=%p, con=%p!", p
, con
);
202 * Find a match for the operation...
205 if ((po
= cupsdFindPolicyOp(p
, con
->request
->request
.op
.operation_id
)) == NULL
)
207 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCheckPolicy: No matching operation, returning 0!");
214 * Return the status of the check...
217 return (cupsdIsAuthorized(con
, owner
));
222 * 'cupsdDeleteAllPolicies()' - Delete all policies in memory.
226 cupsdDeleteAllPolicies(void)
228 int i
, j
; /* Looping vars */
229 cupsd_policy_t
**p
; /* Current policy */
230 cupsd_location_t
**po
; /* Current policy op */
233 if (NumPolicies
== 0)
236 for (i
= NumPolicies
, p
= Policies
; i
> 0; i
--, p
++)
238 for (j
= (*p
)->num_ops
, po
= (*p
)->ops
; j
> 0; j
--, po
++)
239 cupsdDeleteLocation(*po
);
241 if ((*p
)->num_ops
> 0)
255 * 'cupsdFindPolicy()' - Find a named policy.
258 cupsd_policy_t
* /* O - Policy */
259 cupsdFindPolicy(const char *policy
) /* I - Name of policy */
261 int i
; /* Looping var */
262 cupsd_policy_t
**p
; /* Current policy */
273 * Check the operation against the available policies...
276 for (i
= NumPolicies
, p
= Policies
; i
> 0; i
--, p
++)
277 if (!strcasecmp(policy
, (*p
)->name
))
285 * 'cupsdFindPolicyOp()' - Find a policy operation.
288 cupsd_location_t
* /* O - Policy operation */
289 cupsdFindPolicyOp(cupsd_policy_t
*p
, /* I - Policy */
290 ipp_op_t op
) /* I - IPP operation */
292 int i
; /* Looping var */
293 cupsd_location_t
**po
; /* Current policy operation */
296 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindPolicyOp(p=%p, op=%x(%s))\n",
297 p
, op
, ippOpString(op
));
307 * Check the operation against the available policies...
310 for (i
= p
->num_ops
, po
= p
->ops
; i
> 0; i
--, po
++)
313 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
314 "cupsdFindPolicyOp: Found exact match...");
318 for (i
= p
->num_ops
, po
= p
->ops
; i
> 0; i
--, po
++)
319 if ((*po
)->op
== IPP_ANY_OPERATION
)
321 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
322 "cupsdFindPolicyOp: Found wildcard match...");
326 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindPolicyOp: No match found!");
333 * End of "$Id: policy.c 5247 2006-03-08 13:43:38Z mike $".