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 { "TempDir", &TempDir
, VAR_STRING
},
155 { "Timeout", &Timeout
, VAR_INTEGER
}
157 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
160 static unsigned ones
[4] =
162 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
164 static unsigned zeros
[4] =
166 0x00000000, 0x00000000, 0x00000000, 0x00000000
170 static CFArrayRef
CDSAGetServerCerts();
171 #endif /* HAVE_CDSASSL */
178 static int read_configuration(cups_file_t
*fp
);
179 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
180 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
181 static int get_address(const char *value
, unsigned defaddress
, int defport
,
182 int deffamily
, http_addr_t
*address
);
183 static int get_addr_and_mask(const char *value
, unsigned *ip
,
185 static ipp_op_t
get_operation(const char *name
);
189 * 'ReadConfiguration()' - Read the cupsd.conf file.
192 int /* O - 1 on success, 0 otherwise */
193 ReadConfiguration(void)
195 int i
; /* Looping var */
196 cups_file_t
*fp
; /* Configuration file */
197 int status
; /* Return status */
198 char temp
[1024], /* Temporary buffer */
199 *slash
; /* Directory separator */
200 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
202 char *language
; /* Language string */
203 struct passwd
*user
; /* Default user */
204 struct group
*group
; /* Default group */
205 char *old_serverroot
, /* Old ServerRoot */
206 *old_requestroot
; /* Old RequestRoot */
210 * Shutdown the server...
216 * Save the old root paths...
219 old_serverroot
= NULL
;
220 SetString(&old_serverroot
, ServerRoot
);
221 old_requestroot
= NULL
;
222 SetString(&old_requestroot
, RequestRoot
);
225 * Reset the server configuration data...
228 DeleteAllLocations();
246 for (i
= 0; i
< NumRelays
; i
++)
247 if (Relays
[i
].from
.type
== AUTH_NAME
)
248 free(Relays
[i
].from
.mask
.name
.name
);
255 if (NumListeners
> 0)
257 #ifdef HAVE_DOMAINSOCKETS
258 int i
; /* Looping var */
259 listener_t
*lis
; /* Current listening socket */
261 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
262 if (lis
->address
.sin_family
== AF_LOCAL
)
263 ClearString((char **)&lis
->address
.sin_addr
);
264 #endif /* HAVE_DOMAINSOCKETS */
275 gethostname(temp
, sizeof(temp
));
276 SetString(&ServerName
, temp
);
277 SetStringf(&ServerAdmin
, "root@%s", temp
);
278 SetString(&ServerBin
, CUPS_SERVERBIN
);
279 SetString(&RequestRoot
, CUPS_REQUESTS
);
280 SetString(&DocumentRoot
, CUPS_DOCROOT
);
281 SetString(&DataDir
, CUPS_DATADIR
);
282 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
283 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
284 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
285 SetString(&Printcap
, "/etc/printcap");
286 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
287 SetString(&FontPath
, CUPS_FONTPATH
);
288 SetString(&RemoteRoot
, "remroot");
289 SetString(&ServerHeader
, "CUPS/1.1");
291 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
292 if ((slash
= strrchr(temp
, '/')) != NULL
)
295 SetString(&ServerRoot
, temp
);
297 ClearString(&Classification
);
298 ClassifyOverride
= 0;
302 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
304 SetString(&ServerCertificate
, "ssl/server.crt");
305 SetString(&ServerKey
, "ssl/server.key");
306 # endif /* HAVE_CDSASSL */
307 #endif /* HAVE_SSL */
309 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
311 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
314 SetString(&DefaultLanguage
, language
);
315 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
317 SetString(&RIPCache
, "8m");
319 if (getenv("TMPDIR") == NULL
)
320 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
322 SetString(&TempDir
, getenv("TMPDIR"));
325 * Find the default system group: "sys", "system", or "root"...
328 group
= getgrnam(CUPS_DEFAULT_GROUP
);
335 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
336 Group
= group
->gr_gid
;
345 SetString(&SystemGroups
[0], group
->gr_name
);
350 SetString(&SystemGroups
[0], "unknown");
356 * Find the default user...
359 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
360 User
= 1; /* Force to a non-priviledged account */
370 ConfigFilePerm
= 0640;
374 FaxRetryInterval
= 300;
379 HostNameLookups
= FALSE
;
380 ImplicitClasses
= TRUE
;
381 ImplicitAnyClasses
= FALSE
;
382 HideImplicitMembers
= TRUE
;
384 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
385 ListenBackLog
= SOMAXCONN
;
388 MaxClientsPerHost
= 0;
389 MaxLogSize
= 1024 * 1024;
390 MaxPrinterHistory
= 10;
393 RootCertDuration
= 300;
395 Timeout
= DEFAULT_TIMEOUT
;
397 BrowseInterval
= DEFAULT_INTERVAL
;
398 BrowsePort
= ippPort();
399 BrowseProtocols
= BROWSE_CUPS
;
400 BrowseShortNames
= TRUE
;
401 BrowseTimeout
= DEFAULT_TIMEOUT
;
404 ClearString(&BrowseLocalOptions
);
405 ClearString(&BrowseRemoteOptions
);
407 JobHistory
= DEFAULT_HISTORY
;
408 JobFiles
= DEFAULT_FILES
;
413 MaxJobsPerPrinter
= 0;
416 ClearString(&DefaultPolicy
);
419 * Read the configuration file...
422 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
425 status
= read_configuration(fp
);
438 * Use the default system group if none was supplied in cupsd.conf...
441 if (NumSystemGroups
== 0)
445 * Get the access control list for browsing...
448 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
451 * Open the system log for cupsd if necessary...
455 if (strcmp(AccessLog
, "syslog") == 0 ||
456 strcmp(ErrorLog
, "syslog") == 0 ||
457 strcmp(PageLog
, "syslog") == 0)
458 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
459 #endif /* HAVE_VSYSLOG */
462 * Log the configuration file that was used...
465 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
468 * Check that we have at least one listen/port line; if not, report this
469 * as an error and exit!
472 if (NumListeners
== 0)
478 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
484 kill(getpid(), SIGTERM
);
488 * Set the default locale using the language and charset...
491 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
494 * Update all relative filenames to include the full path from ServerRoot...
497 if (DocumentRoot
[0] != '/')
498 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
500 if (RequestRoot
[0] != '/')
501 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
503 if (ServerBin
[0] != '/')
504 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
507 if (ServerCertificate
[0] != '/')
508 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
510 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
511 chown(ServerCertificate
, RunUser
, Group
);
512 chmod(ServerCertificate
, ConfigFilePerm
);
514 if (ServerKey
[0] != '/')
515 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
517 chown(ServerKey
, RunUser
, Group
);
518 chmod(ServerKey
, ConfigFilePerm
);
519 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
520 #endif /* HAVE_SSL */
523 * Make sure that ServerRoot and the config files are owned and
524 * writable by the user and group in the cupsd.conf file...
527 chown(ServerRoot
, RunUser
, Group
);
528 chmod(ServerRoot
, 0775);
530 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
531 chown(temp
, RunUser
, Group
);
534 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
535 chown(temp
, RunUser
, Group
);
538 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
539 chown(temp
, RunUser
, Group
);
542 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
543 chown(temp
, RunUser
, Group
);
544 chmod(temp
, ConfigFilePerm
);
546 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
547 chown(temp
, RunUser
, Group
);
551 chmod(temp
, ConfigFilePerm
);
552 #endif /* __APPLE__ */
554 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
555 chown(temp
, RunUser
, Group
);
559 chmod(temp
, ConfigFilePerm
);
560 #endif /* __APPLE__ */
562 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
563 chown(temp
, User
, Group
);
567 * Make sure the request and temporary directories have the right
571 chown(RequestRoot
, RunUser
, Group
);
572 chmod(RequestRoot
, 0710);
574 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
577 * Only update ownership and permissions if the CUPS temp directory
578 * is under the spool directory...
581 chown(TempDir
, RunUser
, Group
);
582 chmod(TempDir
, 01770);
586 * Check the MaxClients setting, and then allocate memory for it...
589 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
592 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
595 MaxClients
= MaxFDs
/ 3;
598 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
600 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
601 MaxClients
, strerror(errno
));
605 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
608 * Check the MaxActiveJobs setting; limit to 1/3 the available
609 * file descriptors, since we need a pipe for each job...
612 if (MaxActiveJobs
> (MaxFDs
/ 3))
613 MaxActiveJobs
= MaxFDs
/ 3;
615 if (Classification
&& strcasecmp(Classification
, "none") == 0)
616 ClearString(&Classification
);
619 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
622 * Update the MaxClientsPerHost value, as needed...
625 if (MaxClientsPerHost
<= 0)
626 MaxClientsPerHost
= MaxClients
;
628 if (MaxClientsPerHost
> MaxClients
)
629 MaxClientsPerHost
= MaxClients
;
631 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
635 * Update the default policy, as needed...
639 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
641 DefaultPolicyPtr
= NULL
;
643 if (!DefaultPolicyPtr
)
645 policy_t
*p
; /* New policy */
646 policyop_t
*po
; /* New policy operation */
647 char groupname
[255]; /* Group name */
651 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
653 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
654 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
657 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
659 DefaultPolicyPtr
= p
= AddPolicy("default");
661 LogMessage(L_INFO
, "<Policy default>");
662 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
663 "Release-Job Restart-Job Purge-Jobs "
664 "Set-Job-Attributes Create-Job-Subscription "
665 "Renew-Subscription Cancel-Subscription "
666 "Get-Notifications Reprocess-Job Cancel-Current-Job "
667 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
668 LogMessage(L_INFO
, "Order Allow,Deny");
669 LogMessage(L_INFO
, "Allow @OWNER");
671 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
672 po
->order_type
= POLICY_DENY
;
674 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
676 for (i
= 0; i
< NumSystemGroups
; i
++)
678 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
679 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
680 LogMessage(L_INFO
, "Allow %s", groupname
);
683 AddPolicyOp(p
, po
, IPP_SEND_URI
);
684 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
685 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
686 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
687 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
688 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
689 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
690 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
691 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
692 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
693 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
694 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
695 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
696 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
697 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
698 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
700 LogMessage(L_INFO
, "</Limit>");
702 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
703 "Set-Printer-Attributes Enable-Printer "
704 "Disable-Printer Pause-Printer-After-Current-Job "
705 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
706 "Activate-Printer Restart-Printer Shutdown-Printer "
707 "Startup-Printer Promote-Job Schedule-Job-After "
708 "CUPS-Add-Printer CUPS-Delete-Printer "
709 "CUPS-Add-Class CUPS-Delete-Class "
710 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
711 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
712 LogMessage(L_INFO
, "Order Allow,Deny");
713 LogMessage(L_INFO
, "Authenticate yes");
715 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
716 po
->order_type
= POLICY_DENY
;
717 po
->authenticate
= 1;
719 for (i
= 0; i
< NumSystemGroups
; i
++)
721 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
722 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
723 LogMessage(L_INFO
, "Allow %s", groupname
);
726 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
727 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
728 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
729 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
730 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
731 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
732 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
733 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
734 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
735 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
736 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
737 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
738 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
739 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
740 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
741 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
742 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
743 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
744 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
745 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
746 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
747 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
748 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
750 LogMessage(L_INFO
, "</Limit>");
752 LogMessage(L_INFO
, "<Limit All>");
753 LogMessage(L_INFO
, "Order Deny,Allow");
755 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
756 po
->order_type
= POLICY_ALLOW
;
758 LogMessage(L_INFO
, "</Limit>");
759 LogMessage(L_INFO
, "</Policy>");
764 * If we are doing a full reload or the server root has changed, flush
765 * the jobs, printers, etc. and start from scratch...
768 if (NeedReload
== RELOAD_ALL
||
769 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
770 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
772 LogMessage(L_INFO
, "Full reload is required.");
782 DefaultPrinter
= NULL
;
796 if (MimeDatabase
!= NULL
)
797 mimeDelete(MimeDatabase
);
801 for (i
= 0; i
< NumMimeTypes
; i
++)
802 free((void *)MimeTypes
[i
]);
808 * Read the MIME type and conversion database...
811 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
813 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
815 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
816 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
819 * Create a list of MIME types for the document-format-supported
823 NumMimeTypes
= MimeDatabase
->num_types
;
824 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
827 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
829 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
831 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
832 MimeDatabase
->types
[i
]->type
);
834 MimeTypes
[i
] = strdup(type
);
837 if (i
< NumMimeTypes
)
838 MimeTypes
[i
] = strdup("application/octet-stream");
844 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
848 * Load printers and classes...
857 * Load devices and PPDs...
860 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
863 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
867 * Load queued jobs...
872 LogMessage(L_INFO
, "Full reload complete.");
878 LogMessage(L_INFO
, "Partial reload complete.");
882 * Reset the reload state...
885 NeedReload
= RELOAD_NONE
;
887 ClearString(&old_serverroot
);
888 ClearString(&old_requestroot
);
891 * Startup the server and return...
901 * 'read_configuration()' - Read a configuration file.
904 static int /* O - 1 on success, 0 on failure */
905 read_configuration(cups_file_t
*fp
) /* I - File to read from */
907 int i
; /* Looping var */
908 int linenum
; /* Current line number */
909 char line
[HTTP_MAX_BUFFER
], /* Line from file */
910 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
911 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
912 *ptr
, /* Pointer into line/temp */
913 *value
; /* Pointer to value */
914 int valuelen
; /* Length of value */
915 var_t
*var
; /* Current variable */
916 unsigned ip
[4], /* Address value */
917 mask
[4]; /* Netmask value */
918 dirsvc_relay_t
*relay
; /* Relay data */
919 dirsvc_poll_t
*poll
; /* Polling data */
920 http_addr_t polladdr
; /* Polling address */
921 location_t
*location
; /* Browse location */
922 cups_file_t
*incfile
; /* Include file */
923 char incname
[1024]; /* Include filename */
927 * Loop through each line in the file...
932 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
935 * Decode the directive...
938 if (!strcasecmp(line
, "Include"))
945 strlcpy(incname
, value
, sizeof(incname
));
947 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
949 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
950 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
951 incname
, strerror(errno
));
954 read_configuration(incfile
);
955 cupsFileClose(incfile
);
958 else if (!strcasecmp(line
, "<Location"))
966 linenum
= read_location(fp
, value
, linenum
);
972 LogMessage(L_ERROR
, "Syntax error on line %d.",
977 else if (!strcasecmp(line
, "<Policy"))
985 linenum
= read_policy(fp
, value
, linenum
);
991 LogMessage(L_ERROR
, "Syntax error on line %d.",
996 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
999 * Add a listening address to the list...
1002 listener_t
*lis
; /* New listeners array */
1005 if (NumListeners
== 0)
1006 lis
= malloc(sizeof(listener_t
));
1008 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1012 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1013 line
, linenum
, strerror(errno
));
1018 lis
+= NumListeners
;
1020 memset(lis
, 0, sizeof(listener_t
));
1022 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1024 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1027 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1028 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1029 ntohs(lis
->address
.ipv6
.sin6_port
));
1031 #endif /* AF_INET6 */
1032 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1033 ntohs(lis
->address
.ipv4
.sin_port
));
1037 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1041 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1044 * Add a listening address to the list...
1047 listener_t
*lis
; /* New listeners array */
1050 if (NumListeners
== 0)
1051 lis
= malloc(sizeof(listener_t
));
1053 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1057 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1058 line
, linenum
, strerror(errno
));
1063 lis
+= NumListeners
;
1065 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1067 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1070 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1071 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1072 ntohs(lis
->address
.ipv6
.sin6_port
));
1074 #endif /* AF_INET6 */
1075 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1076 ntohs(lis
->address
.ipv4
.sin_port
));
1077 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1081 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1084 #endif /* HAVE_SSL */
1085 else if (!strcasecmp(line
, "BrowseAddress"))
1088 * Add a browse address to the list...
1091 dirsvc_addr_t
*dira
; /* New browse address array */
1094 if (NumBrowsers
== 0)
1095 dira
= malloc(sizeof(dirsvc_addr_t
));
1097 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1101 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1102 linenum
, strerror(errno
));
1107 dira
+= NumBrowsers
;
1109 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1111 if (!strcasecmp(value
, "@LOCAL"))
1114 * Send browse data to all local interfaces...
1117 strcpy(dira
->iface
, "*");
1120 else if (!strncasecmp(value
, "@IF(", 4))
1123 * Send browse data to the named interface...
1126 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1128 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1134 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1136 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1139 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1140 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1141 ntohs(dira
->to
.ipv6
.sin6_port
));
1143 #endif /* AF_INET6 */
1144 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1145 ntohs(dira
->to
.ipv4
.sin_port
));
1150 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1153 else if (!strcasecmp(line
, "BrowseOrder"))
1156 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1159 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1160 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1162 if (location
== NULL
)
1163 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1164 else if (!strncasecmp(value
, "deny", 4))
1165 location
->order_type
= AUTH_ALLOW
;
1166 else if (!strncasecmp(value
, "allow", 5))
1167 location
->order_type
= AUTH_DENY
;
1169 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1172 else if (!strcasecmp(line
, "BrowseProtocols"))
1175 * "BrowseProtocol name [... name]"
1178 BrowseProtocols
= 0;
1182 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1183 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1186 if (value
[valuelen
])
1188 value
[valuelen
] = '\0';
1192 if (!strcasecmp(value
, "cups"))
1193 BrowseProtocols
|= BROWSE_CUPS
;
1194 else if (!strcasecmp(value
, "slp"))
1195 BrowseProtocols
|= BROWSE_SLP
;
1196 else if (!strcasecmp(value
, "ldap"))
1197 BrowseProtocols
|= BROWSE_LDAP
;
1198 else if (!strcasecmp(value
, "all"))
1199 BrowseProtocols
|= BROWSE_ALL
;
1202 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1207 for (value
+= valuelen
; *value
; value
++)
1208 if (!isspace(*value
) || *value
!= ',')
1212 else if (!strcasecmp(line
, "BrowseAllow") ||
1213 !strcasecmp(line
, "BrowseDeny"))
1216 * BrowseAllow [From] host/ip...
1217 * BrowseDeny [From] host/ip...
1220 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1221 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1223 if (location
== NULL
)
1224 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1227 if (!strncasecmp(value
, "from ", 5))
1230 * Strip leading "from"...
1235 while (isspace(*value
))
1240 * Figure out what form the allow/deny address takes:
1251 * nnn.nnn.nnn.nnn/mm
1252 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1255 if (!strcasecmp(value
, "all"))
1261 if (!strcasecmp(line
, "BrowseAllow"))
1262 AllowIP(location
, zeros
, zeros
);
1264 DenyIP(location
, zeros
, zeros
);
1266 else if (!strcasecmp(value
, "none"))
1272 if (!strcasecmp(line
, "BrowseAllow"))
1273 AllowIP(location
, ones
, zeros
);
1275 DenyIP(location
, ones
, zeros
);
1277 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1280 * Host or domain name...
1283 if (value
[0] == '*')
1286 if (!strcasecmp(line
, "BrowseAllow"))
1287 AllowHost(location
, value
);
1289 DenyHost(location
, value
);
1294 * One of many IP address forms...
1297 if (!get_addr_and_mask(value
, ip
, mask
))
1299 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1304 if (!strcasecmp(line
, "BrowseAllow"))
1305 AllowIP(location
, ip
, mask
);
1307 DenyIP(location
, ip
, mask
);
1311 else if (!strcasecmp(line
, "BrowseRelay"))
1314 * BrowseRelay [from] source [to] destination
1318 relay
= malloc(sizeof(dirsvc_relay_t
));
1320 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1324 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1325 linenum
, strerror(errno
));
1332 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1334 if (!strncasecmp(value
, "from ", 5))
1337 * Strip leading "from"...
1342 while (isspace(*value
))
1347 * Figure out what form the from address takes:
1356 * nnn.nnn.nnn.nnn/mm
1357 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1360 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1363 * Host or domain name...
1366 if (value
[0] == '*')
1369 strlcpy(temp
, value
, sizeof(temp
));
1370 if ((ptr
= strchr(temp
, ' ')) != NULL
)
1373 relay
->from
.type
= AUTH_NAME
;
1374 relay
->from
.mask
.name
.name
= strdup(temp
);
1375 relay
->from
.mask
.name
.length
= strlen(temp
);
1380 * One of many IP address forms...
1383 if (!get_addr_and_mask(value
, ip
, mask
))
1385 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1390 relay
->from
.type
= AUTH_IP
;
1391 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1392 sizeof(relay
->from
.mask
.ip
.address
));
1393 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1394 sizeof(relay
->from
.mask
.ip
.netmask
));
1398 * Skip value and trailing whitespace...
1401 for (; *value
; value
++)
1402 if (isspace(*value
))
1405 while (isspace(*value
))
1408 if (!strncasecmp(value
, "to ", 3))
1411 * Strip leading "to"...
1416 while (isspace(*value
))
1421 * Get "to" address and port...
1424 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1426 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
1428 if (relay
->from
.type
== AUTH_IP
)
1429 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
1430 relay
->from
.mask
.ip
.address
[0],
1431 relay
->from
.mask
.ip
.address
[1],
1432 relay
->from
.mask
.ip
.address
[2],
1433 relay
->from
.mask
.ip
.address
[3],
1434 relay
->from
.mask
.ip
.netmask
[0],
1435 relay
->from
.mask
.ip
.netmask
[1],
1436 relay
->from
.mask
.ip
.netmask
[2],
1437 relay
->from
.mask
.ip
.netmask
[3]);
1439 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
1442 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1443 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1444 ntohs(relay
->to
.ipv6
.sin6_port
));
1446 #endif /* AF_INET6 */
1447 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1448 ntohs(relay
->to
.ipv4
.sin_port
));
1454 if (relay
->from
.type
== AUTH_NAME
)
1455 free(relay
->from
.mask
.name
.name
);
1457 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1460 else if (!strcasecmp(line
, "BrowsePoll"))
1463 * BrowsePoll address[:port]
1467 poll
= malloc(sizeof(dirsvc_poll_t
));
1469 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1473 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1474 linenum
, strerror(errno
));
1482 * Get poll address and port...
1485 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1488 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1490 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1493 if (polladdr
.addr
.sa_family
== AF_INET6
)
1494 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1496 #endif /* AF_INET6 */
1497 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1499 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1502 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1504 else if (!strcasecmp(line
, "User"))
1507 * User ID to run as...
1510 if (isdigit(value
[0]))
1514 struct passwd
*p
; /* Password information */
1517 p
= getpwnam(value
);
1522 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
1525 else if (!strcasecmp(line
, "Group"))
1528 * Group ID to run as...
1531 if (isdigit(value
[0]))
1532 Group
= atoi(value
);
1535 struct group
*g
; /* Group information */
1538 g
= getgrnam(value
);
1543 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
1546 else if (!strcasecmp(line
, "SystemGroup"))
1549 * System (admin) group(s)...
1552 char *valueptr
, /* Pointer into value */
1553 quote
; /* Quote character */
1556 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1558 if (*value
== '\'' || *value
== '\"')
1561 * Scan quoted name...
1566 for (valueptr
= value
; *valueptr
; valueptr
++)
1567 if (*valueptr
== quote
)
1573 * Scan space or comma-delimited name...
1576 for (valueptr
= value
; *valueptr
; valueptr
++)
1577 if (isspace(*valueptr
) || *valueptr
== ',')
1584 SetString(SystemGroups
+ i
, value
);
1588 while (*value
== ',' || isspace(*value
))
1593 NumSystemGroups
= i
;
1595 else if (!strcasecmp(line
, "HostNameLookups"))
1598 * Do hostname lookups?
1601 if (!strcasecmp(value
, "off"))
1602 HostNameLookups
= 0;
1603 else if (!strcasecmp(value
, "on"))
1604 HostNameLookups
= 1;
1605 else if (!strcasecmp(value
, "double"))
1606 HostNameLookups
= 2;
1608 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1611 else if (!strcasecmp(line
, "LogLevel"))
1614 * Amount of logging to do...
1617 if (!strcasecmp(value
, "debug2"))
1618 LogLevel
= L_DEBUG2
;
1619 else if (!strcasecmp(value
, "debug"))
1621 else if (!strcasecmp(value
, "info"))
1623 else if (!strcasecmp(value
, "notice"))
1624 LogLevel
= L_NOTICE
;
1625 else if (!strcasecmp(value
, "warn"))
1627 else if (!strcasecmp(value
, "error"))
1629 else if (!strcasecmp(value
, "crit"))
1631 else if (!strcasecmp(value
, "alert"))
1633 else if (!strcasecmp(value
, "emerg"))
1635 else if (!strcasecmp(value
, "none"))
1638 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1640 else if (!strcasecmp(line
, "PrintcapFormat"))
1643 * Format of printcap file?
1646 if (!strcasecmp(value
, "bsd"))
1647 PrintcapFormat
= PRINTCAP_BSD
;
1648 else if (!strcasecmp(value
, "solaris"))
1649 PrintcapFormat
= PRINTCAP_SOLARIS
;
1651 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1654 else if (!strcasecmp(line
, "ServerTokens"))
1657 * Set the string used for the Server header...
1660 struct utsname plat
; /* Platform info */
1665 if (!strcasecmp(value
, "ProductOnly"))
1666 SetString(&ServerHeader
, "CUPS");
1667 else if (!strcasecmp(value
, "Major"))
1668 SetString(&ServerHeader
, "CUPS/1");
1669 else if (!strcasecmp(value
, "Minor"))
1670 SetString(&ServerHeader
, "CUPS/1.1");
1671 else if (!strcasecmp(value
, "Minimal"))
1672 SetString(&ServerHeader
, CUPS_MINIMAL
);
1673 else if (!strcasecmp(value
, "OS"))
1674 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1675 else if (!strcasecmp(value
, "Full"))
1676 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1677 else if (!strcasecmp(value
, "None"))
1678 ClearString(&ServerHeader
);
1680 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1685 * Find a simple variable in the list...
1688 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1689 if (!strcasecmp(line
, var
->name
))
1695 * Unknown directive! Output an error message and continue...
1698 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
1708 char *units
; /* Units */
1711 n
= strtol(value
, &units
, 0);
1713 if (units
&& *units
)
1715 if (tolower(units
[0] & 255) == 'g')
1716 n
*= 1024 * 1024 * 1024;
1717 else if (tolower(units
[0] & 255) == 'm')
1719 else if (tolower(units
[0] & 255) == 'k')
1721 else if (tolower(units
[0] & 255) == 't')
1725 *((int *)var
->ptr
) = n
;
1730 if (!strcasecmp(value
, "true") ||
1731 !strcasecmp(value
, "on") ||
1732 !strcasecmp(value
, "enabled") ||
1733 !strcasecmp(value
, "yes") ||
1735 *((int *)var
->ptr
) = TRUE
;
1736 else if (!strcasecmp(value
, "false") ||
1737 !strcasecmp(value
, "off") ||
1738 !strcasecmp(value
, "disabled") ||
1739 !strcasecmp(value
, "no") ||
1740 !strcasecmp(value
, "0"))
1741 *((int *)var
->ptr
) = FALSE
;
1743 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1748 SetString((char **)var
->ptr
, value
);
1759 * 'read_location()' - Read a <Location path> definition.
1762 static int /* O - New line number or 0 on error */
1763 read_location(cups_file_t
*fp
, /* I - Configuration file */
1764 char *location
, /* I - Location name/path */
1765 int linenum
) /* I - Current line number */
1767 int i
; /* Looping var */
1768 location_t
*loc
, /* New location */
1769 *parent
; /* Parent location */
1770 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1771 *value
, /* Value for directive */
1772 *valptr
; /* Pointer into value */
1773 unsigned ip
[4], /* IP address components */
1774 mask
[4]; /* IP netmask components */
1777 if ((parent
= AddLocation(location
)) == NULL
)
1780 parent
->limit
= AUTH_LIMIT_ALL
;
1783 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1786 * Decode the directive...
1789 if (!strcasecmp(line
, "</Location>"))
1791 else if (!strcasecmp(line
, "<Limit") ||
1792 !strcasecmp(line
, "<LimitExcept"))
1796 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
1800 if ((loc
= CopyLocation(&parent
)) == NULL
)
1806 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1811 if (!strcmp(value
, "ALL"))
1812 loc
->limit
= AUTH_LIMIT_ALL
;
1813 else if (!strcmp(value
, "GET"))
1814 loc
->limit
|= AUTH_LIMIT_GET
;
1815 else if (!strcmp(value
, "HEAD"))
1816 loc
->limit
|= AUTH_LIMIT_HEAD
;
1817 else if (!strcmp(value
, "OPTIONS"))
1818 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1819 else if (!strcmp(value
, "POST"))
1820 loc
->limit
|= AUTH_LIMIT_POST
;
1821 else if (!strcmp(value
, "PUT"))
1822 loc
->limit
|= AUTH_LIMIT_PUT
;
1823 else if (!strcmp(value
, "TRACE"))
1824 loc
->limit
|= AUTH_LIMIT_TRACE
;
1826 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1829 for (value
= valptr
; isspace(*value
& 255); value
++);
1832 if (!strcasecmp(line
, "<LimitExcept"))
1833 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1835 parent
->limit
&= ~loc
->limit
;
1837 else if (!strcasecmp(line
, "</Limit>"))
1839 else if (!strcasecmp(line
, "Encryption"))
1842 * "Encryption xxx" - set required encryption level...
1845 if (!strcasecmp(value
, "never"))
1846 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1847 else if (!strcasecmp(value
, "always"))
1849 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1850 "Using \"required\" instead.", value
, linenum
);
1852 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1854 else if (!strcasecmp(value
, "required"))
1855 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1856 else if (!strcasecmp(value
, "ifrequested"))
1857 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1859 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1862 else if (!strcasecmp(line
, "Order"))
1865 * "Order Deny,Allow" or "Order Allow,Deny"...
1868 if (!strncasecmp(value
, "deny", 4))
1869 loc
->order_type
= AUTH_ALLOW
;
1870 else if (!strncasecmp(value
, "allow", 5))
1871 loc
->order_type
= AUTH_DENY
;
1873 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1876 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1879 * Allow [From] host/ip...
1880 * Deny [From] host/ip...
1883 if (!strncasecmp(value
, "from", 4))
1886 * Strip leading "from"...
1891 while (isspace(*value
& 255))
1896 * Figure out what form the allow/deny address takes:
1907 * nnn.nnn.nnn.nnn/mm
1908 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1911 if (!strcasecmp(value
, "all"))
1917 if (!strcasecmp(line
, "Allow"))
1918 AllowIP(loc
, zeros
, zeros
);
1920 DenyIP(loc
, zeros
, zeros
);
1922 else if (!strcasecmp(value
, "none"))
1928 if (!strcasecmp(line
, "Allow"))
1929 AllowIP(loc
, ones
, zeros
);
1931 DenyIP(loc
, ones
, zeros
);
1933 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1936 * Host or domain name...
1939 if (value
[0] == '*')
1942 if (!strcasecmp(line
, "Allow"))
1943 AllowHost(loc
, value
);
1945 DenyHost(loc
, value
);
1950 * One of many IP address forms...
1953 if (!get_addr_and_mask(value
, ip
, mask
))
1955 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1960 if (!strcasecmp(line
, "Allow"))
1961 AllowIP(loc
, ip
, mask
);
1963 DenyIP(loc
, ip
, mask
);
1966 else if (!strcasecmp(line
, "AuthType"))
1969 * AuthType {none,basic,digest,basicdigest}
1972 if (!strcasecmp(value
, "none"))
1974 loc
->type
= AUTH_NONE
;
1975 loc
->level
= AUTH_ANON
;
1977 else if (!strcasecmp(value
, "basic"))
1979 loc
->type
= AUTH_BASIC
;
1981 if (loc
->level
== AUTH_ANON
)
1982 loc
->level
= AUTH_USER
;
1984 else if (!strcasecmp(value
, "digest"))
1986 loc
->type
= AUTH_DIGEST
;
1988 if (loc
->level
== AUTH_ANON
)
1989 loc
->level
= AUTH_USER
;
1991 else if (!strcasecmp(value
, "basicdigest"))
1993 loc
->type
= AUTH_BASICDIGEST
;
1995 if (loc
->level
== AUTH_ANON
)
1996 loc
->level
= AUTH_USER
;
1999 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2002 else if (!strcasecmp(line
, "AuthClass"))
2005 * AuthClass anonymous, user, system, group
2008 if (!strcasecmp(value
, "anonymous"))
2010 loc
->type
= AUTH_NONE
;
2011 loc
->level
= AUTH_ANON
;
2013 else if (!strcasecmp(value
, "user"))
2014 loc
->level
= AUTH_USER
;
2015 else if (!strcasecmp(value
, "group"))
2016 loc
->level
= AUTH_GROUP
;
2017 else if (!strcasecmp(value
, "system"))
2019 loc
->level
= AUTH_GROUP
;
2022 * Use the default system group if none is defined so far...
2025 if (NumSystemGroups
)
2026 NumSystemGroups
= 1;
2028 for (i
= 0; i
< NumSystemGroups
; i
++)
2029 AddName(loc
, SystemGroups
[i
]);
2032 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2035 else if (!strcasecmp(line
, "AuthGroupName"))
2036 AddName(loc
, value
);
2037 else if (!strcasecmp(line
, "Require"))
2040 * Apache synonym for AuthClass and AuthGroupName...
2044 * Require valid-user
2045 * Require group names
2046 * Require user names
2049 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2054 if (!strcasecmp(value
, "valid-user") ||
2055 !strcasecmp(value
, "user"))
2056 loc
->level
= AUTH_USER
;
2057 else if (!strcasecmp(value
, "group"))
2058 loc
->level
= AUTH_GROUP
;
2061 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2067 * Get the list of names from the line...
2070 for (value
= valptr
; *value
;)
2072 while (isspace(*value
& 255))
2075 if (*value
== '\"' || *value
== '\'')
2078 * Grab quoted name...
2081 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2088 * Grab literal name.
2091 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2097 AddName(loc
, value
);
2099 for (value
= valptr
; isspace(*value
& 255); value
++);
2102 else if (!strcasecmp(line
, "Satisfy"))
2104 if (!strcasecmp(value
, "all"))
2105 loc
->satisfy
= AUTH_SATISFY_ALL
;
2106 else if (!strcasecmp(value
, "any"))
2107 loc
->satisfy
= AUTH_SATISFY_ANY
;
2109 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2113 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2117 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2125 * 'read_policy()' - Read a <Policy name> definition.
2128 static int /* O - New line number or 0 on error */
2129 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2130 char *policy
, /* I - Location name/path */
2131 int linenum
) /* I - Current line number */
2133 int i
; /* Looping var */
2134 policy_t
*pol
; /* Policy */
2135 policyop_t
*op
; /* Policy operation */
2136 int num_ops
; /* Number of IPP operations */
2137 ipp_op_t ops
[100]; /* Operations */
2138 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2139 *value
, /* Value for directive */
2140 *valptr
; /* Pointer into value */
2144 * Create the policy...
2147 if ((pol
= AddPolicy(policy
)) == NULL
)
2151 * Read from the file...
2157 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2160 * Decode the directive...
2163 if (!strcasecmp(line
, "</Policy>"))
2166 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2171 else if (!strcasecmp(line
, "<Limit") && !op
)
2175 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2180 * Scan for IPP operation names...
2187 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2192 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2194 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2195 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2201 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2204 for (value
= valptr
; isspace(*value
& 255); value
++);
2208 * If none are specified, apply the policy to all operations...
2213 ops
[0] = IPP_ANY_OPERATION
;
2218 * Add a new policy for the first operation...
2221 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2223 else if (!strcasecmp(line
, "</Limit>") && op
)
2226 * Finish the current operation limit...
2232 * Copy the policy to the other operations...
2235 for (i
= 1; i
< num_ops
; i
++)
2236 AddPolicyOp(pol
, op
, ops
[i
]);
2241 else if (!strcasecmp(line
, "Authenticate") && op
)
2244 * Authenticate boolean
2247 if (!strcasecmp(value
, "on") ||
2248 !strcasecmp(value
, "yes") ||
2249 !strcasecmp(value
, "true"))
2250 op
->authenticate
= 1;
2251 else if (!strcasecmp(value
, "off") ||
2252 !strcasecmp(value
, "no") ||
2253 !strcasecmp(value
, "false"))
2254 op
->authenticate
= 0;
2256 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2259 else if (!strcasecmp(line
, "Order") && op
)
2262 * "Order Deny,Allow" or "Order Allow,Deny"...
2265 if (!strncasecmp(value
, "deny", 4))
2266 op
->order_type
= POLICY_ALLOW
;
2267 else if (!strncasecmp(value
, "allow", 5))
2268 op
->order_type
= POLICY_DENY
;
2270 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2273 else if ((!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny")) && op
)
2276 * Allow line, @group, @OWNER
2277 * Deny line, @group, @OWNER
2280 for (value
= valptr
; *value
;)
2282 while (isspace(*value
& 255))
2285 if (*value
== '\"' || *value
== '\'')
2288 * Grab quoted name...
2291 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2298 * Grab literal name.
2301 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2307 if (!strcasecmp(line
, "Allow"))
2308 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2310 AddPolicyOpName(op
, POLICY_DENY
, value
);
2312 for (value
= valptr
; isspace(*value
& 255); value
++);
2316 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2319 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2323 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2331 * 'get_address()' - Get an address + port number from a line.
2334 static int /* O - 1 if address good, 0 if bad */
2335 get_address(const char *value
, /* I - Value string */
2336 unsigned defaddress
, /* I - Default address */
2337 int defport
, /* I - Default port */
2338 int deffamily
, /* I - Default family */
2339 http_addr_t
*address
) /* O - Socket address */
2341 char hostname
[256], /* Hostname or IP */
2342 portname
[256]; /* Port number or name */
2343 struct hostent
*host
; /* Host address */
2344 struct servent
*port
; /* Port number */
2348 * Initialize the socket address to the defaults...
2351 memset(address
, 0, sizeof(http_addr_t
));
2354 if (deffamily
== AF_INET6
)
2356 address
->ipv6
.sin6_family
= AF_INET6
;
2357 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2358 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2359 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2360 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2361 address
->ipv6
.sin6_port
= htons(defport
);
2364 #endif /* AF_INET6 */
2366 address
->ipv4
.sin_family
= AF_INET
;
2367 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2368 address
->ipv4
.sin_port
= htons(defport
);
2373 * If the address starts with a "/", it is a domain socket...
2378 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2380 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2384 address
->un
.sun_family
= AF_LOCAL
;
2385 strcpy(address
->un
.sun_path
, value
);
2389 #endif /* AF_LOCAL */
2392 * Try to grab a hostname and port number...
2395 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2398 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2401 * Hostname is a port number...
2404 strlcpy(portname
, hostname
, sizeof(portname
));
2415 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2420 * Decode the hostname and port number as needed...
2423 if (hostname
[0] && strcmp(hostname
, "*"))
2425 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2427 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2428 hstrerror(h_errno
));
2432 httpAddrLoad(host
, defport
, 0, address
);
2435 if (portname
[0] != '\0')
2437 if (isdigit(portname
[0] & 255))
2440 if (address
->addr
.sa_family
== AF_INET6
)
2441 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2443 #endif /* AF_INET6 */
2444 address
->ipv4
.sin_port
= htons(atoi(portname
));
2448 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2450 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2457 if (address
->addr
.sa_family
== AF_INET6
)
2458 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2460 #endif /* AF_INET6 */
2461 address
->ipv4
.sin_port
= htons(port
->s_port
);
2471 * 'get_addr_and_mask()' - Get an IP address and netmask.
2474 static int /* O - 1 on success, 0 on failure */
2475 get_addr_and_mask(const char *value
, /* I - String from config file */
2476 unsigned *ip
, /* O - Address value */
2477 unsigned *mask
) /* O - Mask value */
2479 int i
, /* Looping var */
2480 family
, /* Address family */
2481 ipcount
; /* Count of fields in address */
2482 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2484 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2485 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2486 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2487 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2492 * Get the address...
2495 memset(ip
, 0, sizeof(unsigned) * 4);
2497 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2501 * See if we have any values > 255; if so, this is an IPv6 address only.
2504 for (i
= 0; i
< ipcount
; i
++)
2510 #endif /* AF_INET6 */
2512 if ((value
= strchr(value
, '/')) != NULL
)
2515 * Get the netmask value(s)...
2519 memset(mask
, 0, sizeof(unsigned) * 4);
2520 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2521 mask
+ 2, mask
+ 3))
2528 if (family
== AF_INET6
)
2533 mask
[0] = 0xffffffff;
2535 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2538 mask
[1] = 0xffffffff;
2542 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2545 mask
[1] = 0xffffffff;
2549 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2554 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2557 #endif /* AF_INET6 */
2562 mask
[0] = 0xffffffff;
2564 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2567 mask
[1] = 0xffffffff;
2571 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2574 mask
[1] = 0xffffffff;
2578 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2583 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2594 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2597 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2600 if ((ip
[0] & ~mask
[0]) != 0 ||
2601 (ip
[1] & ~mask
[1]) != 0 ||
2602 (ip
[2] & ~mask
[2]) != 0 ||
2603 (ip
[3] & ~mask
[3]) != 0)
2611 * 'get_operation()' - Get an IPP opcode from an operation name...
2614 static ipp_op_t
/* O - Operation code or -1 on error */
2615 get_operation(const char *name
) /* I - Operating name */
2617 int i
; /* Looping var */
2618 static const char * const ipp_ops
[] = /* List of standard operations */
2622 /* 0x0002 */ "print-job",
2623 /* 0x0003 */ "print-uri",
2624 /* 0x0004 */ "validate-job",
2625 /* 0x0005 */ "create-job",
2626 /* 0x0006 */ "send-document",
2627 /* 0x0007 */ "send-uri",
2628 /* 0x0008 */ "cancel-job",
2629 /* 0x0009 */ "get-job-attributes",
2630 /* 0x000a */ "get-jobs",
2631 /* 0x000b */ "get-printer-attributes",
2632 /* 0x000c */ "hold-job",
2633 /* 0x000d */ "release-job",
2634 /* 0x000e */ "restart-job",
2636 /* 0x0010 */ "pause-printer",
2637 /* 0x0011 */ "resume-printer",
2638 /* 0x0012 */ "purge-jobs",
2639 /* 0x0013 */ "set-printer-attributes",
2640 /* 0x0014 */ "set-job-attributes",
2641 /* 0x0015 */ "get-printer-supported-values",
2642 /* 0x0016 */ "create-printer-subscription",
2643 /* 0x0017 */ "create-job-subscription",
2644 /* 0x0018 */ "get-subscription-attributes",
2645 /* 0x0019 */ "get-subscriptions",
2646 /* 0x001a */ "renew-subscription",
2647 /* 0x001b */ "cancel-subscription",
2648 /* 0x001c */ "get-notifications",
2649 /* 0x001d */ "send-notifications",
2653 /* 0x0021 */ "get-print-support-files",
2654 /* 0x0022 */ "enable-printer",
2655 /* 0x0023 */ "disable-printer",
2656 /* 0x0024 */ "pause-printer-after-current-job",
2657 /* 0x0025 */ "hold-new-jobs",
2658 /* 0x0026 */ "release-held-new-jobs",
2659 /* 0x0027 */ "deactivate-printer",
2660 /* 0x0028 */ "activate-printer",
2661 /* 0x0029 */ "restart-printer",
2662 /* 0x002a */ "shutdown-printer",
2663 /* 0x002b */ "startup-printer",
2664 /* 0x002c */ "reprocess-job",
2665 /* 0x002d */ "cancel-current-job",
2666 /* 0x002e */ "suspend-current-job",
2667 /* 0x002f */ "resume-job",
2668 /* 0x0030 */ "promote-job",
2669 /* 0x0031 */ "schedule-job-after"
2671 *cups_ops
[] = /* List of CUPS operations */
2673 /* 0x4001 */ "cups-get-default",
2674 /* 0x4002 */ "cups-get-printers",
2675 /* 0x4003 */ "cups-add-printer",
2676 /* 0x4004 */ "cups-delete-printer",
2677 /* 0x4005 */ "cups-get-classes",
2678 /* 0x4006 */ "cups-add-class",
2679 /* 0x4007 */ "cups-delete-class",
2680 /* 0x4008 */ "cups-accept-jobs",
2681 /* 0x4009 */ "cups-reject-jobs",
2682 /* 0x400a */ "cups-set-default",
2683 /* 0x400b */ "cups-get-devices",
2684 /* 0x400c */ "cups-get-ppds",
2685 /* 0x400d */ "cups-move-job",
2686 /* 0x400e */ "cups-add-device",
2687 /* 0x400f */ "cups-delete-device"
2691 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2692 if (!strcasecmp(name
, ipp_ops
[i
]))
2693 return ((ipp_op_t
)i
);
2695 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2696 if (!strcasecmp(name
, cups_ops
[i
]))
2697 return ((ipp_op_t
)(i
+ 0x4001));
2699 return ((ipp_op_t
)-1);
2705 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2706 * required by SSLSetCertificate.
2708 * For now we assumes that there is exactly one SecIdentity in the
2709 * keychain - i.e. there is exactly one matching cert/private key pair.
2710 * In the future we will search a keychain for a SecIdentity matching a
2711 * specific criteria. We also skip the operation of adding additional
2712 * non-signing certs from the keychain to the CFArrayRef.
2714 * To create a self-signed certificate for testing use the certtool.
2715 * Executing the following as root will do it:
2717 * certtool c c v k=CUPS
2721 CDSAGetServerCerts(void)
2723 OSStatus err
; /* Error info */
2724 SecKeychainRef kcRef
; /* Keychain reference */
2725 SecIdentitySearchRef srchRef
; /* Search reference */
2726 SecIdentityRef identity
; /* Identity */
2727 CFArrayRef ca
; /* Certificate array */
2734 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2737 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2738 ServerCertificate
, err
);
2742 * Search for "any" identity matching specified key use;
2743 * in this app, we expect there to be exactly one.
2746 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2750 "Cannot find signing key in keychain \"%s\", error %d",
2751 ServerCertificate
, err
);
2754 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2758 "Cannot find signing key in keychain \"%s\", error %d",
2759 ServerCertificate
, err
);
2762 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2763 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2767 * Found one. Place it in a CFArray.
2768 * TBD: snag other (non-identity) certs from keychain and add them
2772 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2775 LogMessage(L_ERROR
, "CFArrayCreate error");
2778 /*CFRelease(identity);*/
2781 /*CFRelease(srchRef);*/
2784 /*CFRelease(kcRef);*/
2789 #endif /* HAVE_CDSASSL */