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>
47 #ifdef HAVE_DOMAINSOCKETS
49 #endif /* HAVE_DOMAINSOCKETS */
52 # include <Security/SecureTransport.h>
53 # include <Security/SecIdentitySearch.h>
54 #endif /* HAVE_CDSASSL */
58 #endif /* HAVE_VSYSLOG */
62 * Possibly missing network definitions...
66 # define INADDR_NONE 0xffffffff
67 #endif /* !INADDR_NONE */
71 * Configuration variable structure...
76 char *name
; /* Name of variable */
77 void *ptr
; /* Pointer to variable */
78 int type
; /* Type (int, string, address) */
90 static var_t variables
[] =
92 { "AccessLog", &AccessLog
, VAR_STRING
},
93 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
94 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
95 { "BrowseLocalOptions", &BrowseLocalOptions
, VAR_STRING
},
96 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
97 { "BrowseRemoteOptions", &BrowseRemoteOptions
, VAR_STRING
},
98 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
99 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
100 { "Browsing", &Browsing
, VAR_BOOLEAN
},
101 { "Classification", &Classification
, VAR_STRING
},
102 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
103 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
104 { "DataDir", &DataDir
, VAR_STRING
},
105 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
106 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
107 { "DefaultPolicy", &DefaultPolicy
, VAR_STRING
},
108 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
109 { "ErrorLog", &ErrorLog
, VAR_STRING
},
110 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
111 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
112 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
113 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
114 { "FilterNice", &FilterNice
, VAR_INTEGER
},
115 { "FontPath", &FontPath
, VAR_STRING
},
116 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
117 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
118 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
119 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
120 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
121 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
122 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
123 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
124 { "MaxActiveJobs", &MaxActiveJobs
, VAR_INTEGER
},
125 { "MaxClients", &MaxClients
, VAR_INTEGER
},
126 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
127 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
128 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
129 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
130 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
131 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
132 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
133 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
134 { "PageLog", &PageLog
, VAR_STRING
},
135 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
136 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
137 { "Printcap", &Printcap
, VAR_STRING
},
138 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
139 { "ReloadTimeout", &ReloadTimeout
, VAR_INTEGER
},
140 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
141 { "RequestRoot", &RequestRoot
, VAR_STRING
},
142 { "RIPCache", &RIPCache
, VAR_STRING
},
143 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
144 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
145 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
146 { "ServerBin", &ServerBin
, VAR_STRING
},
148 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
149 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
150 { "ServerKey", &ServerKey
, VAR_STRING
},
151 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
152 #endif /* HAVE_SSL */
153 { "ServerName", &ServerName
, VAR_STRING
},
154 { "ServerRoot", &ServerRoot
, VAR_STRING
},
155 { "StateDir", &StateDir
, VAR_STRING
},
156 { "TempDir", &TempDir
, VAR_STRING
},
157 { "Timeout", &Timeout
, VAR_INTEGER
}
159 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
162 static unsigned ones
[4] =
164 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
166 static unsigned zeros
[4] =
168 0x00000000, 0x00000000, 0x00000000, 0x00000000
172 static CFArrayRef
CDSAGetServerCerts();
173 #endif /* HAVE_CDSASSL */
180 static int read_configuration(cups_file_t
*fp
);
181 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
182 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
183 static int get_address(const char *value
, unsigned defaddress
, int defport
,
184 int deffamily
, http_addr_t
*address
);
185 static int get_addr_and_mask(const char *value
, unsigned *ip
,
187 static ipp_op_t
get_operation(const char *name
);
191 * 'ReadConfiguration()' - Read the cupsd.conf file.
194 int /* O - 1 on success, 0 otherwise */
195 ReadConfiguration(void)
197 int i
; /* Looping var */
198 cups_file_t
*fp
; /* Configuration file */
199 int status
; /* Return status */
200 char temp
[1024], /* Temporary buffer */
201 *slash
; /* Directory separator */
202 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
204 char *language
; /* Language string */
205 struct passwd
*user
; /* Default user */
206 struct group
*group
; /* Default group */
207 char *old_serverroot
, /* Old ServerRoot */
208 *old_requestroot
; /* Old RequestRoot */
212 * Shutdown the server...
218 * Save the old root paths...
221 old_serverroot
= NULL
;
222 SetString(&old_serverroot
, ServerRoot
);
223 old_requestroot
= NULL
;
224 SetString(&old_requestroot
, RequestRoot
);
227 * Reset the server configuration data...
230 DeleteAllLocations();
248 for (i
= 0; i
< NumRelays
; i
++)
249 if (Relays
[i
].from
.type
== AUTH_NAME
)
250 free(Relays
[i
].from
.mask
.name
.name
);
257 if (NumListeners
> 0)
259 #ifdef HAVE_DOMAINSOCKETS
260 int i
; /* Looping var */
261 listener_t
*lis
; /* Current listening socket */
263 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
264 if (lis
->address
.sin_family
== AF_LOCAL
)
265 ClearString((char **)&lis
->address
.sin_addr
);
266 #endif /* HAVE_DOMAINSOCKETS */
277 gethostname(temp
, sizeof(temp
));
278 SetString(&ServerName
, temp
);
279 SetStringf(&ServerAdmin
, "root@%s", temp
);
280 SetString(&ServerBin
, CUPS_SERVERBIN
);
281 SetString(&RequestRoot
, CUPS_REQUESTS
);
282 SetString(&DocumentRoot
, CUPS_DOCROOT
);
283 SetString(&DataDir
, CUPS_DATADIR
);
284 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
285 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
286 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
287 SetString(&Printcap
, "/etc/printcap");
288 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
289 SetString(&FontPath
, CUPS_FONTPATH
);
290 SetString(&RemoteRoot
, "remroot");
291 SetString(&ServerHeader
, "CUPS/1.1");
292 SetString(&StateDir
, CUPS_STATEDIR
);
294 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
295 if ((slash
= strrchr(temp
, '/')) != NULL
)
298 SetString(&ServerRoot
, temp
);
300 ClearString(&Classification
);
301 ClassifyOverride
= 0;
305 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
307 SetString(&ServerCertificate
, "ssl/server.crt");
308 SetString(&ServerKey
, "ssl/server.key");
309 # endif /* HAVE_CDSASSL */
310 #endif /* HAVE_SSL */
312 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
314 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
317 SetString(&DefaultLanguage
, language
);
318 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
320 SetString(&RIPCache
, "8m");
322 if (getenv("TMPDIR") == NULL
)
323 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
325 SetString(&TempDir
, getenv("TMPDIR"));
328 * Find the default system group: "sys", "system", or "root"...
331 group
= getgrnam(CUPS_DEFAULT_GROUP
);
338 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
339 Group
= group
->gr_gid
;
348 SetString(&SystemGroups
[0], group
->gr_name
);
353 SetString(&SystemGroups
[0], "unknown");
359 * Find the default user...
362 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
363 User
= 1; /* Force to a non-priviledged account */
373 ConfigFilePerm
= 0640;
377 FaxRetryInterval
= 300;
382 HostNameLookups
= FALSE
;
383 ImplicitClasses
= TRUE
;
384 ImplicitAnyClasses
= FALSE
;
385 HideImplicitMembers
= TRUE
;
387 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
388 ListenBackLog
= SOMAXCONN
;
391 MaxClientsPerHost
= 0;
392 MaxLogSize
= 1024 * 1024;
393 MaxPrinterHistory
= 10;
396 RootCertDuration
= 300;
398 Timeout
= DEFAULT_TIMEOUT
;
400 BrowseInterval
= DEFAULT_INTERVAL
;
401 BrowsePort
= ippPort();
402 BrowseProtocols
= BROWSE_CUPS
;
403 BrowseShortNames
= TRUE
;
404 BrowseTimeout
= DEFAULT_TIMEOUT
;
407 ClearString(&BrowseLocalOptions
);
408 ClearString(&BrowseRemoteOptions
);
410 JobHistory
= DEFAULT_HISTORY
;
411 JobFiles
= DEFAULT_FILES
;
416 MaxJobsPerPrinter
= 0;
419 ClearString(&DefaultPolicy
);
422 * Read the configuration file...
425 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
428 status
= read_configuration(fp
);
441 * Use the default system group if none was supplied in cupsd.conf...
444 if (NumSystemGroups
== 0)
448 * Get the access control list for browsing...
451 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
454 * Open the system log for cupsd if necessary...
458 if (strcmp(AccessLog
, "syslog") == 0 ||
459 strcmp(ErrorLog
, "syslog") == 0 ||
460 strcmp(PageLog
, "syslog") == 0)
461 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
462 #endif /* HAVE_VSYSLOG */
465 * Log the configuration file that was used...
468 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
471 * Check that we have at least one listen/port line; if not, report this
472 * as an error and exit!
475 if (NumListeners
== 0)
481 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
487 cupsdEndProcess(getpid(), 0);
491 * Set the default locale using the language and charset...
494 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
497 * Update all relative filenames to include the full path from ServerRoot...
500 if (DocumentRoot
[0] != '/')
501 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
503 if (RequestRoot
[0] != '/')
504 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
506 if (ServerBin
[0] != '/')
507 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
510 if (ServerCertificate
[0] != '/')
511 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
513 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
514 chown(ServerCertificate
, RunUser
, Group
);
515 chmod(ServerCertificate
, ConfigFilePerm
);
517 if (ServerKey
[0] != '/')
518 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
520 chown(ServerKey
, RunUser
, Group
);
521 chmod(ServerKey
, ConfigFilePerm
);
522 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
523 #endif /* HAVE_SSL */
526 * Make sure that directories and config files are owned and
527 * writable by the user and group in the cupsd.conf file...
530 chown(StateDir
, RunUser
, Group
);
531 chmod(StateDir
, 0775);
533 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
536 chown(temp
, RunUser
, Group
);
539 snprintf(temp
, sizeof(temp
), "%s/ppd", StateDir
);
542 chown(temp
, RunUser
, Group
);
545 chown(ServerRoot
, RunUser
, Group
);
546 chmod(ServerRoot
, 0775);
548 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
551 chown(temp
, RunUser
, Group
);
554 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
557 chown(temp
, RunUser
, Group
);
560 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
561 chown(temp
, RunUser
, Group
);
562 chmod(temp
, ConfigFilePerm
);
564 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
565 chown(temp
, RunUser
, Group
);
569 chmod(temp
, ConfigFilePerm
);
570 #endif /* __APPLE__ */
572 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
573 chown(temp
, RunUser
, Group
);
577 chmod(temp
, ConfigFilePerm
);
578 #endif /* __APPLE__ */
580 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
581 chown(temp
, User
, Group
);
585 * Make sure the request and temporary directories have the right
589 chown(RequestRoot
, RunUser
, Group
);
590 chmod(RequestRoot
, 0710);
592 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
596 * Update ownership and permissions if the CUPS temp directory
597 * is under the spool directory or does not exist...
600 if (access(TempDir
, 0))
601 mkdir(TempDir
, 01770);
603 chown(TempDir
, RunUser
, Group
);
604 chmod(TempDir
, 01770);
607 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
610 * Clean out the temporary directory...
613 cups_dir_t
*dir
; /* Temporary directory */
614 cups_dentry_t
*dent
; /* Directory entry */
615 char tempfile
[1024]; /* Temporary filename */
618 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
620 LogMessage(L_INFO
, "Cleaning out old temporary files in \"%s\"...",
623 while ((dent
= cupsDirRead(dir
)) != NULL
)
625 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
627 if (unlink(tempfile
))
628 LogMessage(L_ERROR
, "Unable to remove temporary file \"%s\" - %s",
629 tempfile
, strerror(errno
));
631 LogMessage(L_DEBUG
, "Removed temporary file \"%s\"...", tempfile
);
637 LogMessage(L_ERROR
, "Unable to open temporary directory \"%s\" - %s",
638 TempDir
, strerror(errno
));
642 * Check the MaxClients setting, and then allocate memory for it...
645 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
648 LogMessage(L_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
651 MaxClients
= MaxFDs
/ 3;
654 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
656 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
657 MaxClients
, strerror(errno
));
661 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
664 * Check the MaxActiveJobs setting; limit to 1/3 the available
665 * file descriptors, since we need a pipe for each job...
668 if (MaxActiveJobs
> (MaxFDs
/ 3))
669 MaxActiveJobs
= MaxFDs
/ 3;
671 if (Classification
&& strcasecmp(Classification
, "none") == 0)
672 ClearString(&Classification
);
675 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
678 * Update the MaxClientsPerHost value, as needed...
681 if (MaxClientsPerHost
<= 0)
682 MaxClientsPerHost
= MaxClients
;
684 if (MaxClientsPerHost
> MaxClients
)
685 MaxClientsPerHost
= MaxClients
;
687 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
691 * Update the default policy, as needed...
695 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
697 DefaultPolicyPtr
= NULL
;
699 if (!DefaultPolicyPtr
)
701 policy_t
*p
; /* New policy */
702 policyop_t
*po
; /* New policy operation */
703 char groupname
[255]; /* Group name */
707 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
709 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
710 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
713 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
715 DefaultPolicyPtr
= p
= AddPolicy("default");
717 LogMessage(L_INFO
, "<Policy default>");
718 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
719 "Release-Job Restart-Job Purge-Jobs "
720 "Set-Job-Attributes Create-Job-Subscription "
721 "Renew-Subscription Cancel-Subscription "
722 "Get-Notifications Reprocess-Job Cancel-Current-Job "
723 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
724 LogMessage(L_INFO
, "Order Allow,Deny");
725 LogMessage(L_INFO
, "Allow @OWNER");
727 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
728 po
->order_type
= POLICY_DENY
;
730 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
732 for (i
= 0; i
< NumSystemGroups
; i
++)
734 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
735 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
736 LogMessage(L_INFO
, "Allow @%s", groupname
);
739 AddPolicyOp(p
, po
, IPP_SEND_URI
);
740 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
741 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
742 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
743 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
744 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
745 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
746 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
747 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
748 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
749 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
750 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
751 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
752 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
753 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
754 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
756 LogMessage(L_INFO
, "</Limit>");
758 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
759 "Set-Printer-Attributes Enable-Printer "
760 "Disable-Printer Pause-Printer-After-Current-Job "
761 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
762 "Activate-Printer Restart-Printer Shutdown-Printer "
763 "Startup-Printer Promote-Job Schedule-Job-After "
764 "CUPS-Add-Printer CUPS-Delete-Printer "
765 "CUPS-Add-Class CUPS-Delete-Class "
766 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
767 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
768 LogMessage(L_INFO
, "Order Allow,Deny");
769 LogMessage(L_INFO
, "Authenticate yes");
771 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
772 po
->order_type
= POLICY_DENY
;
773 po
->authenticate
= 1;
775 for (i
= 0; i
< NumSystemGroups
; i
++)
777 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
778 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
779 LogMessage(L_INFO
, "Allow @%s", groupname
);
782 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
783 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
784 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
785 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
786 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
787 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
788 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
789 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
790 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
791 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
792 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
793 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
794 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
795 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
796 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
797 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
798 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
799 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
800 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
801 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
802 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
803 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
804 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
806 LogMessage(L_INFO
, "</Limit>");
808 LogMessage(L_INFO
, "<Limit All>");
809 LogMessage(L_INFO
, "Order Deny,Allow");
811 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
812 po
->order_type
= POLICY_ALLOW
;
814 LogMessage(L_INFO
, "</Limit>");
815 LogMessage(L_INFO
, "</Policy>");
820 * If we are doing a full reload or the server root has changed, flush
821 * the jobs, printers, etc. and start from scratch...
824 if (NeedReload
== RELOAD_ALL
||
825 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
826 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
828 LogMessage(L_INFO
, "Full reload is required.");
838 DefaultPrinter
= NULL
;
840 if (MimeDatabase
!= NULL
)
841 mimeDelete(MimeDatabase
);
845 for (i
= 0; i
< NumMimeTypes
; i
++)
846 free((void *)MimeTypes
[i
]);
852 * Read the MIME type and conversion database...
855 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
857 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
859 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
860 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
863 * Create a list of MIME types for the document-format-supported
867 NumMimeTypes
= MimeDatabase
->num_types
;
868 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
871 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
873 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
875 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
876 MimeDatabase
->types
[i
]->type
);
878 MimeTypes
[i
] = strdup(type
);
881 if (i
< NumMimeTypes
)
882 MimeTypes
[i
] = strdup("application/octet-stream");
888 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
892 * Load printers and classes...
901 * Load queued jobs...
906 LogMessage(L_INFO
, "Full reload complete.");
912 LogMessage(L_INFO
, "Partial reload complete.");
916 * Reset the reload state...
919 NeedReload
= RELOAD_NONE
;
921 ClearString(&old_serverroot
);
922 ClearString(&old_requestroot
);
925 * Startup the server and return...
935 * 'read_configuration()' - Read a configuration file.
938 static int /* O - 1 on success, 0 on failure */
939 read_configuration(cups_file_t
*fp
) /* I - File to read from */
941 int i
; /* Looping var */
942 int linenum
; /* Current line number */
943 char line
[HTTP_MAX_BUFFER
], /* Line from file */
944 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
945 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
946 *ptr
, /* Pointer into line/temp */
947 *value
; /* Pointer to value */
948 int valuelen
; /* Length of value */
949 var_t
*var
; /* Current variable */
950 unsigned ip
[4], /* Address value */
951 mask
[4]; /* Netmask value */
952 dirsvc_relay_t
*relay
; /* Relay data */
953 dirsvc_poll_t
*poll
; /* Polling data */
954 http_addr_t polladdr
; /* Polling address */
955 location_t
*location
; /* Browse location */
956 cups_file_t
*incfile
; /* Include file */
957 char incname
[1024]; /* Include filename */
961 * Loop through each line in the file...
966 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
969 * Decode the directive...
972 if (!strcasecmp(line
, "Include"))
979 strlcpy(incname
, value
, sizeof(incname
));
981 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
983 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
984 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
985 incname
, strerror(errno
));
988 read_configuration(incfile
);
989 cupsFileClose(incfile
);
992 else if (!strcasecmp(line
, "<Location"))
1000 linenum
= read_location(fp
, value
, linenum
);
1006 LogMessage(L_ERROR
, "Syntax error on line %d.",
1011 else if (!strcasecmp(line
, "<Policy"))
1019 linenum
= read_policy(fp
, value
, linenum
);
1025 LogMessage(L_ERROR
, "Syntax error on line %d.",
1030 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1033 * Add a listening address to the list...
1036 listener_t
*lis
; /* New listeners array */
1039 if (NumListeners
== 0)
1040 lis
= malloc(sizeof(listener_t
));
1042 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1046 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1047 line
, linenum
, strerror(errno
));
1052 lis
+= NumListeners
;
1054 memset(lis
, 0, sizeof(listener_t
));
1056 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1058 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1061 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1062 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1063 ntohs(lis
->address
.ipv6
.sin6_port
));
1065 #endif /* AF_INET6 */
1066 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1067 ntohs(lis
->address
.ipv4
.sin_port
));
1071 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1075 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1078 * Add a listening address to the list...
1081 listener_t
*lis
; /* New listeners array */
1084 if (NumListeners
== 0)
1085 lis
= malloc(sizeof(listener_t
));
1087 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1091 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1092 line
, linenum
, strerror(errno
));
1097 lis
+= NumListeners
;
1099 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1101 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1104 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1105 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1106 ntohs(lis
->address
.ipv6
.sin6_port
));
1108 #endif /* AF_INET6 */
1109 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1110 ntohs(lis
->address
.ipv4
.sin_port
));
1111 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1115 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1118 #endif /* HAVE_SSL */
1119 else if (!strcasecmp(line
, "BrowseAddress"))
1122 * Add a browse address to the list...
1125 dirsvc_addr_t
*dira
; /* New browse address array */
1128 if (NumBrowsers
== 0)
1129 dira
= malloc(sizeof(dirsvc_addr_t
));
1131 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1135 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1136 linenum
, strerror(errno
));
1141 dira
+= NumBrowsers
;
1143 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1145 if (!strcasecmp(value
, "@LOCAL"))
1148 * Send browse data to all local interfaces...
1151 strcpy(dira
->iface
, "*");
1154 else if (!strncasecmp(value
, "@IF(", 4))
1157 * Send browse data to the named interface...
1160 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1162 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1168 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1170 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1173 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1174 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1175 ntohs(dira
->to
.ipv6
.sin6_port
));
1177 #endif /* AF_INET6 */
1178 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1179 ntohs(dira
->to
.ipv4
.sin_port
));
1184 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1187 else if (!strcasecmp(line
, "BrowseOrder"))
1190 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1193 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1194 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1196 if (location
== NULL
)
1197 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1198 else if (!strncasecmp(value
, "deny", 4))
1199 location
->order_type
= AUTH_ALLOW
;
1200 else if (!strncasecmp(value
, "allow", 5))
1201 location
->order_type
= AUTH_DENY
;
1203 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1206 else if (!strcasecmp(line
, "BrowseProtocols"))
1209 * "BrowseProtocol name [... name]"
1212 BrowseProtocols
= 0;
1216 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1217 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1220 if (value
[valuelen
])
1222 value
[valuelen
] = '\0';
1226 if (!strcasecmp(value
, "cups"))
1227 BrowseProtocols
|= BROWSE_CUPS
;
1228 else if (!strcasecmp(value
, "slp"))
1229 BrowseProtocols
|= BROWSE_SLP
;
1230 else if (!strcasecmp(value
, "ldap"))
1231 BrowseProtocols
|= BROWSE_LDAP
;
1232 else if (!strcasecmp(value
, "all"))
1233 BrowseProtocols
|= BROWSE_ALL
;
1236 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1241 for (value
+= valuelen
; *value
; value
++)
1242 if (!isspace(*value
) || *value
!= ',')
1246 else if (!strcasecmp(line
, "BrowseAllow") ||
1247 !strcasecmp(line
, "BrowseDeny"))
1250 * BrowseAllow [From] host/ip...
1251 * BrowseDeny [From] host/ip...
1254 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1255 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1257 if (location
== NULL
)
1258 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1261 if (!strncasecmp(value
, "from ", 5))
1264 * Strip leading "from"...
1269 while (isspace(*value
))
1274 * Figure out what form the allow/deny address takes:
1285 * nnn.nnn.nnn.nnn/mm
1286 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1289 if (!strcasecmp(value
, "all"))
1295 if (!strcasecmp(line
, "BrowseAllow"))
1296 AllowIP(location
, zeros
, zeros
);
1298 DenyIP(location
, zeros
, zeros
);
1300 else if (!strcasecmp(value
, "none"))
1306 if (!strcasecmp(line
, "BrowseAllow"))
1307 AllowIP(location
, ones
, zeros
);
1309 DenyIP(location
, ones
, zeros
);
1311 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1314 * Host or domain name...
1317 if (value
[0] == '*')
1320 if (!strcasecmp(line
, "BrowseAllow"))
1321 AllowHost(location
, value
);
1323 DenyHost(location
, value
);
1328 * One of many IP address forms...
1331 if (!get_addr_and_mask(value
, ip
, mask
))
1333 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1338 if (!strcasecmp(line
, "BrowseAllow"))
1339 AllowIP(location
, ip
, mask
);
1341 DenyIP(location
, ip
, mask
);
1345 else if (!strcasecmp(line
, "BrowseRelay"))
1348 * BrowseRelay [from] source [to] destination
1352 relay
= malloc(sizeof(dirsvc_relay_t
));
1354 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1358 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1359 linenum
, strerror(errno
));
1366 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1368 if (!strncasecmp(value
, "from ", 5))
1371 * Strip leading "from"...
1376 while (isspace(*value
))
1381 * Figure out what form the from address takes:
1390 * nnn.nnn.nnn.nnn/mm
1391 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1394 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1397 * Host or domain name...
1400 if (value
[0] == '*')
1403 strlcpy(temp
, value
, sizeof(temp
));
1404 if ((ptr
= strchr(temp
, ' ')) != NULL
)
1407 relay
->from
.type
= AUTH_NAME
;
1408 relay
->from
.mask
.name
.name
= strdup(temp
);
1409 relay
->from
.mask
.name
.length
= strlen(temp
);
1414 * One of many IP address forms...
1417 if (!get_addr_and_mask(value
, ip
, mask
))
1419 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1424 relay
->from
.type
= AUTH_IP
;
1425 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1426 sizeof(relay
->from
.mask
.ip
.address
));
1427 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1428 sizeof(relay
->from
.mask
.ip
.netmask
));
1432 * Skip value and trailing whitespace...
1435 for (; *value
; value
++)
1436 if (isspace(*value
))
1439 while (isspace(*value
))
1442 if (!strncasecmp(value
, "to ", 3))
1445 * Strip leading "to"...
1450 while (isspace(*value
))
1455 * Get "to" address and port...
1458 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1460 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
1462 if (relay
->from
.type
== AUTH_IP
)
1463 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
1464 relay
->from
.mask
.ip
.address
[0],
1465 relay
->from
.mask
.ip
.address
[1],
1466 relay
->from
.mask
.ip
.address
[2],
1467 relay
->from
.mask
.ip
.address
[3],
1468 relay
->from
.mask
.ip
.netmask
[0],
1469 relay
->from
.mask
.ip
.netmask
[1],
1470 relay
->from
.mask
.ip
.netmask
[2],
1471 relay
->from
.mask
.ip
.netmask
[3]);
1473 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
1476 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1477 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1478 ntohs(relay
->to
.ipv6
.sin6_port
));
1480 #endif /* AF_INET6 */
1481 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1482 ntohs(relay
->to
.ipv4
.sin_port
));
1488 if (relay
->from
.type
== AUTH_NAME
)
1489 free(relay
->from
.mask
.name
.name
);
1491 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1494 else if (!strcasecmp(line
, "BrowsePoll"))
1497 * BrowsePoll address[:port]
1501 poll
= malloc(sizeof(dirsvc_poll_t
));
1503 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1507 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1508 linenum
, strerror(errno
));
1516 * Get poll address and port...
1519 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1522 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1524 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1527 if (polladdr
.addr
.sa_family
== AF_INET6
)
1528 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1530 #endif /* AF_INET6 */
1531 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1533 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1536 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1538 else if (!strcasecmp(line
, "User"))
1541 * User ID to run as...
1544 if (isdigit(value
[0]))
1548 struct passwd
*p
; /* Password information */
1551 p
= getpwnam(value
);
1556 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
1559 else if (!strcasecmp(line
, "Group"))
1562 * Group ID to run as...
1565 if (isdigit(value
[0]))
1566 Group
= atoi(value
);
1569 struct group
*g
; /* Group information */
1572 g
= getgrnam(value
);
1577 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
1580 else if (!strcasecmp(line
, "SystemGroup"))
1583 * System (admin) group(s)...
1586 char *valueptr
, /* Pointer into value */
1587 quote
; /* Quote character */
1590 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1592 if (*value
== '\'' || *value
== '\"')
1595 * Scan quoted name...
1600 for (valueptr
= value
; *valueptr
; valueptr
++)
1601 if (*valueptr
== quote
)
1607 * Scan space or comma-delimited name...
1610 for (valueptr
= value
; *valueptr
; valueptr
++)
1611 if (isspace(*valueptr
) || *valueptr
== ',')
1618 SetString(SystemGroups
+ i
, value
);
1622 while (*value
== ',' || isspace(*value
))
1627 NumSystemGroups
= i
;
1629 else if (!strcasecmp(line
, "HostNameLookups"))
1632 * Do hostname lookups?
1635 if (!strcasecmp(value
, "off"))
1636 HostNameLookups
= 0;
1637 else if (!strcasecmp(value
, "on"))
1638 HostNameLookups
= 1;
1639 else if (!strcasecmp(value
, "double"))
1640 HostNameLookups
= 2;
1642 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1645 else if (!strcasecmp(line
, "LogLevel"))
1648 * Amount of logging to do...
1651 if (!strcasecmp(value
, "debug2"))
1652 LogLevel
= L_DEBUG2
;
1653 else if (!strcasecmp(value
, "debug"))
1655 else if (!strcasecmp(value
, "info"))
1657 else if (!strcasecmp(value
, "notice"))
1658 LogLevel
= L_NOTICE
;
1659 else if (!strcasecmp(value
, "warn"))
1661 else if (!strcasecmp(value
, "error"))
1663 else if (!strcasecmp(value
, "crit"))
1665 else if (!strcasecmp(value
, "alert"))
1667 else if (!strcasecmp(value
, "emerg"))
1669 else if (!strcasecmp(value
, "none"))
1672 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1674 else if (!strcasecmp(line
, "PrintcapFormat"))
1677 * Format of printcap file?
1680 if (!strcasecmp(value
, "bsd"))
1681 PrintcapFormat
= PRINTCAP_BSD
;
1682 else if (!strcasecmp(value
, "solaris"))
1683 PrintcapFormat
= PRINTCAP_SOLARIS
;
1685 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1688 else if (!strcasecmp(line
, "ServerTokens"))
1691 * Set the string used for the Server header...
1694 struct utsname plat
; /* Platform info */
1699 if (!strcasecmp(value
, "ProductOnly"))
1700 SetString(&ServerHeader
, "CUPS");
1701 else if (!strcasecmp(value
, "Major"))
1702 SetString(&ServerHeader
, "CUPS/1");
1703 else if (!strcasecmp(value
, "Minor"))
1704 SetString(&ServerHeader
, "CUPS/1.1");
1705 else if (!strcasecmp(value
, "Minimal"))
1706 SetString(&ServerHeader
, CUPS_MINIMAL
);
1707 else if (!strcasecmp(value
, "OS"))
1708 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1709 else if (!strcasecmp(value
, "Full"))
1710 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1711 else if (!strcasecmp(value
, "None"))
1712 ClearString(&ServerHeader
);
1714 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1719 * Find a simple variable in the list...
1722 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1723 if (!strcasecmp(line
, var
->name
))
1729 * Unknown directive! Output an error message and continue...
1732 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
1742 char *units
; /* Units */
1745 n
= strtol(value
, &units
, 0);
1747 if (units
&& *units
)
1749 if (tolower(units
[0] & 255) == 'g')
1750 n
*= 1024 * 1024 * 1024;
1751 else if (tolower(units
[0] & 255) == 'm')
1753 else if (tolower(units
[0] & 255) == 'k')
1755 else if (tolower(units
[0] & 255) == 't')
1759 *((int *)var
->ptr
) = n
;
1764 if (!strcasecmp(value
, "true") ||
1765 !strcasecmp(value
, "on") ||
1766 !strcasecmp(value
, "enabled") ||
1767 !strcasecmp(value
, "yes") ||
1769 *((int *)var
->ptr
) = TRUE
;
1770 else if (!strcasecmp(value
, "false") ||
1771 !strcasecmp(value
, "off") ||
1772 !strcasecmp(value
, "disabled") ||
1773 !strcasecmp(value
, "no") ||
1774 !strcasecmp(value
, "0"))
1775 *((int *)var
->ptr
) = FALSE
;
1777 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1782 SetString((char **)var
->ptr
, value
);
1793 * 'read_location()' - Read a <Location path> definition.
1796 static int /* O - New line number or 0 on error */
1797 read_location(cups_file_t
*fp
, /* I - Configuration file */
1798 char *location
, /* I - Location name/path */
1799 int linenum
) /* I - Current line number */
1801 int i
; /* Looping var */
1802 location_t
*loc
, /* New location */
1803 *parent
; /* Parent location */
1804 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1805 *value
, /* Value for directive */
1806 *valptr
; /* Pointer into value */
1807 unsigned ip
[4], /* IP address components */
1808 mask
[4]; /* IP netmask components */
1811 if ((parent
= AddLocation(location
)) == NULL
)
1814 parent
->limit
= AUTH_LIMIT_ALL
;
1817 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1820 * Decode the directive...
1823 if (!strcasecmp(line
, "</Location>"))
1825 else if (!strcasecmp(line
, "<Limit") ||
1826 !strcasecmp(line
, "<LimitExcept"))
1830 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
1834 if ((loc
= CopyLocation(&parent
)) == NULL
)
1840 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1845 if (!strcmp(value
, "ALL"))
1846 loc
->limit
= AUTH_LIMIT_ALL
;
1847 else if (!strcmp(value
, "GET"))
1848 loc
->limit
|= AUTH_LIMIT_GET
;
1849 else if (!strcmp(value
, "HEAD"))
1850 loc
->limit
|= AUTH_LIMIT_HEAD
;
1851 else if (!strcmp(value
, "OPTIONS"))
1852 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1853 else if (!strcmp(value
, "POST"))
1854 loc
->limit
|= AUTH_LIMIT_POST
;
1855 else if (!strcmp(value
, "PUT"))
1856 loc
->limit
|= AUTH_LIMIT_PUT
;
1857 else if (!strcmp(value
, "TRACE"))
1858 loc
->limit
|= AUTH_LIMIT_TRACE
;
1860 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1863 for (value
= valptr
; isspace(*value
& 255); value
++);
1866 if (!strcasecmp(line
, "<LimitExcept"))
1867 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1869 parent
->limit
&= ~loc
->limit
;
1871 else if (!strcasecmp(line
, "</Limit>"))
1873 else if (!strcasecmp(line
, "Encryption"))
1876 * "Encryption xxx" - set required encryption level...
1879 if (!strcasecmp(value
, "never"))
1880 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1881 else if (!strcasecmp(value
, "always"))
1883 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1884 "Using \"required\" instead.", value
, linenum
);
1886 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1888 else if (!strcasecmp(value
, "required"))
1889 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1890 else if (!strcasecmp(value
, "ifrequested"))
1891 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1893 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1896 else if (!strcasecmp(line
, "Order"))
1899 * "Order Deny,Allow" or "Order Allow,Deny"...
1902 if (!strncasecmp(value
, "deny", 4))
1903 loc
->order_type
= AUTH_ALLOW
;
1904 else if (!strncasecmp(value
, "allow", 5))
1905 loc
->order_type
= AUTH_DENY
;
1907 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1910 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1913 * Allow [From] host/ip...
1914 * Deny [From] host/ip...
1917 if (!strncasecmp(value
, "from", 4))
1920 * Strip leading "from"...
1925 while (isspace(*value
& 255))
1930 * Figure out what form the allow/deny address takes:
1941 * nnn.nnn.nnn.nnn/mm
1942 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1945 if (!strcasecmp(value
, "all"))
1951 if (!strcasecmp(line
, "Allow"))
1952 AllowIP(loc
, zeros
, zeros
);
1954 DenyIP(loc
, zeros
, zeros
);
1956 else if (!strcasecmp(value
, "none"))
1962 if (!strcasecmp(line
, "Allow"))
1963 AllowIP(loc
, ones
, zeros
);
1965 DenyIP(loc
, ones
, zeros
);
1967 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1970 * Host or domain name...
1973 if (value
[0] == '*')
1976 if (!strcasecmp(line
, "Allow"))
1977 AllowHost(loc
, value
);
1979 DenyHost(loc
, value
);
1984 * One of many IP address forms...
1987 if (!get_addr_and_mask(value
, ip
, mask
))
1989 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1994 if (!strcasecmp(line
, "Allow"))
1995 AllowIP(loc
, ip
, mask
);
1997 DenyIP(loc
, ip
, mask
);
2000 else if (!strcasecmp(line
, "AuthType"))
2003 * AuthType {none,basic,digest,basicdigest}
2006 if (!strcasecmp(value
, "none"))
2008 loc
->type
= AUTH_NONE
;
2009 loc
->level
= AUTH_ANON
;
2011 else if (!strcasecmp(value
, "basic"))
2013 loc
->type
= AUTH_BASIC
;
2015 if (loc
->level
== AUTH_ANON
)
2016 loc
->level
= AUTH_USER
;
2018 else if (!strcasecmp(value
, "digest"))
2020 loc
->type
= AUTH_DIGEST
;
2022 if (loc
->level
== AUTH_ANON
)
2023 loc
->level
= AUTH_USER
;
2025 else if (!strcasecmp(value
, "basicdigest"))
2027 loc
->type
= AUTH_BASICDIGEST
;
2029 if (loc
->level
== AUTH_ANON
)
2030 loc
->level
= AUTH_USER
;
2033 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2036 else if (!strcasecmp(line
, "AuthClass"))
2039 * AuthClass anonymous, user, system, group
2042 if (!strcasecmp(value
, "anonymous"))
2044 loc
->type
= AUTH_NONE
;
2045 loc
->level
= AUTH_ANON
;
2047 else if (!strcasecmp(value
, "user"))
2048 loc
->level
= AUTH_USER
;
2049 else if (!strcasecmp(value
, "group"))
2050 loc
->level
= AUTH_GROUP
;
2051 else if (!strcasecmp(value
, "system"))
2053 loc
->level
= AUTH_GROUP
;
2056 * Use the default system group if none is defined so far...
2059 if (NumSystemGroups
)
2060 NumSystemGroups
= 1;
2062 for (i
= 0; i
< NumSystemGroups
; i
++)
2063 AddName(loc
, SystemGroups
[i
]);
2066 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2069 else if (!strcasecmp(line
, "AuthGroupName"))
2070 AddName(loc
, value
);
2071 else if (!strcasecmp(line
, "Require"))
2074 * Apache synonym for AuthClass and AuthGroupName...
2078 * Require valid-user
2079 * Require group names
2080 * Require user names
2083 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2088 if (!strcasecmp(value
, "valid-user") ||
2089 !strcasecmp(value
, "user"))
2090 loc
->level
= AUTH_USER
;
2091 else if (!strcasecmp(value
, "group"))
2092 loc
->level
= AUTH_GROUP
;
2095 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2101 * Get the list of names from the line...
2104 for (value
= valptr
; *value
;)
2106 while (isspace(*value
& 255))
2109 if (*value
== '\"' || *value
== '\'')
2112 * Grab quoted name...
2115 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2122 * Grab literal name.
2125 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2131 AddName(loc
, value
);
2133 for (value
= valptr
; isspace(*value
& 255); value
++);
2136 else if (!strcasecmp(line
, "Satisfy"))
2138 if (!strcasecmp(value
, "all"))
2139 loc
->satisfy
= AUTH_SATISFY_ALL
;
2140 else if (!strcasecmp(value
, "any"))
2141 loc
->satisfy
= AUTH_SATISFY_ANY
;
2143 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2147 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2151 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2159 * 'read_policy()' - Read a <Policy name> definition.
2162 static int /* O - New line number or 0 on error */
2163 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2164 char *policy
, /* I - Location name/path */
2165 int linenum
) /* I - Current line number */
2167 int i
; /* Looping var */
2168 policy_t
*pol
; /* Policy */
2169 policyop_t
*op
; /* Policy operation */
2170 int num_ops
; /* Number of IPP operations */
2171 ipp_op_t ops
[100]; /* Operations */
2172 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2173 *value
, /* Value for directive */
2174 *valptr
; /* Pointer into value */
2178 * Create the policy...
2181 if ((pol
= AddPolicy(policy
)) == NULL
)
2185 * Read from the file...
2191 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2194 * Decode the directive...
2197 if (!strcasecmp(line
, "</Policy>"))
2200 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2205 else if (!strcasecmp(line
, "<Limit") && !op
)
2209 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2214 * Scan for IPP operation names...
2221 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2226 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2228 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2229 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2235 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2238 for (value
= valptr
; isspace(*value
& 255); value
++);
2242 * If none are specified, apply the policy to all operations...
2247 ops
[0] = IPP_ANY_OPERATION
;
2252 * Add a new policy for the first operation...
2255 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2257 else if (!strcasecmp(line
, "</Limit>") && op
)
2260 * Finish the current operation limit...
2266 * Copy the policy to the other operations...
2269 for (i
= 1; i
< num_ops
; i
++)
2270 AddPolicyOp(pol
, op
, ops
[i
]);
2275 else if (!strcasecmp(line
, "Authenticate") && op
)
2278 * Authenticate boolean
2281 if (!strcasecmp(value
, "on") ||
2282 !strcasecmp(value
, "yes") ||
2283 !strcasecmp(value
, "true"))
2284 op
->authenticate
= 1;
2285 else if (!strcasecmp(value
, "off") ||
2286 !strcasecmp(value
, "no") ||
2287 !strcasecmp(value
, "false"))
2288 op
->authenticate
= 0;
2290 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2293 else if (!strcasecmp(line
, "Order") && op
)
2296 * "Order Deny,Allow" or "Order Allow,Deny"...
2299 if (!strncasecmp(value
, "deny", 4))
2300 op
->order_type
= POLICY_ALLOW
;
2301 else if (!strncasecmp(value
, "allow", 5))
2302 op
->order_type
= POLICY_DENY
;
2304 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2307 else if ((!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny")) && op
)
2310 * Allow line, @group, @OWNER
2311 * Deny line, @group, @OWNER
2316 while (isspace(*value
& 255))
2319 if (*value
== '\"' || *value
== '\'')
2322 * Grab quoted name...
2325 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2332 * Grab literal name.
2335 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2341 if (!strcasecmp(line
, "Allow"))
2342 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2344 AddPolicyOpName(op
, POLICY_DENY
, value
);
2346 for (value
= valptr
; isspace(*value
& 255); value
++);
2350 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2353 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2357 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2365 * 'get_address()' - Get an address + port number from a line.
2368 static int /* O - 1 if address good, 0 if bad */
2369 get_address(const char *value
, /* I - Value string */
2370 unsigned defaddress
, /* I - Default address */
2371 int defport
, /* I - Default port */
2372 int deffamily
, /* I - Default family */
2373 http_addr_t
*address
) /* O - Socket address */
2375 char hostname
[256], /* Hostname or IP */
2376 portname
[256]; /* Port number or name */
2377 struct hostent
*host
; /* Host address */
2378 struct servent
*port
; /* Port number */
2382 * Initialize the socket address to the defaults...
2385 memset(address
, 0, sizeof(http_addr_t
));
2388 if (deffamily
== AF_INET6
)
2390 address
->ipv6
.sin6_family
= AF_INET6
;
2391 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2392 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2393 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2394 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2395 address
->ipv6
.sin6_port
= htons(defport
);
2398 #endif /* AF_INET6 */
2400 address
->ipv4
.sin_family
= AF_INET
;
2401 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2402 address
->ipv4
.sin_port
= htons(defport
);
2407 * If the address starts with a "/", it is a domain socket...
2412 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2414 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2418 address
->un
.sun_family
= AF_LOCAL
;
2419 strcpy(address
->un
.sun_path
, value
);
2423 #endif /* AF_LOCAL */
2426 * Try to grab a hostname and port number...
2429 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2432 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2435 * Hostname is a port number...
2438 strlcpy(portname
, hostname
, sizeof(portname
));
2449 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2454 * Decode the hostname and port number as needed...
2457 if (hostname
[0] && strcmp(hostname
, "*"))
2459 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2461 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2462 hstrerror(h_errno
));
2466 httpAddrLoad(host
, defport
, 0, address
);
2469 if (portname
[0] != '\0')
2471 if (isdigit(portname
[0] & 255))
2474 if (address
->addr
.sa_family
== AF_INET6
)
2475 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2477 #endif /* AF_INET6 */
2478 address
->ipv4
.sin_port
= htons(atoi(portname
));
2482 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2484 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2491 if (address
->addr
.sa_family
== AF_INET6
)
2492 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2494 #endif /* AF_INET6 */
2495 address
->ipv4
.sin_port
= htons(port
->s_port
);
2505 * 'get_addr_and_mask()' - Get an IP address and netmask.
2508 static int /* O - 1 on success, 0 on failure */
2509 get_addr_and_mask(const char *value
, /* I - String from config file */
2510 unsigned *ip
, /* O - Address value */
2511 unsigned *mask
) /* O - Mask value */
2513 int i
, /* Looping var */
2514 family
, /* Address family */
2515 ipcount
; /* Count of fields in address */
2516 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2518 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2519 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2520 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2521 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2526 * Get the address...
2529 memset(ip
, 0, sizeof(unsigned) * 4);
2531 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2535 * See if we have any values > 255; if so, this is an IPv6 address only.
2538 for (i
= 0; i
< ipcount
; i
++)
2544 #endif /* AF_INET6 */
2546 if ((value
= strchr(value
, '/')) != NULL
)
2549 * Get the netmask value(s)...
2553 memset(mask
, 0, sizeof(unsigned) * 4);
2554 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2555 mask
+ 2, mask
+ 3))
2562 if (family
== AF_INET6
)
2567 mask
[0] = 0xffffffff;
2569 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2572 mask
[1] = 0xffffffff;
2576 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2579 mask
[1] = 0xffffffff;
2583 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2588 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2591 #endif /* AF_INET6 */
2596 mask
[0] = 0xffffffff;
2598 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2601 mask
[1] = 0xffffffff;
2605 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2608 mask
[1] = 0xffffffff;
2612 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2617 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2628 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2631 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2634 if ((ip
[0] & ~mask
[0]) != 0 ||
2635 (ip
[1] & ~mask
[1]) != 0 ||
2636 (ip
[2] & ~mask
[2]) != 0 ||
2637 (ip
[3] & ~mask
[3]) != 0)
2645 * 'get_operation()' - Get an IPP opcode from an operation name...
2648 static ipp_op_t
/* O - Operation code or -1 on error */
2649 get_operation(const char *name
) /* I - Operating name */
2651 int i
; /* Looping var */
2652 static const char * const ipp_ops
[] = /* List of standard operations */
2656 /* 0x0002 */ "print-job",
2657 /* 0x0003 */ "print-uri",
2658 /* 0x0004 */ "validate-job",
2659 /* 0x0005 */ "create-job",
2660 /* 0x0006 */ "send-document",
2661 /* 0x0007 */ "send-uri",
2662 /* 0x0008 */ "cancel-job",
2663 /* 0x0009 */ "get-job-attributes",
2664 /* 0x000a */ "get-jobs",
2665 /* 0x000b */ "get-printer-attributes",
2666 /* 0x000c */ "hold-job",
2667 /* 0x000d */ "release-job",
2668 /* 0x000e */ "restart-job",
2670 /* 0x0010 */ "pause-printer",
2671 /* 0x0011 */ "resume-printer",
2672 /* 0x0012 */ "purge-jobs",
2673 /* 0x0013 */ "set-printer-attributes",
2674 /* 0x0014 */ "set-job-attributes",
2675 /* 0x0015 */ "get-printer-supported-values",
2676 /* 0x0016 */ "create-printer-subscription",
2677 /* 0x0017 */ "create-job-subscription",
2678 /* 0x0018 */ "get-subscription-attributes",
2679 /* 0x0019 */ "get-subscriptions",
2680 /* 0x001a */ "renew-subscription",
2681 /* 0x001b */ "cancel-subscription",
2682 /* 0x001c */ "get-notifications",
2683 /* 0x001d */ "send-notifications",
2687 /* 0x0021 */ "get-print-support-files",
2688 /* 0x0022 */ "enable-printer",
2689 /* 0x0023 */ "disable-printer",
2690 /* 0x0024 */ "pause-printer-after-current-job",
2691 /* 0x0025 */ "hold-new-jobs",
2692 /* 0x0026 */ "release-held-new-jobs",
2693 /* 0x0027 */ "deactivate-printer",
2694 /* 0x0028 */ "activate-printer",
2695 /* 0x0029 */ "restart-printer",
2696 /* 0x002a */ "shutdown-printer",
2697 /* 0x002b */ "startup-printer",
2698 /* 0x002c */ "reprocess-job",
2699 /* 0x002d */ "cancel-current-job",
2700 /* 0x002e */ "suspend-current-job",
2701 /* 0x002f */ "resume-job",
2702 /* 0x0030 */ "promote-job",
2703 /* 0x0031 */ "schedule-job-after"
2705 *cups_ops
[] = /* List of CUPS operations */
2707 /* 0x4001 */ "cups-get-default",
2708 /* 0x4002 */ "cups-get-printers",
2709 /* 0x4003 */ "cups-add-printer",
2710 /* 0x4004 */ "cups-delete-printer",
2711 /* 0x4005 */ "cups-get-classes",
2712 /* 0x4006 */ "cups-add-class",
2713 /* 0x4007 */ "cups-delete-class",
2714 /* 0x4008 */ "cups-accept-jobs",
2715 /* 0x4009 */ "cups-reject-jobs",
2716 /* 0x400a */ "cups-set-default",
2717 /* 0x400b */ "cups-get-devices",
2718 /* 0x400c */ "cups-get-ppds",
2719 /* 0x400d */ "cups-move-job",
2720 /* 0x400e */ "cups-add-device",
2721 /* 0x400f */ "cups-delete-device"
2725 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2726 if (!strcasecmp(name
, ipp_ops
[i
]))
2727 return ((ipp_op_t
)i
);
2729 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2730 if (!strcasecmp(name
, cups_ops
[i
]))
2731 return ((ipp_op_t
)(i
+ 0x4001));
2733 return ((ipp_op_t
)-1);
2739 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2740 * required by SSLSetCertificate.
2742 * For now we assumes that there is exactly one SecIdentity in the
2743 * keychain - i.e. there is exactly one matching cert/private key pair.
2744 * In the future we will search a keychain for a SecIdentity matching a
2745 * specific criteria. We also skip the operation of adding additional
2746 * non-signing certs from the keychain to the CFArrayRef.
2748 * To create a self-signed certificate for testing use the certtool.
2749 * Executing the following as root will do it:
2751 * certtool c c v k=CUPS
2755 CDSAGetServerCerts(void)
2757 OSStatus err
; /* Error info */
2758 SecKeychainRef kcRef
; /* Keychain reference */
2759 SecIdentitySearchRef srchRef
; /* Search reference */
2760 SecIdentityRef identity
; /* Identity */
2761 CFArrayRef ca
; /* Certificate array */
2768 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2771 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2772 ServerCertificate
, err
);
2776 * Search for "any" identity matching specified key use;
2777 * in this app, we expect there to be exactly one.
2780 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2784 "Cannot find signing key in keychain \"%s\", error %d",
2785 ServerCertificate
, err
);
2788 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2792 "Cannot find signing key in keychain \"%s\", error %d",
2793 ServerCertificate
, err
);
2796 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2797 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2801 * Found one. Place it in a CFArray.
2802 * TBD: snag other (non-identity) certs from keychain and add them
2806 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2809 LogMessage(L_ERROR
, "CFArrayCreate error");
2812 /*CFRelease(identity);*/
2815 /*CFRelease(srchRef);*/
2818 /*CFRelease(kcRef);*/
2823 #endif /* HAVE_CDSASSL */