4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 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 * ReadConfiguration() - Read the cupsd.conf file.
27 * read_configuration() - Read a configuration file.
28 * read_location() - Read a <Location path> definition.
29 * read_policy() - Read a <Policy name> definition.
30 * get_address() - Get an address + port number from a line.
31 * get_addr_and_mask() - Get an IP address and netmask.
32 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
33 * required by SSLSetCertificate.
37 * Include necessary headers...
44 #include <sys/utsname.h>
46 #ifdef HAVE_DOMAINSOCKETS
48 #endif /* HAVE_DOMAINSOCKETS */
51 # include <Security/SecureTransport.h>
52 # include <Security/SecIdentitySearch.h>
53 #endif /* HAVE_CDSASSL */
57 #endif /* HAVE_VSYSLOG */
61 * Possibly missing network definitions...
65 # define INADDR_NONE 0xffffffff
66 #endif /* !INADDR_NONE */
70 * Configuration variable structure...
75 char *name
; /* Name of variable */
76 void *ptr
; /* Pointer to variable */
77 int type
; /* Type (int, string, address) */
89 static var_t variables
[] =
91 { "AccessLog", &AccessLog
, VAR_STRING
},
92 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
93 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
94 { "BrowseLocalOptions", &BrowseLocalOptions
, VAR_STRING
},
95 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
96 { "BrowseRemoteOptions", &BrowseRemoteOptions
, VAR_STRING
},
97 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
98 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
99 { "Browsing", &Browsing
, VAR_BOOLEAN
},
100 { "Classification", &Classification
, VAR_STRING
},
101 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
102 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
103 { "DataDir", &DataDir
, VAR_STRING
},
104 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
105 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
106 { "DefaultPolicy", &DefaultPolicy
, VAR_STRING
},
107 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
108 { "ErrorLog", &ErrorLog
, VAR_STRING
},
109 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
110 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
111 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
112 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
113 { "FilterNice", &FilterNice
, VAR_INTEGER
},
114 { "FontPath", &FontPath
, VAR_STRING
},
115 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
116 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
117 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
118 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
119 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
120 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
121 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
122 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
123 { "MaxActiveJobs", &MaxActiveJobs
, VAR_INTEGER
},
124 { "MaxClients", &MaxClients
, VAR_INTEGER
},
125 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
126 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
127 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
128 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
129 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
130 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
131 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
132 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
133 { "PageLog", &PageLog
, VAR_STRING
},
134 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
135 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
136 { "Printcap", &Printcap
, VAR_STRING
},
137 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
138 { "ReloadTimeout", &ReloadTimeout
, VAR_INTEGER
},
139 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
140 { "RequestRoot", &RequestRoot
, VAR_STRING
},
141 { "RIPCache", &RIPCache
, VAR_STRING
},
142 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
143 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
144 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
145 { "ServerBin", &ServerBin
, VAR_STRING
},
147 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
148 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
149 { "ServerKey", &ServerKey
, VAR_STRING
},
150 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
151 #endif /* HAVE_SSL */
152 { "ServerName", &ServerName
, VAR_STRING
},
153 { "ServerRoot", &ServerRoot
, VAR_STRING
},
154 { "StateDir", &StateDir
, VAR_STRING
},
155 { "TempDir", &TempDir
, VAR_STRING
},
156 { "Timeout", &Timeout
, VAR_INTEGER
}
158 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
161 static unsigned ones
[4] =
163 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
165 static unsigned zeros
[4] =
167 0x00000000, 0x00000000, 0x00000000, 0x00000000
171 static CFArrayRef
CDSAGetServerCerts();
172 #endif /* HAVE_CDSASSL */
179 static int read_configuration(cups_file_t
*fp
);
180 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
181 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
182 static int get_address(const char *value
, unsigned defaddress
, int defport
,
183 int deffamily
, http_addr_t
*address
);
184 static int get_addr_and_mask(const char *value
, unsigned *ip
,
186 static ipp_op_t
get_operation(const char *name
);
190 * 'ReadConfiguration()' - Read the cupsd.conf file.
193 int /* O - 1 on success, 0 otherwise */
194 ReadConfiguration(void)
196 int i
; /* Looping var */
197 cups_file_t
*fp
; /* Configuration file */
198 int status
; /* Return status */
199 char temp
[1024], /* Temporary buffer */
200 *slash
; /* Directory separator */
201 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
203 char *language
; /* Language string */
204 struct passwd
*user
; /* Default user */
205 struct group
*group
; /* Default group */
206 char *old_serverroot
, /* Old ServerRoot */
207 *old_requestroot
; /* Old RequestRoot */
211 * Shutdown the server...
217 * Save the old root paths...
220 old_serverroot
= NULL
;
221 SetString(&old_serverroot
, ServerRoot
);
222 old_requestroot
= NULL
;
223 SetString(&old_requestroot
, RequestRoot
);
226 * Reset the server configuration data...
229 DeleteAllLocations();
247 for (i
= 0; i
< NumRelays
; i
++)
248 if (Relays
[i
].from
.type
== AUTH_NAME
)
249 free(Relays
[i
].from
.mask
.name
.name
);
256 if (NumListeners
> 0)
258 #ifdef HAVE_DOMAINSOCKETS
259 int i
; /* Looping var */
260 listener_t
*lis
; /* Current listening socket */
262 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
263 if (lis
->address
.sin_family
== AF_LOCAL
)
264 ClearString((char **)&lis
->address
.sin_addr
);
265 #endif /* HAVE_DOMAINSOCKETS */
276 gethostname(temp
, sizeof(temp
));
277 SetString(&ServerName
, temp
);
278 SetStringf(&ServerAdmin
, "root@%s", temp
);
279 SetString(&ServerBin
, CUPS_SERVERBIN
);
280 SetString(&RequestRoot
, CUPS_REQUESTS
);
281 SetString(&DocumentRoot
, CUPS_DOCROOT
);
282 SetString(&DataDir
, CUPS_DATADIR
);
283 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
284 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
285 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
286 SetString(&Printcap
, "/etc/printcap");
287 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
288 SetString(&FontPath
, CUPS_FONTPATH
);
289 SetString(&RemoteRoot
, "remroot");
290 SetString(&ServerHeader
, "CUPS/1.1");
291 SetString(&StateDir
, CUPS_STATEDIR
);
293 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
294 if ((slash
= strrchr(temp
, '/')) != NULL
)
297 SetString(&ServerRoot
, temp
);
299 ClearString(&Classification
);
300 ClassifyOverride
= 0;
304 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
306 SetString(&ServerCertificate
, "ssl/server.crt");
307 SetString(&ServerKey
, "ssl/server.key");
308 # endif /* HAVE_CDSASSL */
309 #endif /* HAVE_SSL */
311 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
313 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
316 SetString(&DefaultLanguage
, language
);
317 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
319 SetString(&RIPCache
, "8m");
321 if (getenv("TMPDIR") == NULL
)
322 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
324 SetString(&TempDir
, getenv("TMPDIR"));
327 * Find the default system group: "sys", "system", or "root"...
330 group
= getgrnam(CUPS_DEFAULT_GROUP
);
337 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
338 Group
= group
->gr_gid
;
347 SetString(&SystemGroups
[0], group
->gr_name
);
352 SetString(&SystemGroups
[0], "unknown");
358 * Find the default user...
361 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
362 User
= 1; /* Force to a non-priviledged account */
372 ConfigFilePerm
= 0640;
376 FaxRetryInterval
= 300;
381 HostNameLookups
= FALSE
;
382 ImplicitClasses
= TRUE
;
383 ImplicitAnyClasses
= FALSE
;
384 HideImplicitMembers
= TRUE
;
386 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
387 ListenBackLog
= SOMAXCONN
;
390 MaxClientsPerHost
= 0;
391 MaxLogSize
= 1024 * 1024;
392 MaxPrinterHistory
= 10;
395 RootCertDuration
= 300;
397 Timeout
= DEFAULT_TIMEOUT
;
399 BrowseInterval
= DEFAULT_INTERVAL
;
400 BrowsePort
= ippPort();
401 BrowseProtocols
= BROWSE_CUPS
;
402 BrowseShortNames
= TRUE
;
403 BrowseTimeout
= DEFAULT_TIMEOUT
;
406 ClearString(&BrowseLocalOptions
);
407 ClearString(&BrowseRemoteOptions
);
409 JobHistory
= DEFAULT_HISTORY
;
410 JobFiles
= DEFAULT_FILES
;
415 MaxJobsPerPrinter
= 0;
418 ClearString(&DefaultPolicy
);
421 * Read the configuration file...
424 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
427 status
= read_configuration(fp
);
440 * Use the default system group if none was supplied in cupsd.conf...
443 if (NumSystemGroups
== 0)
447 * Get the access control list for browsing...
450 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
453 * Open the system log for cupsd if necessary...
457 if (strcmp(AccessLog
, "syslog") == 0 ||
458 strcmp(ErrorLog
, "syslog") == 0 ||
459 strcmp(PageLog
, "syslog") == 0)
460 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
461 #endif /* HAVE_VSYSLOG */
464 * Log the configuration file that was used...
467 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
470 * Check that we have at least one listen/port line; if not, report this
471 * as an error and exit!
474 if (NumListeners
== 0)
480 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
486 cupsdEndProcess(getpid(), 0);
490 * Set the default locale using the language and charset...
493 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
496 * Update all relative filenames to include the full path from ServerRoot...
499 if (DocumentRoot
[0] != '/')
500 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
502 if (RequestRoot
[0] != '/')
503 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
505 if (ServerBin
[0] != '/')
506 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
509 if (ServerCertificate
[0] != '/')
510 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
512 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
513 chown(ServerCertificate
, RunUser
, Group
);
514 chmod(ServerCertificate
, ConfigFilePerm
);
516 if (ServerKey
[0] != '/')
517 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
519 chown(ServerKey
, RunUser
, Group
);
520 chmod(ServerKey
, ConfigFilePerm
);
521 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
522 #endif /* HAVE_SSL */
525 * Make sure that directories and config files are owned and
526 * writable by the user and group in the cupsd.conf file...
529 chown(StateDir
, RunUser
, Group
);
530 chmod(StateDir
, 0775);
532 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
533 chown(temp
, RunUser
, Group
);
536 chown(ServerRoot
, RunUser
, Group
);
537 chmod(ServerRoot
, 0775);
539 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
540 chown(temp
, RunUser
, Group
);
543 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
544 chown(temp
, RunUser
, Group
);
547 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
548 chown(temp
, RunUser
, Group
);
549 chmod(temp
, ConfigFilePerm
);
551 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
552 chown(temp
, RunUser
, Group
);
556 chmod(temp
, ConfigFilePerm
);
557 #endif /* __APPLE__ */
559 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
560 chown(temp
, RunUser
, Group
);
564 chmod(temp
, ConfigFilePerm
);
565 #endif /* __APPLE__ */
567 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
568 chown(temp
, User
, Group
);
572 * Make sure the request and temporary directories have the right
576 chown(RequestRoot
, RunUser
, Group
);
577 chmod(RequestRoot
, 0710);
579 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
582 * Only update ownership and permissions if the CUPS temp directory
583 * is under the spool directory...
586 chown(TempDir
, RunUser
, Group
);
587 chmod(TempDir
, 01770);
591 * Check the MaxClients setting, and then allocate memory for it...
594 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
597 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
600 MaxClients
= MaxFDs
/ 3;
603 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
605 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
606 MaxClients
, strerror(errno
));
610 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
613 * Check the MaxActiveJobs setting; limit to 1/3 the available
614 * file descriptors, since we need a pipe for each job...
617 if (MaxActiveJobs
> (MaxFDs
/ 3))
618 MaxActiveJobs
= MaxFDs
/ 3;
620 if (Classification
&& strcasecmp(Classification
, "none") == 0)
621 ClearString(&Classification
);
624 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
627 * Update the MaxClientsPerHost value, as needed...
630 if (MaxClientsPerHost
<= 0)
631 MaxClientsPerHost
= MaxClients
;
633 if (MaxClientsPerHost
> MaxClients
)
634 MaxClientsPerHost
= MaxClients
;
636 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
640 * Update the default policy, as needed...
644 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
646 DefaultPolicyPtr
= NULL
;
648 if (!DefaultPolicyPtr
)
650 policy_t
*p
; /* New policy */
651 policyop_t
*po
; /* New policy operation */
652 char groupname
[255]; /* Group name */
656 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
658 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
659 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
662 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
664 DefaultPolicyPtr
= p
= AddPolicy("default");
666 LogMessage(L_INFO
, "<Policy default>");
667 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
668 "Release-Job Restart-Job Purge-Jobs "
669 "Set-Job-Attributes Create-Job-Subscription "
670 "Renew-Subscription Cancel-Subscription "
671 "Get-Notifications Reprocess-Job Cancel-Current-Job "
672 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
673 LogMessage(L_INFO
, "Order Allow,Deny");
674 LogMessage(L_INFO
, "Allow @OWNER");
676 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
677 po
->order_type
= POLICY_DENY
;
679 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
681 for (i
= 0; i
< NumSystemGroups
; i
++)
683 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
684 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
685 LogMessage(L_INFO
, "Allow %s", groupname
);
688 AddPolicyOp(p
, po
, IPP_SEND_URI
);
689 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
690 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
691 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
692 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
693 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
694 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
695 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
696 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
697 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
698 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
699 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
700 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
701 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
702 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
703 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
705 LogMessage(L_INFO
, "</Limit>");
707 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
708 "Set-Printer-Attributes Enable-Printer "
709 "Disable-Printer Pause-Printer-After-Current-Job "
710 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
711 "Activate-Printer Restart-Printer Shutdown-Printer "
712 "Startup-Printer Promote-Job Schedule-Job-After "
713 "CUPS-Add-Printer CUPS-Delete-Printer "
714 "CUPS-Add-Class CUPS-Delete-Class "
715 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
716 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
717 LogMessage(L_INFO
, "Order Allow,Deny");
718 LogMessage(L_INFO
, "Authenticate yes");
720 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
721 po
->order_type
= POLICY_DENY
;
722 po
->authenticate
= 1;
724 for (i
= 0; i
< NumSystemGroups
; i
++)
726 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
727 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
728 LogMessage(L_INFO
, "Allow %s", groupname
);
731 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
732 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
733 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
734 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
735 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
736 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
737 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
738 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
739 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
740 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
741 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
742 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
743 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
744 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
745 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
746 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
747 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
748 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
749 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
750 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
751 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
752 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
753 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
755 LogMessage(L_INFO
, "</Limit>");
757 LogMessage(L_INFO
, "<Limit All>");
758 LogMessage(L_INFO
, "Order Deny,Allow");
760 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
761 po
->order_type
= POLICY_ALLOW
;
763 LogMessage(L_INFO
, "</Limit>");
764 LogMessage(L_INFO
, "</Policy>");
769 * If we are doing a full reload or the server root has changed, flush
770 * the jobs, printers, etc. and start from scratch...
773 if (NeedReload
== RELOAD_ALL
||
774 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
775 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
777 LogMessage(L_INFO
, "Full reload is required.");
787 DefaultPrinter
= NULL
;
801 if (MimeDatabase
!= NULL
)
802 mimeDelete(MimeDatabase
);
806 for (i
= 0; i
< NumMimeTypes
; i
++)
807 free((void *)MimeTypes
[i
]);
813 * Read the MIME type and conversion database...
816 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
818 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
820 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
821 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
824 * Create a list of MIME types for the document-format-supported
828 NumMimeTypes
= MimeDatabase
->num_types
;
829 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
832 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
834 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
836 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
837 MimeDatabase
->types
[i
]->type
);
839 MimeTypes
[i
] = strdup(type
);
842 if (i
< NumMimeTypes
)
843 MimeTypes
[i
] = strdup("application/octet-stream");
849 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
853 * Load printers and classes...
862 * Load devices and PPDs...
865 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
868 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
872 * Load queued jobs...
877 LogMessage(L_INFO
, "Full reload complete.");
883 LogMessage(L_INFO
, "Partial reload complete.");
887 * Reset the reload state...
890 NeedReload
= RELOAD_NONE
;
892 ClearString(&old_serverroot
);
893 ClearString(&old_requestroot
);
896 * Startup the server and return...
906 * 'read_configuration()' - Read a configuration file.
909 static int /* O - 1 on success, 0 on failure */
910 read_configuration(cups_file_t
*fp
) /* I - File to read from */
912 int i
; /* Looping var */
913 int linenum
; /* Current line number */
914 char line
[HTTP_MAX_BUFFER
], /* Line from file */
915 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
916 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
917 *ptr
, /* Pointer into line/temp */
918 *value
; /* Pointer to value */
919 int valuelen
; /* Length of value */
920 var_t
*var
; /* Current variable */
921 unsigned ip
[4], /* Address value */
922 mask
[4]; /* Netmask value */
923 dirsvc_relay_t
*relay
; /* Relay data */
924 dirsvc_poll_t
*poll
; /* Polling data */
925 http_addr_t polladdr
; /* Polling address */
926 location_t
*location
; /* Browse location */
927 cups_file_t
*incfile
; /* Include file */
928 char incname
[1024]; /* Include filename */
932 * Loop through each line in the file...
937 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
940 * Decode the directive...
943 if (!strcasecmp(line
, "Include"))
950 strlcpy(incname
, value
, sizeof(incname
));
952 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
954 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
955 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
956 incname
, strerror(errno
));
959 read_configuration(incfile
);
960 cupsFileClose(incfile
);
963 else if (!strcasecmp(line
, "<Location"))
971 linenum
= read_location(fp
, value
, linenum
);
977 LogMessage(L_ERROR
, "Syntax error on line %d.",
982 else if (!strcasecmp(line
, "<Policy"))
990 linenum
= read_policy(fp
, value
, linenum
);
996 LogMessage(L_ERROR
, "Syntax error on line %d.",
1001 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1004 * Add a listening address to the list...
1007 listener_t
*lis
; /* New listeners array */
1010 if (NumListeners
== 0)
1011 lis
= malloc(sizeof(listener_t
));
1013 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1017 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1018 line
, linenum
, strerror(errno
));
1023 lis
+= NumListeners
;
1025 memset(lis
, 0, sizeof(listener_t
));
1027 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1029 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1032 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1033 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1034 ntohs(lis
->address
.ipv6
.sin6_port
));
1036 #endif /* AF_INET6 */
1037 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1038 ntohs(lis
->address
.ipv4
.sin_port
));
1042 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1046 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1049 * Add a listening address to the list...
1052 listener_t
*lis
; /* New listeners array */
1055 if (NumListeners
== 0)
1056 lis
= malloc(sizeof(listener_t
));
1058 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1062 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1063 line
, linenum
, strerror(errno
));
1068 lis
+= NumListeners
;
1070 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1072 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1075 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1076 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1077 ntohs(lis
->address
.ipv6
.sin6_port
));
1079 #endif /* AF_INET6 */
1080 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1081 ntohs(lis
->address
.ipv4
.sin_port
));
1082 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1086 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1089 #endif /* HAVE_SSL */
1090 else if (!strcasecmp(line
, "BrowseAddress"))
1093 * Add a browse address to the list...
1096 dirsvc_addr_t
*dira
; /* New browse address array */
1099 if (NumBrowsers
== 0)
1100 dira
= malloc(sizeof(dirsvc_addr_t
));
1102 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1106 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1107 linenum
, strerror(errno
));
1112 dira
+= NumBrowsers
;
1114 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1116 if (!strcasecmp(value
, "@LOCAL"))
1119 * Send browse data to all local interfaces...
1122 strcpy(dira
->iface
, "*");
1125 else if (!strncasecmp(value
, "@IF(", 4))
1128 * Send browse data to the named interface...
1131 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1133 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1139 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1141 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1144 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1145 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1146 ntohs(dira
->to
.ipv6
.sin6_port
));
1148 #endif /* AF_INET6 */
1149 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1150 ntohs(dira
->to
.ipv4
.sin_port
));
1155 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1158 else if (!strcasecmp(line
, "BrowseOrder"))
1161 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1164 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1165 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1167 if (location
== NULL
)
1168 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1169 else if (!strncasecmp(value
, "deny", 4))
1170 location
->order_type
= AUTH_ALLOW
;
1171 else if (!strncasecmp(value
, "allow", 5))
1172 location
->order_type
= AUTH_DENY
;
1174 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1177 else if (!strcasecmp(line
, "BrowseProtocols"))
1180 * "BrowseProtocol name [... name]"
1183 BrowseProtocols
= 0;
1187 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1188 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1191 if (value
[valuelen
])
1193 value
[valuelen
] = '\0';
1197 if (!strcasecmp(value
, "cups"))
1198 BrowseProtocols
|= BROWSE_CUPS
;
1199 else if (!strcasecmp(value
, "slp"))
1200 BrowseProtocols
|= BROWSE_SLP
;
1201 else if (!strcasecmp(value
, "ldap"))
1202 BrowseProtocols
|= BROWSE_LDAP
;
1203 else if (!strcasecmp(value
, "all"))
1204 BrowseProtocols
|= BROWSE_ALL
;
1207 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1212 for (value
+= valuelen
; *value
; value
++)
1213 if (!isspace(*value
) || *value
!= ',')
1217 else if (!strcasecmp(line
, "BrowseAllow") ||
1218 !strcasecmp(line
, "BrowseDeny"))
1221 * BrowseAllow [From] host/ip...
1222 * BrowseDeny [From] host/ip...
1225 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1226 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1228 if (location
== NULL
)
1229 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1232 if (!strncasecmp(value
, "from ", 5))
1235 * Strip leading "from"...
1240 while (isspace(*value
))
1245 * Figure out what form the allow/deny address takes:
1256 * nnn.nnn.nnn.nnn/mm
1257 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1260 if (!strcasecmp(value
, "all"))
1266 if (!strcasecmp(line
, "BrowseAllow"))
1267 AllowIP(location
, zeros
, zeros
);
1269 DenyIP(location
, zeros
, zeros
);
1271 else if (!strcasecmp(value
, "none"))
1277 if (!strcasecmp(line
, "BrowseAllow"))
1278 AllowIP(location
, ones
, zeros
);
1280 DenyIP(location
, ones
, zeros
);
1282 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1285 * Host or domain name...
1288 if (value
[0] == '*')
1291 if (!strcasecmp(line
, "BrowseAllow"))
1292 AllowHost(location
, value
);
1294 DenyHost(location
, value
);
1299 * One of many IP address forms...
1302 if (!get_addr_and_mask(value
, ip
, mask
))
1304 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1309 if (!strcasecmp(line
, "BrowseAllow"))
1310 AllowIP(location
, ip
, mask
);
1312 DenyIP(location
, ip
, mask
);
1316 else if (!strcasecmp(line
, "BrowseRelay"))
1319 * BrowseRelay [from] source [to] destination
1323 relay
= malloc(sizeof(dirsvc_relay_t
));
1325 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1329 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1330 linenum
, strerror(errno
));
1337 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1339 if (!strncasecmp(value
, "from ", 5))
1342 * Strip leading "from"...
1347 while (isspace(*value
))
1352 * Figure out what form the from address takes:
1361 * nnn.nnn.nnn.nnn/mm
1362 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1365 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1368 * Host or domain name...
1371 if (value
[0] == '*')
1374 strlcpy(temp
, value
, sizeof(temp
));
1375 if ((ptr
= strchr(temp
, ' ')) != NULL
)
1378 relay
->from
.type
= AUTH_NAME
;
1379 relay
->from
.mask
.name
.name
= strdup(temp
);
1380 relay
->from
.mask
.name
.length
= strlen(temp
);
1385 * One of many IP address forms...
1388 if (!get_addr_and_mask(value
, ip
, mask
))
1390 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1395 relay
->from
.type
= AUTH_IP
;
1396 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1397 sizeof(relay
->from
.mask
.ip
.address
));
1398 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1399 sizeof(relay
->from
.mask
.ip
.netmask
));
1403 * Skip value and trailing whitespace...
1406 for (; *value
; value
++)
1407 if (isspace(*value
))
1410 while (isspace(*value
))
1413 if (!strncasecmp(value
, "to ", 3))
1416 * Strip leading "to"...
1421 while (isspace(*value
))
1426 * Get "to" address and port...
1429 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1431 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
1433 if (relay
->from
.type
== AUTH_IP
)
1434 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
1435 relay
->from
.mask
.ip
.address
[0],
1436 relay
->from
.mask
.ip
.address
[1],
1437 relay
->from
.mask
.ip
.address
[2],
1438 relay
->from
.mask
.ip
.address
[3],
1439 relay
->from
.mask
.ip
.netmask
[0],
1440 relay
->from
.mask
.ip
.netmask
[1],
1441 relay
->from
.mask
.ip
.netmask
[2],
1442 relay
->from
.mask
.ip
.netmask
[3]);
1444 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
1447 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1448 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1449 ntohs(relay
->to
.ipv6
.sin6_port
));
1451 #endif /* AF_INET6 */
1452 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1453 ntohs(relay
->to
.ipv4
.sin_port
));
1459 if (relay
->from
.type
== AUTH_NAME
)
1460 free(relay
->from
.mask
.name
.name
);
1462 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1465 else if (!strcasecmp(line
, "BrowsePoll"))
1468 * BrowsePoll address[:port]
1472 poll
= malloc(sizeof(dirsvc_poll_t
));
1474 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1478 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1479 linenum
, strerror(errno
));
1487 * Get poll address and port...
1490 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1493 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1495 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1498 if (polladdr
.addr
.sa_family
== AF_INET6
)
1499 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1501 #endif /* AF_INET6 */
1502 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1504 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1507 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1509 else if (!strcasecmp(line
, "User"))
1512 * User ID to run as...
1515 if (isdigit(value
[0]))
1519 struct passwd
*p
; /* Password information */
1522 p
= getpwnam(value
);
1527 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
1530 else if (!strcasecmp(line
, "Group"))
1533 * Group ID to run as...
1536 if (isdigit(value
[0]))
1537 Group
= atoi(value
);
1540 struct group
*g
; /* Group information */
1543 g
= getgrnam(value
);
1548 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
1551 else if (!strcasecmp(line
, "SystemGroup"))
1554 * System (admin) group(s)...
1557 char *valueptr
, /* Pointer into value */
1558 quote
; /* Quote character */
1561 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1563 if (*value
== '\'' || *value
== '\"')
1566 * Scan quoted name...
1571 for (valueptr
= value
; *valueptr
; valueptr
++)
1572 if (*valueptr
== quote
)
1578 * Scan space or comma-delimited name...
1581 for (valueptr
= value
; *valueptr
; valueptr
++)
1582 if (isspace(*valueptr
) || *valueptr
== ',')
1589 SetString(SystemGroups
+ i
, value
);
1593 while (*value
== ',' || isspace(*value
))
1598 NumSystemGroups
= i
;
1600 else if (!strcasecmp(line
, "HostNameLookups"))
1603 * Do hostname lookups?
1606 if (!strcasecmp(value
, "off"))
1607 HostNameLookups
= 0;
1608 else if (!strcasecmp(value
, "on"))
1609 HostNameLookups
= 1;
1610 else if (!strcasecmp(value
, "double"))
1611 HostNameLookups
= 2;
1613 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1616 else if (!strcasecmp(line
, "LogLevel"))
1619 * Amount of logging to do...
1622 if (!strcasecmp(value
, "debug2"))
1623 LogLevel
= L_DEBUG2
;
1624 else if (!strcasecmp(value
, "debug"))
1626 else if (!strcasecmp(value
, "info"))
1628 else if (!strcasecmp(value
, "notice"))
1629 LogLevel
= L_NOTICE
;
1630 else if (!strcasecmp(value
, "warn"))
1632 else if (!strcasecmp(value
, "error"))
1634 else if (!strcasecmp(value
, "crit"))
1636 else if (!strcasecmp(value
, "alert"))
1638 else if (!strcasecmp(value
, "emerg"))
1640 else if (!strcasecmp(value
, "none"))
1643 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1645 else if (!strcasecmp(line
, "PrintcapFormat"))
1648 * Format of printcap file?
1651 if (!strcasecmp(value
, "bsd"))
1652 PrintcapFormat
= PRINTCAP_BSD
;
1653 else if (!strcasecmp(value
, "solaris"))
1654 PrintcapFormat
= PRINTCAP_SOLARIS
;
1656 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1659 else if (!strcasecmp(line
, "ServerTokens"))
1662 * Set the string used for the Server header...
1665 struct utsname plat
; /* Platform info */
1670 if (!strcasecmp(value
, "ProductOnly"))
1671 SetString(&ServerHeader
, "CUPS");
1672 else if (!strcasecmp(value
, "Major"))
1673 SetString(&ServerHeader
, "CUPS/1");
1674 else if (!strcasecmp(value
, "Minor"))
1675 SetString(&ServerHeader
, "CUPS/1.1");
1676 else if (!strcasecmp(value
, "Minimal"))
1677 SetString(&ServerHeader
, CUPS_MINIMAL
);
1678 else if (!strcasecmp(value
, "OS"))
1679 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1680 else if (!strcasecmp(value
, "Full"))
1681 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1682 else if (!strcasecmp(value
, "None"))
1683 ClearString(&ServerHeader
);
1685 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1690 * Find a simple variable in the list...
1693 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1694 if (!strcasecmp(line
, var
->name
))
1700 * Unknown directive! Output an error message and continue...
1703 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
1713 char *units
; /* Units */
1716 n
= strtol(value
, &units
, 0);
1718 if (units
&& *units
)
1720 if (tolower(units
[0] & 255) == 'g')
1721 n
*= 1024 * 1024 * 1024;
1722 else if (tolower(units
[0] & 255) == 'm')
1724 else if (tolower(units
[0] & 255) == 'k')
1726 else if (tolower(units
[0] & 255) == 't')
1730 *((int *)var
->ptr
) = n
;
1735 if (!strcasecmp(value
, "true") ||
1736 !strcasecmp(value
, "on") ||
1737 !strcasecmp(value
, "enabled") ||
1738 !strcasecmp(value
, "yes") ||
1740 *((int *)var
->ptr
) = TRUE
;
1741 else if (!strcasecmp(value
, "false") ||
1742 !strcasecmp(value
, "off") ||
1743 !strcasecmp(value
, "disabled") ||
1744 !strcasecmp(value
, "no") ||
1745 !strcasecmp(value
, "0"))
1746 *((int *)var
->ptr
) = FALSE
;
1748 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1753 SetString((char **)var
->ptr
, value
);
1764 * 'read_location()' - Read a <Location path> definition.
1767 static int /* O - New line number or 0 on error */
1768 read_location(cups_file_t
*fp
, /* I - Configuration file */
1769 char *location
, /* I - Location name/path */
1770 int linenum
) /* I - Current line number */
1772 int i
; /* Looping var */
1773 location_t
*loc
, /* New location */
1774 *parent
; /* Parent location */
1775 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1776 *value
, /* Value for directive */
1777 *valptr
; /* Pointer into value */
1778 unsigned ip
[4], /* IP address components */
1779 mask
[4]; /* IP netmask components */
1782 if ((parent
= AddLocation(location
)) == NULL
)
1785 parent
->limit
= AUTH_LIMIT_ALL
;
1788 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1791 * Decode the directive...
1794 if (!strcasecmp(line
, "</Location>"))
1796 else if (!strcasecmp(line
, "<Limit") ||
1797 !strcasecmp(line
, "<LimitExcept"))
1801 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
1805 if ((loc
= CopyLocation(&parent
)) == NULL
)
1811 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1816 if (!strcmp(value
, "ALL"))
1817 loc
->limit
= AUTH_LIMIT_ALL
;
1818 else if (!strcmp(value
, "GET"))
1819 loc
->limit
|= AUTH_LIMIT_GET
;
1820 else if (!strcmp(value
, "HEAD"))
1821 loc
->limit
|= AUTH_LIMIT_HEAD
;
1822 else if (!strcmp(value
, "OPTIONS"))
1823 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1824 else if (!strcmp(value
, "POST"))
1825 loc
->limit
|= AUTH_LIMIT_POST
;
1826 else if (!strcmp(value
, "PUT"))
1827 loc
->limit
|= AUTH_LIMIT_PUT
;
1828 else if (!strcmp(value
, "TRACE"))
1829 loc
->limit
|= AUTH_LIMIT_TRACE
;
1831 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1834 for (value
= valptr
; isspace(*value
& 255); value
++);
1837 if (!strcasecmp(line
, "<LimitExcept"))
1838 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1840 parent
->limit
&= ~loc
->limit
;
1842 else if (!strcasecmp(line
, "</Limit>"))
1844 else if (!strcasecmp(line
, "Encryption"))
1847 * "Encryption xxx" - set required encryption level...
1850 if (!strcasecmp(value
, "never"))
1851 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1852 else if (!strcasecmp(value
, "always"))
1854 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1855 "Using \"required\" instead.", value
, linenum
);
1857 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1859 else if (!strcasecmp(value
, "required"))
1860 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1861 else if (!strcasecmp(value
, "ifrequested"))
1862 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1864 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1867 else if (!strcasecmp(line
, "Order"))
1870 * "Order Deny,Allow" or "Order Allow,Deny"...
1873 if (!strncasecmp(value
, "deny", 4))
1874 loc
->order_type
= AUTH_ALLOW
;
1875 else if (!strncasecmp(value
, "allow", 5))
1876 loc
->order_type
= AUTH_DENY
;
1878 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1881 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1884 * Allow [From] host/ip...
1885 * Deny [From] host/ip...
1888 if (!strncasecmp(value
, "from", 4))
1891 * Strip leading "from"...
1896 while (isspace(*value
& 255))
1901 * Figure out what form the allow/deny address takes:
1912 * nnn.nnn.nnn.nnn/mm
1913 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1916 if (!strcasecmp(value
, "all"))
1922 if (!strcasecmp(line
, "Allow"))
1923 AllowIP(loc
, zeros
, zeros
);
1925 DenyIP(loc
, zeros
, zeros
);
1927 else if (!strcasecmp(value
, "none"))
1933 if (!strcasecmp(line
, "Allow"))
1934 AllowIP(loc
, ones
, zeros
);
1936 DenyIP(loc
, ones
, zeros
);
1938 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1941 * Host or domain name...
1944 if (value
[0] == '*')
1947 if (!strcasecmp(line
, "Allow"))
1948 AllowHost(loc
, value
);
1950 DenyHost(loc
, value
);
1955 * One of many IP address forms...
1958 if (!get_addr_and_mask(value
, ip
, mask
))
1960 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1965 if (!strcasecmp(line
, "Allow"))
1966 AllowIP(loc
, ip
, mask
);
1968 DenyIP(loc
, ip
, mask
);
1971 else if (!strcasecmp(line
, "AuthType"))
1974 * AuthType {none,basic,digest,basicdigest}
1977 if (!strcasecmp(value
, "none"))
1979 loc
->type
= AUTH_NONE
;
1980 loc
->level
= AUTH_ANON
;
1982 else if (!strcasecmp(value
, "basic"))
1984 loc
->type
= AUTH_BASIC
;
1986 if (loc
->level
== AUTH_ANON
)
1987 loc
->level
= AUTH_USER
;
1989 else if (!strcasecmp(value
, "digest"))
1991 loc
->type
= AUTH_DIGEST
;
1993 if (loc
->level
== AUTH_ANON
)
1994 loc
->level
= AUTH_USER
;
1996 else if (!strcasecmp(value
, "basicdigest"))
1998 loc
->type
= AUTH_BASICDIGEST
;
2000 if (loc
->level
== AUTH_ANON
)
2001 loc
->level
= AUTH_USER
;
2004 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2007 else if (!strcasecmp(line
, "AuthClass"))
2010 * AuthClass anonymous, user, system, group
2013 if (!strcasecmp(value
, "anonymous"))
2015 loc
->type
= AUTH_NONE
;
2016 loc
->level
= AUTH_ANON
;
2018 else if (!strcasecmp(value
, "user"))
2019 loc
->level
= AUTH_USER
;
2020 else if (!strcasecmp(value
, "group"))
2021 loc
->level
= AUTH_GROUP
;
2022 else if (!strcasecmp(value
, "system"))
2024 loc
->level
= AUTH_GROUP
;
2027 * Use the default system group if none is defined so far...
2030 if (NumSystemGroups
)
2031 NumSystemGroups
= 1;
2033 for (i
= 0; i
< NumSystemGroups
; i
++)
2034 AddName(loc
, SystemGroups
[i
]);
2037 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2040 else if (!strcasecmp(line
, "AuthGroupName"))
2041 AddName(loc
, value
);
2042 else if (!strcasecmp(line
, "Require"))
2045 * Apache synonym for AuthClass and AuthGroupName...
2049 * Require valid-user
2050 * Require group names
2051 * Require user names
2054 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2059 if (!strcasecmp(value
, "valid-user") ||
2060 !strcasecmp(value
, "user"))
2061 loc
->level
= AUTH_USER
;
2062 else if (!strcasecmp(value
, "group"))
2063 loc
->level
= AUTH_GROUP
;
2066 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2072 * Get the list of names from the line...
2075 for (value
= valptr
; *value
;)
2077 while (isspace(*value
& 255))
2080 if (*value
== '\"' || *value
== '\'')
2083 * Grab quoted name...
2086 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2093 * Grab literal name.
2096 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2102 AddName(loc
, value
);
2104 for (value
= valptr
; isspace(*value
& 255); value
++);
2107 else if (!strcasecmp(line
, "Satisfy"))
2109 if (!strcasecmp(value
, "all"))
2110 loc
->satisfy
= AUTH_SATISFY_ALL
;
2111 else if (!strcasecmp(value
, "any"))
2112 loc
->satisfy
= AUTH_SATISFY_ANY
;
2114 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2118 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2122 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2130 * 'read_policy()' - Read a <Policy name> definition.
2133 static int /* O - New line number or 0 on error */
2134 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2135 char *policy
, /* I - Location name/path */
2136 int linenum
) /* I - Current line number */
2138 int i
; /* Looping var */
2139 policy_t
*pol
; /* Policy */
2140 policyop_t
*op
; /* Policy operation */
2141 int num_ops
; /* Number of IPP operations */
2142 ipp_op_t ops
[100]; /* Operations */
2143 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2144 *value
, /* Value for directive */
2145 *valptr
; /* Pointer into value */
2149 * Create the policy...
2152 if ((pol
= AddPolicy(policy
)) == NULL
)
2156 * Read from the file...
2162 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2165 * Decode the directive...
2168 if (!strcasecmp(line
, "</Policy>"))
2171 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2176 else if (!strcasecmp(line
, "<Limit") && !op
)
2180 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2185 * Scan for IPP operation names...
2192 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2197 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2199 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2200 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2206 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2209 for (value
= valptr
; isspace(*value
& 255); value
++);
2213 * If none are specified, apply the policy to all operations...
2218 ops
[0] = IPP_ANY_OPERATION
;
2223 * Add a new policy for the first operation...
2226 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2228 else if (!strcasecmp(line
, "</Limit>") && op
)
2231 * Finish the current operation limit...
2237 * Copy the policy to the other operations...
2240 for (i
= 1; i
< num_ops
; i
++)
2241 AddPolicyOp(pol
, op
, ops
[i
]);
2246 else if (!strcasecmp(line
, "Authenticate") && op
)
2249 * Authenticate boolean
2252 if (!strcasecmp(value
, "on") ||
2253 !strcasecmp(value
, "yes") ||
2254 !strcasecmp(value
, "true"))
2255 op
->authenticate
= 1;
2256 else if (!strcasecmp(value
, "off") ||
2257 !strcasecmp(value
, "no") ||
2258 !strcasecmp(value
, "false"))
2259 op
->authenticate
= 0;
2261 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2264 else if (!strcasecmp(line
, "Order") && op
)
2267 * "Order Deny,Allow" or "Order Allow,Deny"...
2270 if (!strncasecmp(value
, "deny", 4))
2271 op
->order_type
= POLICY_ALLOW
;
2272 else if (!strncasecmp(value
, "allow", 5))
2273 op
->order_type
= POLICY_DENY
;
2275 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2278 else if ((!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny")) && op
)
2281 * Allow line, @group, @OWNER
2282 * Deny line, @group, @OWNER
2285 for (value
= valptr
; *value
;)
2287 while (isspace(*value
& 255))
2290 if (*value
== '\"' || *value
== '\'')
2293 * Grab quoted name...
2296 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2303 * Grab literal name.
2306 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2312 if (!strcasecmp(line
, "Allow"))
2313 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2315 AddPolicyOpName(op
, POLICY_DENY
, value
);
2317 for (value
= valptr
; isspace(*value
& 255); value
++);
2321 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2324 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2328 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2336 * 'get_address()' - Get an address + port number from a line.
2339 static int /* O - 1 if address good, 0 if bad */
2340 get_address(const char *value
, /* I - Value string */
2341 unsigned defaddress
, /* I - Default address */
2342 int defport
, /* I - Default port */
2343 int deffamily
, /* I - Default family */
2344 http_addr_t
*address
) /* O - Socket address */
2346 char hostname
[256], /* Hostname or IP */
2347 portname
[256]; /* Port number or name */
2348 struct hostent
*host
; /* Host address */
2349 struct servent
*port
; /* Port number */
2353 * Initialize the socket address to the defaults...
2356 memset(address
, 0, sizeof(http_addr_t
));
2359 if (deffamily
== AF_INET6
)
2361 address
->ipv6
.sin6_family
= AF_INET6
;
2362 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2363 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2364 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2365 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2366 address
->ipv6
.sin6_port
= htons(defport
);
2369 #endif /* AF_INET6 */
2371 address
->ipv4
.sin_family
= AF_INET
;
2372 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2373 address
->ipv4
.sin_port
= htons(defport
);
2378 * If the address starts with a "/", it is a domain socket...
2383 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2385 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2389 address
->un
.sun_family
= AF_LOCAL
;
2390 strcpy(address
->un
.sun_path
, value
);
2394 #endif /* AF_LOCAL */
2397 * Try to grab a hostname and port number...
2400 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2403 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2406 * Hostname is a port number...
2409 strlcpy(portname
, hostname
, sizeof(portname
));
2420 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2425 * Decode the hostname and port number as needed...
2428 if (hostname
[0] && strcmp(hostname
, "*"))
2430 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2432 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2433 hstrerror(h_errno
));
2437 httpAddrLoad(host
, defport
, 0, address
);
2440 if (portname
[0] != '\0')
2442 if (isdigit(portname
[0] & 255))
2445 if (address
->addr
.sa_family
== AF_INET6
)
2446 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2448 #endif /* AF_INET6 */
2449 address
->ipv4
.sin_port
= htons(atoi(portname
));
2453 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2455 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2462 if (address
->addr
.sa_family
== AF_INET6
)
2463 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2465 #endif /* AF_INET6 */
2466 address
->ipv4
.sin_port
= htons(port
->s_port
);
2476 * 'get_addr_and_mask()' - Get an IP address and netmask.
2479 static int /* O - 1 on success, 0 on failure */
2480 get_addr_and_mask(const char *value
, /* I - String from config file */
2481 unsigned *ip
, /* O - Address value */
2482 unsigned *mask
) /* O - Mask value */
2484 int i
, /* Looping var */
2485 family
, /* Address family */
2486 ipcount
; /* Count of fields in address */
2487 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2489 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2490 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2491 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2492 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2497 * Get the address...
2500 memset(ip
, 0, sizeof(unsigned) * 4);
2502 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2506 * See if we have any values > 255; if so, this is an IPv6 address only.
2509 for (i
= 0; i
< ipcount
; i
++)
2515 #endif /* AF_INET6 */
2517 if ((value
= strchr(value
, '/')) != NULL
)
2520 * Get the netmask value(s)...
2524 memset(mask
, 0, sizeof(unsigned) * 4);
2525 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2526 mask
+ 2, mask
+ 3))
2533 if (family
== AF_INET6
)
2538 mask
[0] = 0xffffffff;
2540 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2543 mask
[1] = 0xffffffff;
2547 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2550 mask
[1] = 0xffffffff;
2554 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2559 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2562 #endif /* AF_INET6 */
2567 mask
[0] = 0xffffffff;
2569 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2572 mask
[1] = 0xffffffff;
2576 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2579 mask
[1] = 0xffffffff;
2583 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2588 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2599 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2602 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2605 if ((ip
[0] & ~mask
[0]) != 0 ||
2606 (ip
[1] & ~mask
[1]) != 0 ||
2607 (ip
[2] & ~mask
[2]) != 0 ||
2608 (ip
[3] & ~mask
[3]) != 0)
2616 * 'get_operation()' - Get an IPP opcode from an operation name...
2619 static ipp_op_t
/* O - Operation code or -1 on error */
2620 get_operation(const char *name
) /* I - Operating name */
2622 int i
; /* Looping var */
2623 static const char * const ipp_ops
[] = /* List of standard operations */
2627 /* 0x0002 */ "print-job",
2628 /* 0x0003 */ "print-uri",
2629 /* 0x0004 */ "validate-job",
2630 /* 0x0005 */ "create-job",
2631 /* 0x0006 */ "send-document",
2632 /* 0x0007 */ "send-uri",
2633 /* 0x0008 */ "cancel-job",
2634 /* 0x0009 */ "get-job-attributes",
2635 /* 0x000a */ "get-jobs",
2636 /* 0x000b */ "get-printer-attributes",
2637 /* 0x000c */ "hold-job",
2638 /* 0x000d */ "release-job",
2639 /* 0x000e */ "restart-job",
2641 /* 0x0010 */ "pause-printer",
2642 /* 0x0011 */ "resume-printer",
2643 /* 0x0012 */ "purge-jobs",
2644 /* 0x0013 */ "set-printer-attributes",
2645 /* 0x0014 */ "set-job-attributes",
2646 /* 0x0015 */ "get-printer-supported-values",
2647 /* 0x0016 */ "create-printer-subscription",
2648 /* 0x0017 */ "create-job-subscription",
2649 /* 0x0018 */ "get-subscription-attributes",
2650 /* 0x0019 */ "get-subscriptions",
2651 /* 0x001a */ "renew-subscription",
2652 /* 0x001b */ "cancel-subscription",
2653 /* 0x001c */ "get-notifications",
2654 /* 0x001d */ "send-notifications",
2658 /* 0x0021 */ "get-print-support-files",
2659 /* 0x0022 */ "enable-printer",
2660 /* 0x0023 */ "disable-printer",
2661 /* 0x0024 */ "pause-printer-after-current-job",
2662 /* 0x0025 */ "hold-new-jobs",
2663 /* 0x0026 */ "release-held-new-jobs",
2664 /* 0x0027 */ "deactivate-printer",
2665 /* 0x0028 */ "activate-printer",
2666 /* 0x0029 */ "restart-printer",
2667 /* 0x002a */ "shutdown-printer",
2668 /* 0x002b */ "startup-printer",
2669 /* 0x002c */ "reprocess-job",
2670 /* 0x002d */ "cancel-current-job",
2671 /* 0x002e */ "suspend-current-job",
2672 /* 0x002f */ "resume-job",
2673 /* 0x0030 */ "promote-job",
2674 /* 0x0031 */ "schedule-job-after"
2676 *cups_ops
[] = /* List of CUPS operations */
2678 /* 0x4001 */ "cups-get-default",
2679 /* 0x4002 */ "cups-get-printers",
2680 /* 0x4003 */ "cups-add-printer",
2681 /* 0x4004 */ "cups-delete-printer",
2682 /* 0x4005 */ "cups-get-classes",
2683 /* 0x4006 */ "cups-add-class",
2684 /* 0x4007 */ "cups-delete-class",
2685 /* 0x4008 */ "cups-accept-jobs",
2686 /* 0x4009 */ "cups-reject-jobs",
2687 /* 0x400a */ "cups-set-default",
2688 /* 0x400b */ "cups-get-devices",
2689 /* 0x400c */ "cups-get-ppds",
2690 /* 0x400d */ "cups-move-job",
2691 /* 0x400e */ "cups-add-device",
2692 /* 0x400f */ "cups-delete-device"
2696 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2697 if (!strcasecmp(name
, ipp_ops
[i
]))
2698 return ((ipp_op_t
)i
);
2700 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2701 if (!strcasecmp(name
, cups_ops
[i
]))
2702 return ((ipp_op_t
)(i
+ 0x4001));
2704 return ((ipp_op_t
)-1);
2710 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2711 * required by SSLSetCertificate.
2713 * For now we assumes that there is exactly one SecIdentity in the
2714 * keychain - i.e. there is exactly one matching cert/private key pair.
2715 * In the future we will search a keychain for a SecIdentity matching a
2716 * specific criteria. We also skip the operation of adding additional
2717 * non-signing certs from the keychain to the CFArrayRef.
2719 * To create a self-signed certificate for testing use the certtool.
2720 * Executing the following as root will do it:
2722 * certtool c c v k=CUPS
2726 CDSAGetServerCerts(void)
2728 OSStatus err
; /* Error info */
2729 SecKeychainRef kcRef
; /* Keychain reference */
2730 SecIdentitySearchRef srchRef
; /* Search reference */
2731 SecIdentityRef identity
; /* Identity */
2732 CFArrayRef ca
; /* Certificate array */
2739 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2742 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2743 ServerCertificate
, err
);
2747 * Search for "any" identity matching specified key use;
2748 * in this app, we expect there to be exactly one.
2751 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2755 "Cannot find signing key in keychain \"%s\", error %d",
2756 ServerCertificate
, err
);
2759 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2763 "Cannot find signing key in keychain \"%s\", error %d",
2764 ServerCertificate
, err
);
2767 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2768 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2772 * Found one. Place it in a CFArray.
2773 * TBD: snag other (non-identity) certs from keychain and add them
2777 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2780 LogMessage(L_ERROR
, "CFArrayCreate error");
2783 /*CFRelease(identity);*/
2786 /*CFRelease(srchRef);*/
2789 /*CFRelease(kcRef);*/
2794 #endif /* HAVE_CDSASSL */