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
= mimeNew();
814 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
817 * Create a list of MIME types for the document-format-supported
821 NumMimeTypes
= MimeDatabase
->num_types
;
822 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
825 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
827 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
829 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
830 MimeDatabase
->types
[i
]->type
);
832 MimeTypes
[i
] = strdup(type
);
835 if (i
< NumMimeTypes
)
836 MimeTypes
[i
] = strdup("application/octet-stream");
842 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
846 * Load printers and classes...
855 * Load devices and PPDs...
858 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
861 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
865 * Load queued jobs...
870 LogMessage(L_INFO
, "Full reload complete.");
876 LogMessage(L_INFO
, "Partial reload complete.");
880 * Reset the reload state...
883 NeedReload
= RELOAD_NONE
;
885 ClearString(&old_serverroot
);
886 ClearString(&old_requestroot
);
889 * Startup the server and return...
899 * 'read_configuration()' - Read a configuration file.
902 static int /* O - 1 on success, 0 on failure */
903 read_configuration(cups_file_t
*fp
) /* I - File to read from */
905 int i
; /* Looping var */
906 int linenum
; /* Current line number */
907 int len
; /* Length of line */
908 char line
[HTTP_MAX_BUFFER
], /* Line from file */
909 name
[256], /* Parameter name */
910 *nameptr
, /* Pointer into name */
911 *value
; /* Pointer to value */
912 int valuelen
; /* Length of value */
913 var_t
*var
; /* Current variable */
914 unsigned ip
[4], /* Address value */
915 mask
[4]; /* Netmask value */
916 dirsvc_relay_t
*relay
; /* Relay data */
917 dirsvc_poll_t
*poll
; /* Polling data */
918 http_addr_t polladdr
; /* Polling address */
919 location_t
*location
; /* Browse location */
920 cups_file_t
*incfile
; /* Include file */
921 char incname
[1024]; /* Include filename */
925 * Loop through each line in the file...
930 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
935 * Skip comment lines...
942 * Strip trailing whitespace, if any...
947 while (len
> 0 && isspace(line
[len
- 1]))
954 * Extract the name from the beginning of the line...
957 for (value
= line
; isspace(*value
); value
++);
959 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
960 nameptr
< (name
+ sizeof(name
) - 1);)
961 *nameptr
++ = *value
++;
964 while (isspace(*value
))
971 * Decode the directive...
974 if (strcasecmp(name
, "Include") == 0)
981 strlcpy(incname
, value
, sizeof(incname
));
983 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
985 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
986 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
987 incname
, strerror(errno
));
990 read_configuration(incfile
);
991 cupsFileClose(incfile
);
994 else if (strcasecmp(name
, "<Location") == 0)
1000 if (line
[len
- 1] == '>')
1002 line
[len
- 1] = '\0';
1004 linenum
= read_location(fp
, value
, linenum
);
1010 LogMessage(L_ERROR
, "Syntax error on line %d.",
1015 else if (!strcasecmp(name
, "<Policy"))
1021 if (line
[len
- 1] == '>')
1023 line
[len
- 1] = '\0';
1025 linenum
= read_policy(fp
, value
, linenum
);
1031 LogMessage(L_ERROR
, "Syntax error on line %d.",
1036 else if (strcasecmp(name
, "Port") == 0 ||
1037 strcasecmp(name
, "Listen") == 0)
1040 * Add a listening address to the list...
1043 listener_t
*temp
; /* New listeners array */
1046 if (NumListeners
== 0)
1047 temp
= malloc(sizeof(listener_t
));
1049 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1053 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1054 name
, linenum
, strerror(errno
));
1059 temp
+= NumListeners
;
1061 memset(temp
, 0, sizeof(listener_t
));
1063 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
1065 httpAddrString(&(temp
->address
), line
, sizeof(line
));
1068 if (temp
->address
.addr
.sa_family
== AF_INET6
)
1069 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
1070 ntohs(temp
->address
.ipv6
.sin6_port
));
1072 #endif /* AF_INET6 */
1073 LogMessage(L_INFO
, "Listening to %s:%d", line
,
1074 ntohs(temp
->address
.ipv4
.sin_port
));
1078 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
1082 else if (strcasecmp(name
, "SSLPort") == 0 ||
1083 strcasecmp(name
, "SSLListen") == 0)
1086 * Add a listening address to the list...
1089 listener_t
*temp
; /* New listeners array */
1092 if (NumListeners
== 0)
1093 temp
= malloc(sizeof(listener_t
));
1095 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1099 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1100 name
, linenum
, strerror(errno
));
1105 temp
+= NumListeners
;
1107 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
1109 httpAddrString(&(temp
->address
), line
, sizeof(line
));
1112 if (temp
->address
.addr
.sa_family
== AF_INET6
)
1113 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
1114 ntohs(temp
->address
.ipv6
.sin6_port
));
1116 #endif /* AF_INET6 */
1117 LogMessage(L_INFO
, "Listening to %s:%d", line
,
1118 ntohs(temp
->address
.ipv4
.sin_port
));
1119 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1123 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
1126 #endif /* HAVE_SSL */
1127 else if (strcasecmp(name
, "BrowseAddress") == 0)
1130 * Add a browse address to the list...
1133 dirsvc_addr_t
*temp
; /* New browse address array */
1136 if (NumBrowsers
== 0)
1137 temp
= malloc(sizeof(dirsvc_addr_t
));
1139 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1143 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1144 linenum
, strerror(errno
));
1149 temp
+= NumBrowsers
;
1151 memset(temp
, 0, sizeof(dirsvc_addr_t
));
1153 if (strcasecmp(value
, "@LOCAL") == 0)
1156 * Send browse data to all local interfaces...
1159 strcpy(temp
->iface
, "*");
1162 else if (strncasecmp(value
, "@IF(", 4) == 0)
1165 * Send browse data to the named interface...
1168 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1170 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
1171 if (*nameptr
== ')')
1176 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(temp
->to
)))
1178 httpAddrString(&(temp
->to
), line
, sizeof(line
));
1181 if (temp
->to
.addr
.sa_family
== AF_INET6
)
1182 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", line
,
1183 ntohs(temp
->to
.ipv6
.sin6_port
));
1185 #endif /* AF_INET6 */
1186 LogMessage(L_INFO
, "Sending browsing info to %s:%d", line
,
1187 ntohs(temp
->to
.ipv4
.sin_port
));
1192 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1195 else if (strcasecmp(name
, "BrowseOrder") == 0)
1198 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1201 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1202 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1204 if (location
== NULL
)
1205 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1206 else if (strncasecmp(value
, "deny", 4) == 0)
1207 location
->order_type
= AUTH_ALLOW
;
1208 else if (strncasecmp(value
, "allow", 5) == 0)
1209 location
->order_type
= AUTH_DENY
;
1211 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1214 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1217 * "BrowseProtocol name [... name]"
1220 BrowseProtocols
= 0;
1224 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1225 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1228 if (value
[valuelen
])
1230 value
[valuelen
] = '\0';
1234 if (strcasecmp(value
, "cups") == 0)
1235 BrowseProtocols
|= BROWSE_CUPS
;
1236 else if (strcasecmp(value
, "slp") == 0)
1237 BrowseProtocols
|= BROWSE_SLP
;
1238 else if (strcasecmp(value
, "ldap") == 0)
1239 BrowseProtocols
|= BROWSE_LDAP
;
1240 else if (strcasecmp(value
, "all") == 0)
1241 BrowseProtocols
|= BROWSE_ALL
;
1244 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1249 for (value
+= valuelen
; *value
; value
++)
1250 if (!isspace(*value
) || *value
!= ',')
1254 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1255 strcasecmp(name
, "BrowseDeny") == 0)
1258 * BrowseAllow [From] host/ip...
1259 * BrowseDeny [From] host/ip...
1262 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1263 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1265 if (location
== NULL
)
1266 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1269 if (strncasecmp(value
, "from ", 5) == 0)
1272 * Strip leading "from"...
1277 while (isspace(*value
))
1282 * Figure out what form the allow/deny address takes:
1293 * nnn.nnn.nnn.nnn/mm
1294 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1297 if (strcasecmp(value
, "all") == 0)
1303 if (strcasecmp(name
, "BrowseAllow") == 0)
1304 AllowIP(location
, zeros
, zeros
);
1306 DenyIP(location
, zeros
, zeros
);
1308 else if (strcasecmp(value
, "none") == 0)
1314 if (strcasecmp(name
, "BrowseAllow") == 0)
1315 AllowIP(location
, ones
, zeros
);
1317 DenyIP(location
, ones
, zeros
);
1319 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1322 * Host or domain name...
1325 if (value
[0] == '*')
1328 if (strcasecmp(name
, "BrowseAllow") == 0)
1329 AllowHost(location
, value
);
1331 DenyHost(location
, value
);
1336 * One of many IP address forms...
1339 if (!get_addr_and_mask(value
, ip
, mask
))
1341 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1346 if (strcasecmp(name
, "BrowseAllow") == 0)
1347 AllowIP(location
, ip
, mask
);
1349 DenyIP(location
, ip
, mask
);
1353 else if (strcasecmp(name
, "BrowseRelay") == 0)
1356 * BrowseRelay [from] source [to] destination
1360 relay
= malloc(sizeof(dirsvc_relay_t
));
1362 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1366 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1367 linenum
, strerror(errno
));
1374 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1376 if (strncasecmp(value
, "from ", 5) == 0)
1379 * Strip leading "from"...
1384 while (isspace(*value
))
1389 * Figure out what form the from address takes:
1398 * nnn.nnn.nnn.nnn/mm
1399 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1402 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1405 * Host or domain name...
1408 if (value
[0] == '*')
1411 strlcpy(name
, value
, sizeof(name
));
1412 if ((nameptr
= strchr(name
, ' ')) != NULL
)
1415 relay
->from
.type
= AUTH_NAME
;
1416 relay
->from
.mask
.name
.name
= strdup(name
);
1417 relay
->from
.mask
.name
.length
= strlen(name
);
1422 * One of many IP address forms...
1425 if (!get_addr_and_mask(value
, ip
, mask
))
1427 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1432 relay
->from
.type
= AUTH_IP
;
1433 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1434 sizeof(relay
->from
.mask
.ip
.address
));
1435 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1436 sizeof(relay
->from
.mask
.ip
.netmask
));
1440 * Skip value and trailing whitespace...
1443 for (; *value
; value
++)
1444 if (isspace(*value
))
1447 while (isspace(*value
))
1450 if (strncasecmp(value
, "to ", 3) == 0)
1453 * Strip leading "to"...
1458 while (isspace(*value
))
1463 * Get "to" address and port...
1466 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1468 httpAddrString(&(relay
->to
), line
, sizeof(line
));
1470 if (relay
->from
.type
== AUTH_IP
)
1471 snprintf(name
, sizeof(name
), "%u.%u.%u.%u/%u.%u.%u.%u",
1472 relay
->from
.mask
.ip
.address
[0],
1473 relay
->from
.mask
.ip
.address
[1],
1474 relay
->from
.mask
.ip
.address
[2],
1475 relay
->from
.mask
.ip
.address
[3],
1476 relay
->from
.mask
.ip
.netmask
[0],
1477 relay
->from
.mask
.ip
.netmask
[1],
1478 relay
->from
.mask
.ip
.netmask
[2],
1479 relay
->from
.mask
.ip
.netmask
[3]);
1482 strncpy(name
, relay
->from
.mask
.name
.name
, sizeof(name
) - 1);
1483 name
[sizeof(name
) - 1] = '\0';
1487 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1488 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1489 ntohs(relay
->to
.ipv6
.sin6_port
));
1491 #endif /* AF_INET6 */
1492 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1493 ntohs(relay
->to
.ipv4
.sin_port
));
1499 if (relay
->from
.type
== AUTH_NAME
)
1500 free(relay
->from
.mask
.name
.name
);
1502 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1505 else if (strcasecmp(name
, "BrowsePoll") == 0)
1508 * BrowsePoll address[:port]
1512 poll
= malloc(sizeof(dirsvc_poll_t
));
1514 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1518 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1519 linenum
, strerror(errno
));
1527 * Get poll address and port...
1530 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1533 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1535 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1538 if (polladdr
.addr
.sa_family
== AF_INET6
)
1539 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1541 #endif /* AF_INET6 */
1542 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1544 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1547 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1549 else if (strcasecmp(name
, "User") == 0)
1552 * User ID to run as...
1555 if (isdigit(value
[0]))
1559 struct passwd
*p
; /* Password information */
1562 p
= getpwnam(value
);
1567 LogMessage(L_WARN
, "Unknown username \"%s\"",
1571 else if (strcasecmp(name
, "Group") == 0)
1574 * Group ID to run as...
1577 if (isdigit(value
[0]))
1578 Group
= atoi(value
);
1581 struct group
*g
; /* Group information */
1584 g
= getgrnam(value
);
1589 LogMessage(L_WARN
, "Unknown groupname \"%s\"",
1593 else if (strcasecmp(name
, "SystemGroup") == 0)
1596 * System (admin) group(s)...
1599 char *valueptr
, /* Pointer into value */
1600 quote
; /* Quote character */
1603 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1605 if (*value
== '\'' || *value
== '\"')
1608 * Scan quoted name...
1613 for (valueptr
= value
; *valueptr
; valueptr
++)
1614 if (*valueptr
== quote
)
1620 * Scan space or comma-delimited name...
1623 for (valueptr
= value
; *valueptr
; valueptr
++)
1624 if (isspace(*valueptr
) || *valueptr
== ',')
1631 SetString(SystemGroups
+ i
, value
);
1635 while (*value
== ',' || isspace(*value
))
1640 NumSystemGroups
= i
;
1642 else if (strcasecmp(name
, "HostNameLookups") == 0)
1645 * Do hostname lookups?
1648 if (strcasecmp(value
, "off") == 0)
1649 HostNameLookups
= 0;
1650 else if (strcasecmp(value
, "on") == 0)
1651 HostNameLookups
= 1;
1652 else if (strcasecmp(value
, "double") == 0)
1653 HostNameLookups
= 2;
1655 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1658 else if (strcasecmp(name
, "LogLevel") == 0)
1661 * Amount of logging to do...
1664 if (strcasecmp(value
, "debug2") == 0)
1665 LogLevel
= L_DEBUG2
;
1666 else if (strcasecmp(value
, "debug") == 0)
1668 else if (strcasecmp(value
, "info") == 0)
1670 else if (strcasecmp(value
, "notice") == 0)
1671 LogLevel
= L_NOTICE
;
1672 else if (strcasecmp(value
, "warn") == 0)
1674 else if (strcasecmp(value
, "error") == 0)
1676 else if (strcasecmp(value
, "crit") == 0)
1678 else if (strcasecmp(value
, "alert") == 0)
1680 else if (strcasecmp(value
, "emerg") == 0)
1682 else if (strcasecmp(value
, "none") == 0)
1685 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1687 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1690 * Format of printcap file?
1693 if (strcasecmp(value
, "bsd") == 0)
1694 PrintcapFormat
= PRINTCAP_BSD
;
1695 else if (strcasecmp(value
, "solaris") == 0)
1696 PrintcapFormat
= PRINTCAP_SOLARIS
;
1698 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1701 else if (!strcasecmp(name
, "ServerTokens"))
1704 * Set the string used for the Server header...
1707 struct utsname plat
; /* Platform info */
1712 if (!strcasecmp(value
, "ProductOnly"))
1713 SetString(&ServerHeader
, "CUPS");
1714 else if (!strcasecmp(value
, "Major"))
1715 SetString(&ServerHeader
, "CUPS/1");
1716 else if (!strcasecmp(value
, "Minor"))
1717 SetString(&ServerHeader
, "CUPS/1.1");
1718 else if (!strcasecmp(value
, "Minimal"))
1719 SetString(&ServerHeader
, CUPS_MINIMAL
);
1720 else if (!strcasecmp(value
, "OS"))
1721 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1722 else if (!strcasecmp(value
, "Full"))
1723 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1724 else if (!strcasecmp(value
, "None"))
1725 ClearString(&ServerHeader
);
1727 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1732 * Find a simple variable in the list...
1735 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1736 if (strcasecmp(name
, var
->name
) == 0)
1742 * Unknown directive! Output an error message and continue...
1745 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1755 char *units
; /* Units */
1758 n
= strtol(value
, &units
, 0);
1760 if (units
&& *units
)
1762 if (tolower(units
[0] & 255) == 'g')
1763 n
*= 1024 * 1024 * 1024;
1764 else if (tolower(units
[0] & 255) == 'm')
1766 else if (tolower(units
[0] & 255) == 'k')
1768 else if (tolower(units
[0] & 255) == 't')
1772 *((int *)var
->ptr
) = n
;
1777 if (strcasecmp(value
, "true") == 0 ||
1778 strcasecmp(value
, "on") == 0 ||
1779 strcasecmp(value
, "enabled") == 0 ||
1780 strcasecmp(value
, "yes") == 0 ||
1782 *((int *)var
->ptr
) = TRUE
;
1783 else if (strcasecmp(value
, "false") == 0 ||
1784 strcasecmp(value
, "off") == 0 ||
1785 strcasecmp(value
, "disabled") == 0 ||
1786 strcasecmp(value
, "no") == 0 ||
1787 strcasecmp(value
, "0") == 0)
1788 *((int *)var
->ptr
) = FALSE
;
1790 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1795 SetString((char **)var
->ptr
, value
);
1806 * 'read_location()' - Read a <Location path> definition.
1809 static int /* O - New line number or 0 on error */
1810 read_location(cups_file_t
*fp
, /* I - Configuration file */
1811 char *location
, /* I - Location name/path */
1812 int linenum
) /* I - Current line number */
1814 int i
; /* Looping var */
1815 location_t
*loc
, /* New location */
1816 *parent
; /* Parent location */
1817 int len
; /* Length of line */
1818 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1819 name
[256], /* Configuration directive */
1820 *nameptr
, /* Pointer into name */
1821 *value
, /* Value for directive */
1822 *valptr
; /* Pointer into value */
1823 unsigned ip
[4], /* IP address components */
1824 mask
[4]; /* IP netmask components */
1827 if ((parent
= AddLocation(location
)) == NULL
)
1830 parent
->limit
= AUTH_LIMIT_ALL
;
1833 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1838 * Skip comment lines...
1845 * Strip trailing whitespace, if any...
1850 while (len
> 0 && isspace(line
[len
- 1] & 255))
1857 * Extract the name from the beginning of the line...
1860 for (value
= line
; isspace(*value
& 255); value
++);
1862 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
1863 nameptr
< (name
+ sizeof(name
) - 1);)
1864 *nameptr
++ = *value
++;
1867 while (isspace(*value
& 255))
1870 if (name
[0] == '\0')
1874 * Decode the directive...
1877 if (strcasecmp(name
, "</Location>") == 0)
1879 else if (strcasecmp(name
, "<Limit") == 0 ||
1880 strcasecmp(name
, "<LimitExcept") == 0)
1882 if ((loc
= CopyLocation(&parent
)) == NULL
)
1888 for (valptr
= value
;
1889 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1895 if (strcmp(value
, "ALL") == 0)
1896 loc
->limit
= AUTH_LIMIT_ALL
;
1897 else if (strcmp(value
, "GET") == 0)
1898 loc
->limit
|= AUTH_LIMIT_GET
;
1899 else if (strcmp(value
, "HEAD") == 0)
1900 loc
->limit
|= AUTH_LIMIT_HEAD
;
1901 else if (strcmp(value
, "OPTIONS") == 0)
1902 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1903 else if (strcmp(value
, "POST") == 0)
1904 loc
->limit
|= AUTH_LIMIT_POST
;
1905 else if (strcmp(value
, "PUT") == 0)
1906 loc
->limit
|= AUTH_LIMIT_PUT
;
1907 else if (strcmp(value
, "TRACE") == 0)
1908 loc
->limit
|= AUTH_LIMIT_TRACE
;
1910 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1913 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
1916 if (strcasecmp(name
, "<LimitExcept") == 0)
1917 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1919 parent
->limit
&= ~loc
->limit
;
1921 else if (strcasecmp(name
, "</Limit>") == 0)
1923 else if (strcasecmp(name
, "Encryption") == 0)
1926 * "Encryption xxx" - set required encryption level...
1929 if (strcasecmp(value
, "never") == 0)
1930 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1931 else if (strcasecmp(value
, "always") == 0)
1933 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1934 "Using \"required\" instead.", value
, linenum
);
1936 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1938 else if (strcasecmp(value
, "required") == 0)
1939 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1940 else if (strcasecmp(value
, "ifrequested") == 0)
1941 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1943 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1946 else if (strcasecmp(name
, "Order") == 0)
1949 * "Order Deny,Allow" or "Order Allow,Deny"...
1952 if (strncasecmp(value
, "deny", 4) == 0)
1953 loc
->order_type
= AUTH_ALLOW
;
1954 else if (strncasecmp(value
, "allow", 5) == 0)
1955 loc
->order_type
= AUTH_DENY
;
1957 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1960 else if (strcasecmp(name
, "Allow") == 0 ||
1961 strcasecmp(name
, "Deny") == 0)
1964 * Allow [From] host/ip...
1965 * Deny [From] host/ip...
1968 if (strncasecmp(value
, "from", 4) == 0)
1971 * Strip leading "from"...
1976 while (isspace(*value
& 255))
1981 * Figure out what form the allow/deny address takes:
1992 * nnn.nnn.nnn.nnn/mm
1993 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1996 if (strcasecmp(value
, "all") == 0)
2002 if (strcasecmp(name
, "Allow") == 0)
2003 AllowIP(loc
, zeros
, zeros
);
2005 DenyIP(loc
, zeros
, zeros
);
2007 else if (strcasecmp(value
, "none") == 0)
2013 if (strcasecmp(name
, "Allow") == 0)
2014 AllowIP(loc
, ones
, zeros
);
2016 DenyIP(loc
, ones
, zeros
);
2018 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2021 * Host or domain name...
2024 if (value
[0] == '*')
2027 if (strcasecmp(name
, "Allow") == 0)
2028 AllowHost(loc
, value
);
2030 DenyHost(loc
, value
);
2035 * One of many IP address forms...
2038 if (!get_addr_and_mask(value
, ip
, mask
))
2040 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2045 if (strcasecmp(name
, "Allow") == 0)
2046 AllowIP(loc
, ip
, mask
);
2048 DenyIP(loc
, ip
, mask
);
2051 else if (strcasecmp(name
, "AuthType") == 0)
2054 * AuthType {none,basic,digest,basicdigest}
2057 if (strcasecmp(value
, "none") == 0)
2059 loc
->type
= AUTH_NONE
;
2060 loc
->level
= AUTH_ANON
;
2062 else if (strcasecmp(value
, "basic") == 0)
2064 loc
->type
= AUTH_BASIC
;
2066 if (loc
->level
== AUTH_ANON
)
2067 loc
->level
= AUTH_USER
;
2069 else if (strcasecmp(value
, "digest") == 0)
2071 loc
->type
= AUTH_DIGEST
;
2073 if (loc
->level
== AUTH_ANON
)
2074 loc
->level
= AUTH_USER
;
2076 else if (strcasecmp(value
, "basicdigest") == 0)
2078 loc
->type
= AUTH_BASICDIGEST
;
2080 if (loc
->level
== AUTH_ANON
)
2081 loc
->level
= AUTH_USER
;
2084 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2087 else if (strcasecmp(name
, "AuthClass") == 0)
2090 * AuthClass anonymous, user, system, group
2093 if (strcasecmp(value
, "anonymous") == 0)
2095 loc
->type
= AUTH_NONE
;
2096 loc
->level
= AUTH_ANON
;
2098 else if (strcasecmp(value
, "user") == 0)
2099 loc
->level
= AUTH_USER
;
2100 else if (strcasecmp(value
, "group") == 0)
2101 loc
->level
= AUTH_GROUP
;
2102 else if (strcasecmp(value
, "system") == 0)
2104 loc
->level
= AUTH_GROUP
;
2107 * Use the default system group if none is defined so far...
2110 if (NumSystemGroups
== 0)
2111 NumSystemGroups
= 1;
2113 for (i
= 0; i
< NumSystemGroups
; i
++)
2114 AddName(loc
, SystemGroups
[i
]);
2117 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2120 else if (strcasecmp(name
, "AuthGroupName") == 0)
2121 AddName(loc
, value
);
2122 else if (strcasecmp(name
, "Require") == 0)
2125 * Apache synonym for AuthClass and AuthGroupName...
2129 * Require valid-user
2130 * Require group names
2131 * Require user names
2134 for (valptr
= value
;
2135 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
2141 if (strcasecmp(value
, "valid-user") == 0 ||
2142 strcasecmp(value
, "user") == 0)
2143 loc
->level
= AUTH_USER
;
2144 else if (strcasecmp(value
, "group") == 0)
2145 loc
->level
= AUTH_GROUP
;
2148 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2154 * Get the list of names from the line...
2157 for (value
= valptr
; *value
;)
2159 while (isspace(*value
& 255))
2162 if (*value
== '\"' || *value
== '\'')
2165 * Grab quoted name...
2168 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2175 * Grab literal name.
2178 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2184 AddName(loc
, value
);
2186 for (value
= valptr
; isspace(*value
& 255); value
++);
2189 else if (strcasecmp(name
, "Satisfy") == 0)
2191 if (strcasecmp(value
, "all") == 0)
2192 loc
->satisfy
= AUTH_SATISFY_ALL
;
2193 else if (strcasecmp(value
, "any") == 0)
2194 loc
->satisfy
= AUTH_SATISFY_ANY
;
2196 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2200 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2204 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2212 * 'read_policy()' - Read a <Policy name> definition.
2215 static int /* O - New line number or 0 on error */
2216 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2217 char *policy
, /* I - Location name/path */
2218 int linenum
) /* I - Current line number */
2220 int i
; /* Looping var */
2221 policy_t
*pol
; /* Policy */
2222 policyop_t
*op
; /* Policy operation */
2223 int num_ops
; /* Number of IPP operations */
2224 ipp_op_t ops
[100]; /* Operations */
2225 int len
; /* Length of line */
2226 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2227 name
[256], /* Configuration directive */
2228 *nameptr
, /* Pointer into name */
2229 *value
, /* Value for directive */
2230 *valptr
; /* Pointer into value */
2234 * Create the policy...
2237 if ((pol
= AddPolicy(policy
)) == NULL
)
2241 * Read from the file...
2247 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
2252 * Skip comment lines...
2259 * Strip trailing whitespace, if any...
2264 while (len
> 0 && isspace(line
[len
- 1] & 255))
2271 * Extract the name from the beginning of the line...
2274 for (value
= line
; isspace(*value
& 255); value
++);
2276 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
2277 nameptr
< (name
+ sizeof(name
) - 1);)
2278 *nameptr
++ = *value
++;
2281 while (isspace(*value
& 255))
2284 if (name
[0] == '\0')
2288 * Decode the directive...
2291 if (!strcasecmp(name
, "</Policy>"))
2294 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2299 else if (!strcasecmp(name
, "<Limit") && !op
)
2302 * Scan for IPP operation names...
2309 for (valptr
= value
;
2310 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
2316 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2318 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2319 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2325 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2328 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
2332 * If none are specified, apply the policy to all operations...
2337 ops
[0] = IPP_ANY_OPERATION
;
2342 * Add a new policy for the first operation...
2345 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2347 else if (!strcasecmp(name
, "</Limit>") && op
)
2350 * Finish the current operation limit...
2356 * Copy the policy to the other operations...
2359 for (i
= 1; i
< num_ops
; i
++)
2360 AddPolicyOp(pol
, op
, ops
[i
]);
2365 else if (!strcasecmp(name
, "Authenticate") && op
)
2368 * Authenticate boolean
2371 if (!strcasecmp(value
, "on") ||
2372 !strcasecmp(value
, "yes") ||
2373 !strcasecmp(value
, "true"))
2374 op
->authenticate
= 1;
2375 else if (!strcasecmp(value
, "off") ||
2376 !strcasecmp(value
, "no") ||
2377 !strcasecmp(value
, "false"))
2378 op
->authenticate
= 0;
2380 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2383 else if (!strcasecmp(name
, "Order") && op
)
2386 * "Order Deny,Allow" or "Order Allow,Deny"...
2389 if (!strncasecmp(value
, "deny", 4))
2390 op
->order_type
= POLICY_ALLOW
;
2391 else if (!strncasecmp(value
, "allow", 5))
2392 op
->order_type
= POLICY_DENY
;
2394 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2397 else if ((!strcasecmp(name
, "Allow") || !strcasecmp(name
, "Deny")) && op
)
2400 * Allow name, @group, @OWNER
2401 * Deny name, @group, @OWNER
2404 for (value
= valptr
; *value
;)
2406 while (isspace(*value
& 255))
2409 if (*value
== '\"' || *value
== '\'')
2412 * Grab quoted name...
2415 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2422 * Grab literal name.
2425 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2431 if (!strcasecmp(name
, "Allow"))
2432 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2434 AddPolicyOpName(op
, POLICY_DENY
, value
);
2436 for (value
= valptr
; isspace(*value
& 255); value
++);
2440 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2443 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2447 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2455 * 'get_address()' - Get an address + port number from a line.
2458 static int /* O - 1 if address good, 0 if bad */
2459 get_address(const char *value
, /* I - Value string */
2460 unsigned defaddress
, /* I - Default address */
2461 int defport
, /* I - Default port */
2462 int deffamily
, /* I - Default family */
2463 http_addr_t
*address
) /* O - Socket address */
2465 char hostname
[256], /* Hostname or IP */
2466 portname
[256]; /* Port number or name */
2467 struct hostent
*host
; /* Host address */
2468 struct servent
*port
; /* Port number */
2472 * Initialize the socket address to the defaults...
2475 memset(address
, 0, sizeof(http_addr_t
));
2478 if (deffamily
== AF_INET6
)
2480 address
->ipv6
.sin6_family
= AF_INET6
;
2481 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2482 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2483 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2484 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2485 address
->ipv6
.sin6_port
= htons(defport
);
2488 #endif /* AF_INET6 */
2490 address
->ipv4
.sin_family
= AF_INET
;
2491 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2492 address
->ipv4
.sin_port
= htons(defport
);
2497 * If the address starts with a "/", it is a domain socket...
2502 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2504 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2508 address
->un
.sun_family
= AF_LOCAL
;
2509 strcpy(address
->un
.sun_path
, value
);
2513 #endif /* AF_LOCAL */
2516 * Try to grab a hostname and port number...
2519 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2522 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2525 * Hostname is a port number...
2528 strlcpy(portname
, hostname
, sizeof(portname
));
2539 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2544 * Decode the hostname and port number as needed...
2547 if (hostname
[0] && strcmp(hostname
, "*"))
2549 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2551 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2552 hstrerror(h_errno
));
2556 httpAddrLoad(host
, defport
, 0, address
);
2559 if (portname
[0] != '\0')
2561 if (isdigit(portname
[0] & 255))
2564 if (address
->addr
.sa_family
== AF_INET6
)
2565 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2567 #endif /* AF_INET6 */
2568 address
->ipv4
.sin_port
= htons(atoi(portname
));
2572 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2574 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2581 if (address
->addr
.sa_family
== AF_INET6
)
2582 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2584 #endif /* AF_INET6 */
2585 address
->ipv4
.sin_port
= htons(port
->s_port
);
2595 * 'get_addr_and_mask()' - Get an IP address and netmask.
2598 static int /* O - 1 on success, 0 on failure */
2599 get_addr_and_mask(const char *value
, /* I - String from config file */
2600 unsigned *ip
, /* O - Address value */
2601 unsigned *mask
) /* O - Mask value */
2603 int i
, /* Looping var */
2604 family
, /* Address family */
2605 ipcount
; /* Count of fields in address */
2606 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2608 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2609 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2610 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2611 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2616 * Get the address...
2619 memset(ip
, 0, sizeof(unsigned) * 4);
2621 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2625 * See if we have any values > 255; if so, this is an IPv6 address only.
2628 for (i
= 0; i
< ipcount
; i
++)
2634 #endif /* AF_INET6 */
2636 if ((value
= strchr(value
, '/')) != NULL
)
2639 * Get the netmask value(s)...
2643 memset(mask
, 0, sizeof(unsigned) * 4);
2644 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2645 mask
+ 2, mask
+ 3))
2652 if (family
== AF_INET6
)
2657 mask
[0] = 0xffffffff;
2659 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2662 mask
[1] = 0xffffffff;
2666 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2669 mask
[1] = 0xffffffff;
2673 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2678 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2681 #endif /* AF_INET6 */
2686 mask
[0] = 0xffffffff;
2688 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2691 mask
[1] = 0xffffffff;
2695 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2698 mask
[1] = 0xffffffff;
2702 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2707 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2718 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2721 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2724 if ((ip
[0] & ~mask
[0]) != 0 ||
2725 (ip
[1] & ~mask
[1]) != 0 ||
2726 (ip
[2] & ~mask
[2]) != 0 ||
2727 (ip
[3] & ~mask
[3]) != 0)
2735 * 'get_operation()' - Get an IPP opcode from an operation name...
2738 static ipp_op_t
/* O - Operation code or -1 on error */
2739 get_operation(const char *name
) /* I - Operating name */
2741 int i
; /* Looping var */
2742 static const char * const ipp_ops
[] = /* List of standard operations */
2746 /* 0x0002 */ "print-job",
2747 /* 0x0003 */ "print-uri",
2748 /* 0x0004 */ "validate-job",
2749 /* 0x0005 */ "create-job",
2750 /* 0x0006 */ "send-document",
2751 /* 0x0007 */ "send-uri",
2752 /* 0x0008 */ "cancel-job",
2753 /* 0x0009 */ "get-job-attributes",
2754 /* 0x000a */ "get-jobs",
2755 /* 0x000b */ "get-printer-attributes",
2756 /* 0x000c */ "hold-job",
2757 /* 0x000d */ "release-job",
2758 /* 0x000e */ "restart-job",
2760 /* 0x0010 */ "pause-printer",
2761 /* 0x0011 */ "resume-printer",
2762 /* 0x0012 */ "purge-jobs",
2763 /* 0x0013 */ "set-printer-attributes",
2764 /* 0x0014 */ "set-job-attributes",
2765 /* 0x0015 */ "get-printer-supported-values",
2766 /* 0x0016 */ "create-printer-subscription",
2767 /* 0x0017 */ "create-job-subscription",
2768 /* 0x0018 */ "get-subscription-attributes",
2769 /* 0x0019 */ "get-subscriptions",
2770 /* 0x001a */ "renew-subscription",
2771 /* 0x001b */ "cancel-subscription",
2772 /* 0x001c */ "get-notifications",
2773 /* 0x001d */ "send-notifications",
2777 /* 0x0021 */ "get-print-support-files",
2778 /* 0x0022 */ "enable-printer",
2779 /* 0x0023 */ "disable-printer",
2780 /* 0x0024 */ "pause-printer-after-current-job",
2781 /* 0x0025 */ "hold-new-jobs",
2782 /* 0x0026 */ "release-held-new-jobs",
2783 /* 0x0027 */ "deactivate-printer",
2784 /* 0x0028 */ "activate-printer",
2785 /* 0x0029 */ "restart-printer",
2786 /* 0x002a */ "shutdown-printer",
2787 /* 0x002b */ "startup-printer",
2788 /* 0x002c */ "reprocess-job",
2789 /* 0x002d */ "cancel-current-job",
2790 /* 0x002e */ "suspend-current-job",
2791 /* 0x002f */ "resume-job",
2792 /* 0x0030 */ "promote-job",
2793 /* 0x0031 */ "schedule-job-after"
2795 *cups_ops
[] = /* List of CUPS operations */
2797 /* 0x4001 */ "cups-get-default",
2798 /* 0x4002 */ "cups-get-printers",
2799 /* 0x4003 */ "cups-add-printer",
2800 /* 0x4004 */ "cups-delete-printer",
2801 /* 0x4005 */ "cups-get-classes",
2802 /* 0x4006 */ "cups-add-class",
2803 /* 0x4007 */ "cups-delete-class",
2804 /* 0x4008 */ "cups-accept-jobs",
2805 /* 0x4009 */ "cups-reject-jobs",
2806 /* 0x400a */ "cups-set-default",
2807 /* 0x400b */ "cups-get-devices",
2808 /* 0x400c */ "cups-get-ppds",
2809 /* 0x400d */ "cups-move-job",
2810 /* 0x400e */ "cups-add-device",
2811 /* 0x400f */ "cups-delete-device"
2815 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2816 if (!strcasecmp(name
, ipp_ops
[i
]))
2817 return ((ipp_op_t
)i
);
2819 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2820 if (!strcasecmp(name
, cups_ops
[i
]))
2821 return ((ipp_op_t
)(i
+ 0x4001));
2823 return ((ipp_op_t
)-1);
2829 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2830 * required by SSLSetCertificate.
2832 * For now we assumes that there is exactly one SecIdentity in the
2833 * keychain - i.e. there is exactly one matching cert/private key pair.
2834 * In the future we will search a keychain for a SecIdentity matching a
2835 * specific criteria. We also skip the operation of adding additional
2836 * non-signing certs from the keychain to the CFArrayRef.
2838 * To create a self-signed certificate for testing use the certtool.
2839 * Executing the following as root will do it:
2841 * certtool c c v k=CUPS
2845 CDSAGetServerCerts(void)
2847 OSStatus err
; /* Error info */
2848 SecKeychainRef kcRef
; /* Keychain reference */
2849 SecIdentitySearchRef srchRef
; /* Search reference */
2850 SecIdentityRef identity
; /* Identity */
2851 CFArrayRef ca
; /* Certificate array */
2858 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2861 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2862 ServerCertificate
, err
);
2866 * Search for "any" identity matching specified key use;
2867 * in this app, we expect there to be exactly one.
2870 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2874 "Cannot find signing key in keychain \"%s\", error %d",
2875 ServerCertificate
, err
);
2878 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2882 "Cannot find signing key in keychain \"%s\", error %d",
2883 ServerCertificate
, err
);
2886 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2887 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2891 * Found one. Place it in a CFArray.
2892 * TBD: snag other (non-identity) certs from keychain and add them
2896 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2899 LogMessage(L_ERROR
, "CFArrayCreate error");
2902 /*CFRelease(identity);*/
2905 /*CFRelease(srchRef);*/
2908 /*CFRelease(kcRef);*/
2913 #endif /* HAVE_CDSASSL */