]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/policy.c
2 * "$Id: policy.c 6649 2007-07-11 21:46:42Z mike $"
4 * Policy routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * cupsdAddPolicy() - Add a policy to the system.
18 * cupsdAddPolicyOp() - Add an operation to a policy.
19 * cupsdCheckPolicy() - Check the IPP operation and username against
21 * cupsdDeleteAllPolicies() - Delete all policies in memory.
22 * cupsdFindPolicy() - Find a named policy.
23 * cupsdFindPolicyOp() - Find a policy operation.
27 * Include necessary headers...
34 * 'AddPolicy()' - Add a policy to the system.
37 cupsd_policy_t
* /* O - Policy */
38 cupsdAddPolicy(const char *policy
) /* I - Name of policy */
40 cupsd_policy_t
*temp
, /* Pointer to policy */
41 **tempa
; /* Pointer to policy array */
48 tempa
= malloc(sizeof(cupsd_policy_t
*));
50 tempa
= realloc(Policies
, sizeof(cupsd_policy_t
*) * (NumPolicies
+ 1));
58 if ((temp
= calloc(1, sizeof(cupsd_policy_t
))) != NULL
)
60 temp
->name
= strdup(policy
);
71 * 'cupsdAddPolicyOp()' - Add an operation to a policy.
74 cupsd_location_t
* /* O - New policy operation */
75 cupsdAddPolicyOp(cupsd_policy_t
*p
, /* I - Policy */
76 cupsd_location_t
*po
, /* I - Policy operation to copy */
77 ipp_op_t op
) /* I - IPP operation code */
79 int i
; /* Looping var */
80 cupsd_location_t
*temp
, /* New policy operation */
81 **tempa
; /* New policy operation array */
82 char name
[1024]; /* Interface name */
85 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdAddPolicyOp(p=%p, po=%p, op=%x(%s))",
86 p
, po
, op
, ippOpString(op
));
92 tempa
= malloc(sizeof(cupsd_location_t
*));
94 tempa
= realloc(p
->ops
, sizeof(cupsd_location_t
*) * (p
->num_ops
+ 1));
101 if ((temp
= calloc(1, sizeof(cupsd_location_t
))) != NULL
)
104 tempa
[p
->num_ops
] = temp
;
108 temp
->limit
= AUTH_LIMIT_IPP
;
113 * Copy the specified policy to the new one...
116 temp
->order_type
= po
->order_type
;
117 temp
->type
= po
->type
;
118 temp
->level
= po
->level
;
119 temp
->satisfy
= po
->satisfy
;
120 temp
->encryption
= po
->encryption
;
122 for (i
= 0; i
< po
->num_names
; i
++)
123 cupsdAddName(temp
, po
->names
[i
]);
125 for (i
= 0; i
< po
->num_allow
; i
++)
126 switch (po
->allow
[i
].type
)
129 cupsdAllowIP(temp
, po
->allow
[i
].mask
.ip
.address
,
130 po
->allow
[i
].mask
.ip
.netmask
);
133 case AUTH_INTERFACE
:
134 snprintf(name
, sizeof(name
), "@IF(%s)",
135 po
->allow
[i
].mask
.name
.name
);
136 cupsdAllowHost(temp
, name
);
140 cupsdAllowHost(temp
, po
->allow
[i
].mask
.name
.name
);
144 for (i
= 0; i
< po
->num_deny
; i
++)
145 switch (po
->deny
[i
].type
)
148 cupsdDenyIP(temp
, po
->deny
[i
].mask
.ip
.address
,
149 po
->deny
[i
].mask
.ip
.netmask
);
152 case AUTH_INTERFACE
:
153 snprintf(name
, sizeof(name
), "@IF(%s)",
154 po
->deny
[i
].mask
.name
.name
);
155 cupsdDenyHost(temp
, name
);
159 cupsdDenyHost(temp
, po
->deny
[i
].mask
.name
.name
);
170 * 'cupsdCheckPolicy()' - Check the IPP operation and username against a policy.
173 http_status_t
/* I - 1 if OK, 0 otherwise */
174 cupsdCheckPolicy(cupsd_policy_t
*p
, /* I - Policy */
175 cupsd_client_t
*con
, /* I - Client connection */
176 const char *owner
) /* I - Owner of object */
178 cupsd_location_t
*po
; /* Current policy operation */
187 cupsdLogMessage(CUPSD_LOG_CRIT
, "cupsdCheckPolicy: p=%p, con=%p!", p
, con
);
189 return ((http_status_t
)0);
193 * Find a match for the operation...
196 if ((po
= cupsdFindPolicyOp(p
, con
->request
->request
.op
.operation_id
)) == NULL
)
198 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdCheckPolicy: No matching operation, returning 0!");
199 return ((http_status_t
)0);
205 * Return the status of the check...
208 return (cupsdIsAuthorized(con
, owner
));
213 * 'cupsdDeleteAllPolicies()' - Delete all policies in memory.
217 cupsdDeleteAllPolicies(void)
219 int i
, j
; /* Looping vars */
220 cupsd_policy_t
**p
; /* Current policy */
221 cupsd_location_t
**po
; /* Current policy op */
224 if (NumPolicies
== 0)
227 for (i
= NumPolicies
, p
= Policies
; i
> 0; i
--, p
++)
229 for (j
= (*p
)->num_ops
, po
= (*p
)->ops
; j
> 0; j
--, po
++)
230 cupsdDeleteLocation(*po
);
232 if ((*p
)->num_ops
> 0)
246 * 'cupsdFindPolicy()' - Find a named policy.
249 cupsd_policy_t
* /* O - Policy */
250 cupsdFindPolicy(const char *policy
) /* I - Name of policy */
252 int i
; /* Looping var */
253 cupsd_policy_t
**p
; /* Current policy */
264 * Check the operation against the available policies...
267 for (i
= NumPolicies
, p
= Policies
; i
> 0; i
--, p
++)
268 if (!strcasecmp(policy
, (*p
)->name
))
276 * 'cupsdFindPolicyOp()' - Find a policy operation.
279 cupsd_location_t
* /* O - Policy operation */
280 cupsdFindPolicyOp(cupsd_policy_t
*p
, /* I - Policy */
281 ipp_op_t op
) /* I - IPP operation */
283 int i
; /* Looping var */
284 cupsd_location_t
**po
; /* Current policy operation */
287 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindPolicyOp(p=%p, op=%x(%s))\n",
288 p
, op
, ippOpString(op
));
298 * Check the operation against the available policies...
301 for (i
= p
->num_ops
, po
= p
->ops
; i
> 0; i
--, po
++)
304 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
305 "cupsdFindPolicyOp: Found exact match...");
309 for (i
= p
->num_ops
, po
= p
->ops
; i
> 0; i
--, po
++)
310 if ((*po
)->op
== IPP_ANY_OPERATION
)
312 cupsdLogMessage(CUPSD_LOG_DEBUG2
,
313 "cupsdFindPolicyOp: Found wildcard match...");
317 cupsdLogMessage(CUPSD_LOG_DEBUG2
, "cupsdFindPolicyOp: No match found!");
324 * End of "$Id: policy.c 6649 2007-07-11 21:46:42Z mike $".