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
);
535 chown(temp
, RunUser
, Group
);
538 snprintf(temp
, sizeof(temp
), "%s/ppd", StateDir
);
541 chown(temp
, RunUser
, Group
);
544 chown(ServerRoot
, RunUser
, Group
);
545 chmod(ServerRoot
, 0775);
547 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
550 chown(temp
, RunUser
, Group
);
553 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
556 chown(temp
, RunUser
, Group
);
559 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
560 chown(temp
, RunUser
, Group
);
561 chmod(temp
, ConfigFilePerm
);
563 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
564 chown(temp
, RunUser
, Group
);
568 chmod(temp
, ConfigFilePerm
);
569 #endif /* __APPLE__ */
571 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
572 chown(temp
, RunUser
, Group
);
576 chmod(temp
, ConfigFilePerm
);
577 #endif /* __APPLE__ */
579 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
580 chown(temp
, User
, Group
);
584 * Make sure the request and temporary directories have the right
588 chown(RequestRoot
, RunUser
, Group
);
589 chmod(RequestRoot
, 0710);
591 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
595 * Only update ownership and permissions if the CUPS temp directory
596 * is under the spool directory or does not exist...
599 if (access(TempDir
, 0))
600 mkdir(TempDir
, 01770);
602 chown(TempDir
, RunUser
, Group
);
603 chmod(TempDir
, 01770);
607 * Check the MaxClients setting, and then allocate memory for it...
610 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
613 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
616 MaxClients
= MaxFDs
/ 3;
619 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
621 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
622 MaxClients
, strerror(errno
));
626 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
629 * Check the MaxActiveJobs setting; limit to 1/3 the available
630 * file descriptors, since we need a pipe for each job...
633 if (MaxActiveJobs
> (MaxFDs
/ 3))
634 MaxActiveJobs
= MaxFDs
/ 3;
636 if (Classification
&& strcasecmp(Classification
, "none") == 0)
637 ClearString(&Classification
);
640 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
643 * Update the MaxClientsPerHost value, as needed...
646 if (MaxClientsPerHost
<= 0)
647 MaxClientsPerHost
= MaxClients
;
649 if (MaxClientsPerHost
> MaxClients
)
650 MaxClientsPerHost
= MaxClients
;
652 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
656 * Update the default policy, as needed...
660 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
662 DefaultPolicyPtr
= NULL
;
664 if (!DefaultPolicyPtr
)
666 policy_t
*p
; /* New policy */
667 policyop_t
*po
; /* New policy operation */
668 char groupname
[255]; /* Group name */
672 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
674 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
675 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
678 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
680 DefaultPolicyPtr
= p
= AddPolicy("default");
682 LogMessage(L_INFO
, "<Policy default>");
683 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
684 "Release-Job Restart-Job Purge-Jobs "
685 "Set-Job-Attributes Create-Job-Subscription "
686 "Renew-Subscription Cancel-Subscription "
687 "Get-Notifications Reprocess-Job Cancel-Current-Job "
688 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
689 LogMessage(L_INFO
, "Order Allow,Deny");
690 LogMessage(L_INFO
, "Allow @OWNER");
692 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
693 po
->order_type
= POLICY_DENY
;
695 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
697 for (i
= 0; i
< NumSystemGroups
; i
++)
699 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
700 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
701 LogMessage(L_INFO
, "Allow @%s", groupname
);
704 AddPolicyOp(p
, po
, IPP_SEND_URI
);
705 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
706 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
707 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
708 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
709 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
710 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
711 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
712 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
713 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
714 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
715 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
716 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
717 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
718 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
719 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
721 LogMessage(L_INFO
, "</Limit>");
723 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
724 "Set-Printer-Attributes Enable-Printer "
725 "Disable-Printer Pause-Printer-After-Current-Job "
726 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
727 "Activate-Printer Restart-Printer Shutdown-Printer "
728 "Startup-Printer Promote-Job Schedule-Job-After "
729 "CUPS-Add-Printer CUPS-Delete-Printer "
730 "CUPS-Add-Class CUPS-Delete-Class "
731 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
732 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
733 LogMessage(L_INFO
, "Order Allow,Deny");
734 LogMessage(L_INFO
, "Authenticate yes");
736 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
737 po
->order_type
= POLICY_DENY
;
738 po
->authenticate
= 1;
740 for (i
= 0; i
< NumSystemGroups
; i
++)
742 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
743 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
744 LogMessage(L_INFO
, "Allow @%s", groupname
);
747 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
748 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
749 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
750 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
751 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
752 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
753 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
754 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
755 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
756 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
757 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
758 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
759 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
760 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
761 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
762 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
763 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
764 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
765 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
766 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
767 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
768 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
769 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
771 LogMessage(L_INFO
, "</Limit>");
773 LogMessage(L_INFO
, "<Limit All>");
774 LogMessage(L_INFO
, "Order Deny,Allow");
776 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
777 po
->order_type
= POLICY_ALLOW
;
779 LogMessage(L_INFO
, "</Limit>");
780 LogMessage(L_INFO
, "</Policy>");
785 * If we are doing a full reload or the server root has changed, flush
786 * the jobs, printers, etc. and start from scratch...
789 if (NeedReload
== RELOAD_ALL
||
790 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
791 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
793 LogMessage(L_INFO
, "Full reload is required.");
803 DefaultPrinter
= NULL
;
805 if (MimeDatabase
!= NULL
)
806 mimeDelete(MimeDatabase
);
810 for (i
= 0; i
< NumMimeTypes
; i
++)
811 free((void *)MimeTypes
[i
]);
817 * Read the MIME type and conversion database...
820 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
822 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
824 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
825 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
828 * Create a list of MIME types for the document-format-supported
832 NumMimeTypes
= MimeDatabase
->num_types
;
833 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
836 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
838 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
840 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
841 MimeDatabase
->types
[i
]->type
);
843 MimeTypes
[i
] = strdup(type
);
846 if (i
< NumMimeTypes
)
847 MimeTypes
[i
] = strdup("application/octet-stream");
853 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
857 * Load printers and classes...
866 * Load queued jobs...
871 LogMessage(L_INFO
, "Full reload complete.");
877 LogMessage(L_INFO
, "Partial reload complete.");
881 * Reset the reload state...
884 NeedReload
= RELOAD_NONE
;
886 ClearString(&old_serverroot
);
887 ClearString(&old_requestroot
);
890 * Startup the server and return...
900 * 'read_configuration()' - Read a configuration file.
903 static int /* O - 1 on success, 0 on failure */
904 read_configuration(cups_file_t
*fp
) /* I - File to read from */
906 int i
; /* Looping var */
907 int linenum
; /* Current line number */
908 char line
[HTTP_MAX_BUFFER
], /* Line from file */
909 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
910 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
911 *ptr
, /* Pointer into line/temp */
912 *value
; /* Pointer to value */
913 int valuelen
; /* Length of value */
914 var_t
*var
; /* Current variable */
915 unsigned ip
[4], /* Address value */
916 mask
[4]; /* Netmask value */
917 dirsvc_relay_t
*relay
; /* Relay data */
918 dirsvc_poll_t
*poll
; /* Polling data */
919 http_addr_t polladdr
; /* Polling address */
920 location_t
*location
; /* Browse location */
921 cups_file_t
*incfile
; /* Include file */
922 char incname
[1024]; /* Include filename */
926 * Loop through each line in the file...
931 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
934 * Decode the directive...
937 if (!strcasecmp(line
, "Include"))
944 strlcpy(incname
, value
, sizeof(incname
));
946 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
948 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
949 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
950 incname
, strerror(errno
));
953 read_configuration(incfile
);
954 cupsFileClose(incfile
);
957 else if (!strcasecmp(line
, "<Location"))
965 linenum
= read_location(fp
, value
, linenum
);
971 LogMessage(L_ERROR
, "Syntax error on line %d.",
976 else if (!strcasecmp(line
, "<Policy"))
984 linenum
= read_policy(fp
, value
, linenum
);
990 LogMessage(L_ERROR
, "Syntax error on line %d.",
995 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
998 * Add a listening address to the list...
1001 listener_t
*lis
; /* New listeners array */
1004 if (NumListeners
== 0)
1005 lis
= malloc(sizeof(listener_t
));
1007 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1011 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1012 line
, linenum
, strerror(errno
));
1017 lis
+= NumListeners
;
1019 memset(lis
, 0, sizeof(listener_t
));
1021 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1023 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1026 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1027 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1028 ntohs(lis
->address
.ipv6
.sin6_port
));
1030 #endif /* AF_INET6 */
1031 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1032 ntohs(lis
->address
.ipv4
.sin_port
));
1036 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1040 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1043 * Add a listening address to the list...
1046 listener_t
*lis
; /* New listeners array */
1049 if (NumListeners
== 0)
1050 lis
= malloc(sizeof(listener_t
));
1052 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1056 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1057 line
, linenum
, strerror(errno
));
1062 lis
+= NumListeners
;
1064 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1066 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1069 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1070 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1071 ntohs(lis
->address
.ipv6
.sin6_port
));
1073 #endif /* AF_INET6 */
1074 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1075 ntohs(lis
->address
.ipv4
.sin_port
));
1076 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1080 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1083 #endif /* HAVE_SSL */
1084 else if (!strcasecmp(line
, "BrowseAddress"))
1087 * Add a browse address to the list...
1090 dirsvc_addr_t
*dira
; /* New browse address array */
1093 if (NumBrowsers
== 0)
1094 dira
= malloc(sizeof(dirsvc_addr_t
));
1096 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1100 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1101 linenum
, strerror(errno
));
1106 dira
+= NumBrowsers
;
1108 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1110 if (!strcasecmp(value
, "@LOCAL"))
1113 * Send browse data to all local interfaces...
1116 strcpy(dira
->iface
, "*");
1119 else if (!strncasecmp(value
, "@IF(", 4))
1122 * Send browse data to the named interface...
1125 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1127 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1133 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1135 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1138 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1139 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1140 ntohs(dira
->to
.ipv6
.sin6_port
));
1142 #endif /* AF_INET6 */
1143 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1144 ntohs(dira
->to
.ipv4
.sin_port
));
1149 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1152 else if (!strcasecmp(line
, "BrowseOrder"))
1155 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1158 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1159 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1161 if (location
== NULL
)
1162 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1163 else if (!strncasecmp(value
, "deny", 4))
1164 location
->order_type
= AUTH_ALLOW
;
1165 else if (!strncasecmp(value
, "allow", 5))
1166 location
->order_type
= AUTH_DENY
;
1168 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1171 else if (!strcasecmp(line
, "BrowseProtocols"))
1174 * "BrowseProtocol name [... name]"
1177 BrowseProtocols
= 0;
1181 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1182 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1185 if (value
[valuelen
])
1187 value
[valuelen
] = '\0';
1191 if (!strcasecmp(value
, "cups"))
1192 BrowseProtocols
|= BROWSE_CUPS
;
1193 else if (!strcasecmp(value
, "slp"))
1194 BrowseProtocols
|= BROWSE_SLP
;
1195 else if (!strcasecmp(value
, "ldap"))
1196 BrowseProtocols
|= BROWSE_LDAP
;
1197 else if (!strcasecmp(value
, "all"))
1198 BrowseProtocols
|= BROWSE_ALL
;
1201 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1206 for (value
+= valuelen
; *value
; value
++)
1207 if (!isspace(*value
) || *value
!= ',')
1211 else if (!strcasecmp(line
, "BrowseAllow") ||
1212 !strcasecmp(line
, "BrowseDeny"))
1215 * BrowseAllow [From] host/ip...
1216 * BrowseDeny [From] host/ip...
1219 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1220 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1222 if (location
== NULL
)
1223 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1226 if (!strncasecmp(value
, "from ", 5))
1229 * Strip leading "from"...
1234 while (isspace(*value
))
1239 * Figure out what form the allow/deny address takes:
1250 * nnn.nnn.nnn.nnn/mm
1251 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1254 if (!strcasecmp(value
, "all"))
1260 if (!strcasecmp(line
, "BrowseAllow"))
1261 AllowIP(location
, zeros
, zeros
);
1263 DenyIP(location
, zeros
, zeros
);
1265 else if (!strcasecmp(value
, "none"))
1271 if (!strcasecmp(line
, "BrowseAllow"))
1272 AllowIP(location
, ones
, zeros
);
1274 DenyIP(location
, ones
, zeros
);
1276 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1279 * Host or domain name...
1282 if (value
[0] == '*')
1285 if (!strcasecmp(line
, "BrowseAllow"))
1286 AllowHost(location
, value
);
1288 DenyHost(location
, value
);
1293 * One of many IP address forms...
1296 if (!get_addr_and_mask(value
, ip
, mask
))
1298 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1303 if (!strcasecmp(line
, "BrowseAllow"))
1304 AllowIP(location
, ip
, mask
);
1306 DenyIP(location
, ip
, mask
);
1310 else if (!strcasecmp(line
, "BrowseRelay"))
1313 * BrowseRelay [from] source [to] destination
1317 relay
= malloc(sizeof(dirsvc_relay_t
));
1319 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1323 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1324 linenum
, strerror(errno
));
1331 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1333 if (!strncasecmp(value
, "from ", 5))
1336 * Strip leading "from"...
1341 while (isspace(*value
))
1346 * Figure out what form the from address takes:
1355 * nnn.nnn.nnn.nnn/mm
1356 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1359 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1362 * Host or domain name...
1365 if (value
[0] == '*')
1368 strlcpy(temp
, value
, sizeof(temp
));
1369 if ((ptr
= strchr(temp
, ' ')) != NULL
)
1372 relay
->from
.type
= AUTH_NAME
;
1373 relay
->from
.mask
.name
.name
= strdup(temp
);
1374 relay
->from
.mask
.name
.length
= strlen(temp
);
1379 * One of many IP address forms...
1382 if (!get_addr_and_mask(value
, ip
, mask
))
1384 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1389 relay
->from
.type
= AUTH_IP
;
1390 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1391 sizeof(relay
->from
.mask
.ip
.address
));
1392 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1393 sizeof(relay
->from
.mask
.ip
.netmask
));
1397 * Skip value and trailing whitespace...
1400 for (; *value
; value
++)
1401 if (isspace(*value
))
1404 while (isspace(*value
))
1407 if (!strncasecmp(value
, "to ", 3))
1410 * Strip leading "to"...
1415 while (isspace(*value
))
1420 * Get "to" address and port...
1423 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1425 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
1427 if (relay
->from
.type
== AUTH_IP
)
1428 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
1429 relay
->from
.mask
.ip
.address
[0],
1430 relay
->from
.mask
.ip
.address
[1],
1431 relay
->from
.mask
.ip
.address
[2],
1432 relay
->from
.mask
.ip
.address
[3],
1433 relay
->from
.mask
.ip
.netmask
[0],
1434 relay
->from
.mask
.ip
.netmask
[1],
1435 relay
->from
.mask
.ip
.netmask
[2],
1436 relay
->from
.mask
.ip
.netmask
[3]);
1438 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
1441 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1442 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1443 ntohs(relay
->to
.ipv6
.sin6_port
));
1445 #endif /* AF_INET6 */
1446 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1447 ntohs(relay
->to
.ipv4
.sin_port
));
1453 if (relay
->from
.type
== AUTH_NAME
)
1454 free(relay
->from
.mask
.name
.name
);
1456 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1459 else if (!strcasecmp(line
, "BrowsePoll"))
1462 * BrowsePoll address[:port]
1466 poll
= malloc(sizeof(dirsvc_poll_t
));
1468 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1472 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1473 linenum
, strerror(errno
));
1481 * Get poll address and port...
1484 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1487 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1489 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1492 if (polladdr
.addr
.sa_family
== AF_INET6
)
1493 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1495 #endif /* AF_INET6 */
1496 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1498 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1501 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1503 else if (!strcasecmp(line
, "User"))
1506 * User ID to run as...
1509 if (isdigit(value
[0]))
1513 struct passwd
*p
; /* Password information */
1516 p
= getpwnam(value
);
1521 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
1524 else if (!strcasecmp(line
, "Group"))
1527 * Group ID to run as...
1530 if (isdigit(value
[0]))
1531 Group
= atoi(value
);
1534 struct group
*g
; /* Group information */
1537 g
= getgrnam(value
);
1542 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
1545 else if (!strcasecmp(line
, "SystemGroup"))
1548 * System (admin) group(s)...
1551 char *valueptr
, /* Pointer into value */
1552 quote
; /* Quote character */
1555 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1557 if (*value
== '\'' || *value
== '\"')
1560 * Scan quoted name...
1565 for (valueptr
= value
; *valueptr
; valueptr
++)
1566 if (*valueptr
== quote
)
1572 * Scan space or comma-delimited name...
1575 for (valueptr
= value
; *valueptr
; valueptr
++)
1576 if (isspace(*valueptr
) || *valueptr
== ',')
1583 SetString(SystemGroups
+ i
, value
);
1587 while (*value
== ',' || isspace(*value
))
1592 NumSystemGroups
= i
;
1594 else if (!strcasecmp(line
, "HostNameLookups"))
1597 * Do hostname lookups?
1600 if (!strcasecmp(value
, "off"))
1601 HostNameLookups
= 0;
1602 else if (!strcasecmp(value
, "on"))
1603 HostNameLookups
= 1;
1604 else if (!strcasecmp(value
, "double"))
1605 HostNameLookups
= 2;
1607 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1610 else if (!strcasecmp(line
, "LogLevel"))
1613 * Amount of logging to do...
1616 if (!strcasecmp(value
, "debug2"))
1617 LogLevel
= L_DEBUG2
;
1618 else if (!strcasecmp(value
, "debug"))
1620 else if (!strcasecmp(value
, "info"))
1622 else if (!strcasecmp(value
, "notice"))
1623 LogLevel
= L_NOTICE
;
1624 else if (!strcasecmp(value
, "warn"))
1626 else if (!strcasecmp(value
, "error"))
1628 else if (!strcasecmp(value
, "crit"))
1630 else if (!strcasecmp(value
, "alert"))
1632 else if (!strcasecmp(value
, "emerg"))
1634 else if (!strcasecmp(value
, "none"))
1637 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1639 else if (!strcasecmp(line
, "PrintcapFormat"))
1642 * Format of printcap file?
1645 if (!strcasecmp(value
, "bsd"))
1646 PrintcapFormat
= PRINTCAP_BSD
;
1647 else if (!strcasecmp(value
, "solaris"))
1648 PrintcapFormat
= PRINTCAP_SOLARIS
;
1650 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1653 else if (!strcasecmp(line
, "ServerTokens"))
1656 * Set the string used for the Server header...
1659 struct utsname plat
; /* Platform info */
1664 if (!strcasecmp(value
, "ProductOnly"))
1665 SetString(&ServerHeader
, "CUPS");
1666 else if (!strcasecmp(value
, "Major"))
1667 SetString(&ServerHeader
, "CUPS/1");
1668 else if (!strcasecmp(value
, "Minor"))
1669 SetString(&ServerHeader
, "CUPS/1.1");
1670 else if (!strcasecmp(value
, "Minimal"))
1671 SetString(&ServerHeader
, CUPS_MINIMAL
);
1672 else if (!strcasecmp(value
, "OS"))
1673 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1674 else if (!strcasecmp(value
, "Full"))
1675 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1676 else if (!strcasecmp(value
, "None"))
1677 ClearString(&ServerHeader
);
1679 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1684 * Find a simple variable in the list...
1687 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1688 if (!strcasecmp(line
, var
->name
))
1694 * Unknown directive! Output an error message and continue...
1697 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
1707 char *units
; /* Units */
1710 n
= strtol(value
, &units
, 0);
1712 if (units
&& *units
)
1714 if (tolower(units
[0] & 255) == 'g')
1715 n
*= 1024 * 1024 * 1024;
1716 else if (tolower(units
[0] & 255) == 'm')
1718 else if (tolower(units
[0] & 255) == 'k')
1720 else if (tolower(units
[0] & 255) == 't')
1724 *((int *)var
->ptr
) = n
;
1729 if (!strcasecmp(value
, "true") ||
1730 !strcasecmp(value
, "on") ||
1731 !strcasecmp(value
, "enabled") ||
1732 !strcasecmp(value
, "yes") ||
1734 *((int *)var
->ptr
) = TRUE
;
1735 else if (!strcasecmp(value
, "false") ||
1736 !strcasecmp(value
, "off") ||
1737 !strcasecmp(value
, "disabled") ||
1738 !strcasecmp(value
, "no") ||
1739 !strcasecmp(value
, "0"))
1740 *((int *)var
->ptr
) = FALSE
;
1742 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1747 SetString((char **)var
->ptr
, value
);
1758 * 'read_location()' - Read a <Location path> definition.
1761 static int /* O - New line number or 0 on error */
1762 read_location(cups_file_t
*fp
, /* I - Configuration file */
1763 char *location
, /* I - Location name/path */
1764 int linenum
) /* I - Current line number */
1766 int i
; /* Looping var */
1767 location_t
*loc
, /* New location */
1768 *parent
; /* Parent location */
1769 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1770 *value
, /* Value for directive */
1771 *valptr
; /* Pointer into value */
1772 unsigned ip
[4], /* IP address components */
1773 mask
[4]; /* IP netmask components */
1776 if ((parent
= AddLocation(location
)) == NULL
)
1779 parent
->limit
= AUTH_LIMIT_ALL
;
1782 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1785 * Decode the directive...
1788 if (!strcasecmp(line
, "</Location>"))
1790 else if (!strcasecmp(line
, "<Limit") ||
1791 !strcasecmp(line
, "<LimitExcept"))
1795 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
1799 if ((loc
= CopyLocation(&parent
)) == NULL
)
1805 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1810 if (!strcmp(value
, "ALL"))
1811 loc
->limit
= AUTH_LIMIT_ALL
;
1812 else if (!strcmp(value
, "GET"))
1813 loc
->limit
|= AUTH_LIMIT_GET
;
1814 else if (!strcmp(value
, "HEAD"))
1815 loc
->limit
|= AUTH_LIMIT_HEAD
;
1816 else if (!strcmp(value
, "OPTIONS"))
1817 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1818 else if (!strcmp(value
, "POST"))
1819 loc
->limit
|= AUTH_LIMIT_POST
;
1820 else if (!strcmp(value
, "PUT"))
1821 loc
->limit
|= AUTH_LIMIT_PUT
;
1822 else if (!strcmp(value
, "TRACE"))
1823 loc
->limit
|= AUTH_LIMIT_TRACE
;
1825 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1828 for (value
= valptr
; isspace(*value
& 255); value
++);
1831 if (!strcasecmp(line
, "<LimitExcept"))
1832 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1834 parent
->limit
&= ~loc
->limit
;
1836 else if (!strcasecmp(line
, "</Limit>"))
1838 else if (!strcasecmp(line
, "Encryption"))
1841 * "Encryption xxx" - set required encryption level...
1844 if (!strcasecmp(value
, "never"))
1845 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1846 else if (!strcasecmp(value
, "always"))
1848 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1849 "Using \"required\" instead.", value
, linenum
);
1851 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1853 else if (!strcasecmp(value
, "required"))
1854 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1855 else if (!strcasecmp(value
, "ifrequested"))
1856 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1858 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1861 else if (!strcasecmp(line
, "Order"))
1864 * "Order Deny,Allow" or "Order Allow,Deny"...
1867 if (!strncasecmp(value
, "deny", 4))
1868 loc
->order_type
= AUTH_ALLOW
;
1869 else if (!strncasecmp(value
, "allow", 5))
1870 loc
->order_type
= AUTH_DENY
;
1872 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1875 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1878 * Allow [From] host/ip...
1879 * Deny [From] host/ip...
1882 if (!strncasecmp(value
, "from", 4))
1885 * Strip leading "from"...
1890 while (isspace(*value
& 255))
1895 * Figure out what form the allow/deny address takes:
1906 * nnn.nnn.nnn.nnn/mm
1907 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1910 if (!strcasecmp(value
, "all"))
1916 if (!strcasecmp(line
, "Allow"))
1917 AllowIP(loc
, zeros
, zeros
);
1919 DenyIP(loc
, zeros
, zeros
);
1921 else if (!strcasecmp(value
, "none"))
1927 if (!strcasecmp(line
, "Allow"))
1928 AllowIP(loc
, ones
, zeros
);
1930 DenyIP(loc
, ones
, zeros
);
1932 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1935 * Host or domain name...
1938 if (value
[0] == '*')
1941 if (!strcasecmp(line
, "Allow"))
1942 AllowHost(loc
, value
);
1944 DenyHost(loc
, value
);
1949 * One of many IP address forms...
1952 if (!get_addr_and_mask(value
, ip
, mask
))
1954 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1959 if (!strcasecmp(line
, "Allow"))
1960 AllowIP(loc
, ip
, mask
);
1962 DenyIP(loc
, ip
, mask
);
1965 else if (!strcasecmp(line
, "AuthType"))
1968 * AuthType {none,basic,digest,basicdigest}
1971 if (!strcasecmp(value
, "none"))
1973 loc
->type
= AUTH_NONE
;
1974 loc
->level
= AUTH_ANON
;
1976 else if (!strcasecmp(value
, "basic"))
1978 loc
->type
= AUTH_BASIC
;
1980 if (loc
->level
== AUTH_ANON
)
1981 loc
->level
= AUTH_USER
;
1983 else if (!strcasecmp(value
, "digest"))
1985 loc
->type
= AUTH_DIGEST
;
1987 if (loc
->level
== AUTH_ANON
)
1988 loc
->level
= AUTH_USER
;
1990 else if (!strcasecmp(value
, "basicdigest"))
1992 loc
->type
= AUTH_BASICDIGEST
;
1994 if (loc
->level
== AUTH_ANON
)
1995 loc
->level
= AUTH_USER
;
1998 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2001 else if (!strcasecmp(line
, "AuthClass"))
2004 * AuthClass anonymous, user, system, group
2007 if (!strcasecmp(value
, "anonymous"))
2009 loc
->type
= AUTH_NONE
;
2010 loc
->level
= AUTH_ANON
;
2012 else if (!strcasecmp(value
, "user"))
2013 loc
->level
= AUTH_USER
;
2014 else if (!strcasecmp(value
, "group"))
2015 loc
->level
= AUTH_GROUP
;
2016 else if (!strcasecmp(value
, "system"))
2018 loc
->level
= AUTH_GROUP
;
2021 * Use the default system group if none is defined so far...
2024 if (NumSystemGroups
)
2025 NumSystemGroups
= 1;
2027 for (i
= 0; i
< NumSystemGroups
; i
++)
2028 AddName(loc
, SystemGroups
[i
]);
2031 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2034 else if (!strcasecmp(line
, "AuthGroupName"))
2035 AddName(loc
, value
);
2036 else if (!strcasecmp(line
, "Require"))
2039 * Apache synonym for AuthClass and AuthGroupName...
2043 * Require valid-user
2044 * Require group names
2045 * Require user names
2048 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2053 if (!strcasecmp(value
, "valid-user") ||
2054 !strcasecmp(value
, "user"))
2055 loc
->level
= AUTH_USER
;
2056 else if (!strcasecmp(value
, "group"))
2057 loc
->level
= AUTH_GROUP
;
2060 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2066 * Get the list of names from the line...
2069 for (value
= valptr
; *value
;)
2071 while (isspace(*value
& 255))
2074 if (*value
== '\"' || *value
== '\'')
2077 * Grab quoted name...
2080 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2087 * Grab literal name.
2090 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2096 AddName(loc
, value
);
2098 for (value
= valptr
; isspace(*value
& 255); value
++);
2101 else if (!strcasecmp(line
, "Satisfy"))
2103 if (!strcasecmp(value
, "all"))
2104 loc
->satisfy
= AUTH_SATISFY_ALL
;
2105 else if (!strcasecmp(value
, "any"))
2106 loc
->satisfy
= AUTH_SATISFY_ANY
;
2108 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2112 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2116 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2124 * 'read_policy()' - Read a <Policy name> definition.
2127 static int /* O - New line number or 0 on error */
2128 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2129 char *policy
, /* I - Location name/path */
2130 int linenum
) /* I - Current line number */
2132 int i
; /* Looping var */
2133 policy_t
*pol
; /* Policy */
2134 policyop_t
*op
; /* Policy operation */
2135 int num_ops
; /* Number of IPP operations */
2136 ipp_op_t ops
[100]; /* Operations */
2137 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2138 *value
, /* Value for directive */
2139 *valptr
; /* Pointer into value */
2143 * Create the policy...
2146 if ((pol
= AddPolicy(policy
)) == NULL
)
2150 * Read from the file...
2156 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2159 * Decode the directive...
2162 if (!strcasecmp(line
, "</Policy>"))
2165 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2170 else if (!strcasecmp(line
, "<Limit") && !op
)
2174 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2179 * Scan for IPP operation names...
2186 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2191 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2193 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2194 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2200 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2203 for (value
= valptr
; isspace(*value
& 255); value
++);
2207 * If none are specified, apply the policy to all operations...
2212 ops
[0] = IPP_ANY_OPERATION
;
2217 * Add a new policy for the first operation...
2220 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2222 else if (!strcasecmp(line
, "</Limit>") && op
)
2225 * Finish the current operation limit...
2231 * Copy the policy to the other operations...
2234 for (i
= 1; i
< num_ops
; i
++)
2235 AddPolicyOp(pol
, op
, ops
[i
]);
2240 else if (!strcasecmp(line
, "Authenticate") && op
)
2243 * Authenticate boolean
2246 if (!strcasecmp(value
, "on") ||
2247 !strcasecmp(value
, "yes") ||
2248 !strcasecmp(value
, "true"))
2249 op
->authenticate
= 1;
2250 else if (!strcasecmp(value
, "off") ||
2251 !strcasecmp(value
, "no") ||
2252 !strcasecmp(value
, "false"))
2253 op
->authenticate
= 0;
2255 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2258 else if (!strcasecmp(line
, "Order") && op
)
2261 * "Order Deny,Allow" or "Order Allow,Deny"...
2264 if (!strncasecmp(value
, "deny", 4))
2265 op
->order_type
= POLICY_ALLOW
;
2266 else if (!strncasecmp(value
, "allow", 5))
2267 op
->order_type
= POLICY_DENY
;
2269 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2272 else if ((!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny")) && op
)
2275 * Allow line, @group, @OWNER
2276 * Deny line, @group, @OWNER
2281 while (isspace(*value
& 255))
2284 if (*value
== '\"' || *value
== '\'')
2287 * Grab quoted name...
2290 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2297 * Grab literal name.
2300 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2306 if (!strcasecmp(line
, "Allow"))
2307 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2309 AddPolicyOpName(op
, POLICY_DENY
, value
);
2311 for (value
= valptr
; isspace(*value
& 255); value
++);
2315 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2318 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2322 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2330 * 'get_address()' - Get an address + port number from a line.
2333 static int /* O - 1 if address good, 0 if bad */
2334 get_address(const char *value
, /* I - Value string */
2335 unsigned defaddress
, /* I - Default address */
2336 int defport
, /* I - Default port */
2337 int deffamily
, /* I - Default family */
2338 http_addr_t
*address
) /* O - Socket address */
2340 char hostname
[256], /* Hostname or IP */
2341 portname
[256]; /* Port number or name */
2342 struct hostent
*host
; /* Host address */
2343 struct servent
*port
; /* Port number */
2347 * Initialize the socket address to the defaults...
2350 memset(address
, 0, sizeof(http_addr_t
));
2353 if (deffamily
== AF_INET6
)
2355 address
->ipv6
.sin6_family
= AF_INET6
;
2356 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2357 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2358 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2359 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2360 address
->ipv6
.sin6_port
= htons(defport
);
2363 #endif /* AF_INET6 */
2365 address
->ipv4
.sin_family
= AF_INET
;
2366 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2367 address
->ipv4
.sin_port
= htons(defport
);
2372 * If the address starts with a "/", it is a domain socket...
2377 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2379 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2383 address
->un
.sun_family
= AF_LOCAL
;
2384 strcpy(address
->un
.sun_path
, value
);
2388 #endif /* AF_LOCAL */
2391 * Try to grab a hostname and port number...
2394 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2397 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2400 * Hostname is a port number...
2403 strlcpy(portname
, hostname
, sizeof(portname
));
2414 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2419 * Decode the hostname and port number as needed...
2422 if (hostname
[0] && strcmp(hostname
, "*"))
2424 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2426 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2427 hstrerror(h_errno
));
2431 httpAddrLoad(host
, defport
, 0, address
);
2434 if (portname
[0] != '\0')
2436 if (isdigit(portname
[0] & 255))
2439 if (address
->addr
.sa_family
== AF_INET6
)
2440 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2442 #endif /* AF_INET6 */
2443 address
->ipv4
.sin_port
= htons(atoi(portname
));
2447 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2449 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2456 if (address
->addr
.sa_family
== AF_INET6
)
2457 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2459 #endif /* AF_INET6 */
2460 address
->ipv4
.sin_port
= htons(port
->s_port
);
2470 * 'get_addr_and_mask()' - Get an IP address and netmask.
2473 static int /* O - 1 on success, 0 on failure */
2474 get_addr_and_mask(const char *value
, /* I - String from config file */
2475 unsigned *ip
, /* O - Address value */
2476 unsigned *mask
) /* O - Mask value */
2478 int i
, /* Looping var */
2479 family
, /* Address family */
2480 ipcount
; /* Count of fields in address */
2481 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2483 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2484 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2485 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2486 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2491 * Get the address...
2494 memset(ip
, 0, sizeof(unsigned) * 4);
2496 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2500 * See if we have any values > 255; if so, this is an IPv6 address only.
2503 for (i
= 0; i
< ipcount
; i
++)
2509 #endif /* AF_INET6 */
2511 if ((value
= strchr(value
, '/')) != NULL
)
2514 * Get the netmask value(s)...
2518 memset(mask
, 0, sizeof(unsigned) * 4);
2519 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2520 mask
+ 2, mask
+ 3))
2527 if (family
== AF_INET6
)
2532 mask
[0] = 0xffffffff;
2534 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2537 mask
[1] = 0xffffffff;
2541 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2544 mask
[1] = 0xffffffff;
2548 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2553 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2556 #endif /* AF_INET6 */
2561 mask
[0] = 0xffffffff;
2563 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2566 mask
[1] = 0xffffffff;
2570 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2573 mask
[1] = 0xffffffff;
2577 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2582 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2593 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2596 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2599 if ((ip
[0] & ~mask
[0]) != 0 ||
2600 (ip
[1] & ~mask
[1]) != 0 ||
2601 (ip
[2] & ~mask
[2]) != 0 ||
2602 (ip
[3] & ~mask
[3]) != 0)
2610 * 'get_operation()' - Get an IPP opcode from an operation name...
2613 static ipp_op_t
/* O - Operation code or -1 on error */
2614 get_operation(const char *name
) /* I - Operating name */
2616 int i
; /* Looping var */
2617 static const char * const ipp_ops
[] = /* List of standard operations */
2621 /* 0x0002 */ "print-job",
2622 /* 0x0003 */ "print-uri",
2623 /* 0x0004 */ "validate-job",
2624 /* 0x0005 */ "create-job",
2625 /* 0x0006 */ "send-document",
2626 /* 0x0007 */ "send-uri",
2627 /* 0x0008 */ "cancel-job",
2628 /* 0x0009 */ "get-job-attributes",
2629 /* 0x000a */ "get-jobs",
2630 /* 0x000b */ "get-printer-attributes",
2631 /* 0x000c */ "hold-job",
2632 /* 0x000d */ "release-job",
2633 /* 0x000e */ "restart-job",
2635 /* 0x0010 */ "pause-printer",
2636 /* 0x0011 */ "resume-printer",
2637 /* 0x0012 */ "purge-jobs",
2638 /* 0x0013 */ "set-printer-attributes",
2639 /* 0x0014 */ "set-job-attributes",
2640 /* 0x0015 */ "get-printer-supported-values",
2641 /* 0x0016 */ "create-printer-subscription",
2642 /* 0x0017 */ "create-job-subscription",
2643 /* 0x0018 */ "get-subscription-attributes",
2644 /* 0x0019 */ "get-subscriptions",
2645 /* 0x001a */ "renew-subscription",
2646 /* 0x001b */ "cancel-subscription",
2647 /* 0x001c */ "get-notifications",
2648 /* 0x001d */ "send-notifications",
2652 /* 0x0021 */ "get-print-support-files",
2653 /* 0x0022 */ "enable-printer",
2654 /* 0x0023 */ "disable-printer",
2655 /* 0x0024 */ "pause-printer-after-current-job",
2656 /* 0x0025 */ "hold-new-jobs",
2657 /* 0x0026 */ "release-held-new-jobs",
2658 /* 0x0027 */ "deactivate-printer",
2659 /* 0x0028 */ "activate-printer",
2660 /* 0x0029 */ "restart-printer",
2661 /* 0x002a */ "shutdown-printer",
2662 /* 0x002b */ "startup-printer",
2663 /* 0x002c */ "reprocess-job",
2664 /* 0x002d */ "cancel-current-job",
2665 /* 0x002e */ "suspend-current-job",
2666 /* 0x002f */ "resume-job",
2667 /* 0x0030 */ "promote-job",
2668 /* 0x0031 */ "schedule-job-after"
2670 *cups_ops
[] = /* List of CUPS operations */
2672 /* 0x4001 */ "cups-get-default",
2673 /* 0x4002 */ "cups-get-printers",
2674 /* 0x4003 */ "cups-add-printer",
2675 /* 0x4004 */ "cups-delete-printer",
2676 /* 0x4005 */ "cups-get-classes",
2677 /* 0x4006 */ "cups-add-class",
2678 /* 0x4007 */ "cups-delete-class",
2679 /* 0x4008 */ "cups-accept-jobs",
2680 /* 0x4009 */ "cups-reject-jobs",
2681 /* 0x400a */ "cups-set-default",
2682 /* 0x400b */ "cups-get-devices",
2683 /* 0x400c */ "cups-get-ppds",
2684 /* 0x400d */ "cups-move-job",
2685 /* 0x400e */ "cups-add-device",
2686 /* 0x400f */ "cups-delete-device"
2690 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2691 if (!strcasecmp(name
, ipp_ops
[i
]))
2692 return ((ipp_op_t
)i
);
2694 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2695 if (!strcasecmp(name
, cups_ops
[i
]))
2696 return ((ipp_op_t
)(i
+ 0x4001));
2698 return ((ipp_op_t
)-1);
2704 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2705 * required by SSLSetCertificate.
2707 * For now we assumes that there is exactly one SecIdentity in the
2708 * keychain - i.e. there is exactly one matching cert/private key pair.
2709 * In the future we will search a keychain for a SecIdentity matching a
2710 * specific criteria. We also skip the operation of adding additional
2711 * non-signing certs from the keychain to the CFArrayRef.
2713 * To create a self-signed certificate for testing use the certtool.
2714 * Executing the following as root will do it:
2716 * certtool c c v k=CUPS
2720 CDSAGetServerCerts(void)
2722 OSStatus err
; /* Error info */
2723 SecKeychainRef kcRef
; /* Keychain reference */
2724 SecIdentitySearchRef srchRef
; /* Search reference */
2725 SecIdentityRef identity
; /* Identity */
2726 CFArrayRef ca
; /* Certificate array */
2733 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2736 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2737 ServerCertificate
, err
);
2741 * Search for "any" identity matching specified key use;
2742 * in this app, we expect there to be exactly one.
2745 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2749 "Cannot find signing key in keychain \"%s\", error %d",
2750 ServerCertificate
, err
);
2753 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2757 "Cannot find signing key in keychain \"%s\", error %d",
2758 ServerCertificate
, err
);
2761 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2762 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2766 * Found one. Place it in a CFArray.
2767 * TBD: snag other (non-identity) certs from keychain and add them
2771 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2774 LogMessage(L_ERROR
, "CFArrayCreate error");
2777 /*CFRelease(identity);*/
2780 /*CFRelease(srchRef);*/
2783 /*CFRelease(kcRef);*/
2788 #endif /* HAVE_CDSASSL */