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
);
420 DefaultAuthType
= AUTH_BASIC
;
423 * Read the configuration file...
426 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
429 status
= read_configuration(fp
);
442 * Use the default system group if none was supplied in cupsd.conf...
445 if (NumSystemGroups
== 0)
449 * Get the access control list for browsing...
452 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
455 * Open the system log for cupsd if necessary...
459 if (strcmp(AccessLog
, "syslog") == 0 ||
460 strcmp(ErrorLog
, "syslog") == 0 ||
461 strcmp(PageLog
, "syslog") == 0)
462 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
463 #endif /* HAVE_VSYSLOG */
466 * Log the configuration file that was used...
469 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
472 * Check that we have at least one listen/port line; if not, report this
473 * as an error and exit!
476 if (NumListeners
== 0)
482 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
488 cupsdEndProcess(getpid(), 0);
492 * Set the default locale using the language and charset...
495 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
498 * Update all relative filenames to include the full path from ServerRoot...
501 if (DocumentRoot
[0] != '/')
502 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
504 if (RequestRoot
[0] != '/')
505 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
507 if (ServerBin
[0] != '/')
508 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
511 if (ServerCertificate
[0] != '/')
512 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
514 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
515 chown(ServerCertificate
, RunUser
, Group
);
516 chmod(ServerCertificate
, ConfigFilePerm
);
518 if (ServerKey
[0] != '/')
519 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
521 chown(ServerKey
, RunUser
, Group
);
522 chmod(ServerKey
, ConfigFilePerm
);
523 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
524 #endif /* HAVE_SSL */
527 * Make sure that directories and config files are owned and
528 * writable by the user and group in the cupsd.conf file...
531 chown(StateDir
, RunUser
, Group
);
532 chmod(StateDir
, 0775);
534 snprintf(temp
, sizeof(temp
), "%s/certs", StateDir
);
537 chown(temp
, RunUser
, Group
);
540 snprintf(temp
, sizeof(temp
), "%s/ppd", StateDir
);
543 chown(temp
, RunUser
, Group
);
546 chown(ServerRoot
, RunUser
, Group
);
547 chmod(ServerRoot
, 0775);
549 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
552 chown(temp
, RunUser
, Group
);
555 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
558 chown(temp
, RunUser
, Group
);
561 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
562 chown(temp
, RunUser
, Group
);
563 chmod(temp
, ConfigFilePerm
);
565 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
566 chown(temp
, RunUser
, Group
);
570 chmod(temp
, ConfigFilePerm
);
571 #endif /* __APPLE__ */
573 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
574 chown(temp
, RunUser
, Group
);
578 chmod(temp
, ConfigFilePerm
);
579 #endif /* __APPLE__ */
581 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
582 chown(temp
, User
, Group
);
586 * Make sure the request and temporary directories have the right
590 chown(RequestRoot
, RunUser
, Group
);
591 chmod(RequestRoot
, 0710);
593 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) ||
597 * Update ownership and permissions if the CUPS temp directory
598 * is under the spool directory or does not exist...
601 if (access(TempDir
, 0))
602 mkdir(TempDir
, 01770);
604 chown(TempDir
, RunUser
, Group
);
605 chmod(TempDir
, 01770);
608 if (!strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)))
611 * Clean out the temporary directory...
614 cups_dir_t
*dir
; /* Temporary directory */
615 cups_dentry_t
*dent
; /* Directory entry */
616 char tempfile
[1024]; /* Temporary filename */
619 if ((dir
= cupsDirOpen(TempDir
)) != NULL
)
621 LogMessage(L_INFO
, "Cleaning out old temporary files in \"%s\"...",
624 while ((dent
= cupsDirRead(dir
)) != NULL
)
626 snprintf(tempfile
, sizeof(tempfile
), "%s/%s", TempDir
, dent
->filename
);
628 if (unlink(tempfile
))
629 LogMessage(L_ERROR
, "Unable to remove temporary file \"%s\" - %s",
630 tempfile
, strerror(errno
));
632 LogMessage(L_DEBUG
, "Removed temporary file \"%s\"...", tempfile
);
638 LogMessage(L_ERROR
, "Unable to open temporary directory \"%s\" - %s",
639 TempDir
, strerror(errno
));
643 * Check the MaxClients setting, and then allocate memory for it...
646 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
649 LogMessage(L_INFO
, "MaxClients limited to 1/3 (%d) of the file descriptor limit (%d)...",
652 MaxClients
= MaxFDs
/ 3;
655 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
657 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
658 MaxClients
, strerror(errno
));
662 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
665 * Check the MaxActiveJobs setting; limit to 1/3 the available
666 * file descriptors, since we need a pipe for each job...
669 if (MaxActiveJobs
> (MaxFDs
/ 3))
670 MaxActiveJobs
= MaxFDs
/ 3;
672 if (Classification
&& strcasecmp(Classification
, "none") == 0)
673 ClearString(&Classification
);
676 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
679 * Update the MaxClientsPerHost value, as needed...
682 if (MaxClientsPerHost
<= 0)
683 MaxClientsPerHost
= MaxClients
;
685 if (MaxClientsPerHost
> MaxClients
)
686 MaxClientsPerHost
= MaxClients
;
688 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
692 * Update the default policy, as needed...
696 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
698 DefaultPolicyPtr
= NULL
;
700 if (!DefaultPolicyPtr
)
702 policy_t
*p
; /* New policy */
703 policyop_t
*po
; /* New policy operation */
704 char groupname
[255]; /* Group name */
708 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
710 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
711 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
714 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
716 DefaultPolicyPtr
= p
= AddPolicy("default");
718 LogMessage(L_INFO
, "<Policy default>");
719 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
720 "Release-Job Restart-Job Purge-Jobs "
721 "Set-Job-Attributes Create-Job-Subscription "
722 "Renew-Subscription Cancel-Subscription "
723 "Get-Notifications Reprocess-Job Cancel-Current-Job "
724 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
725 LogMessage(L_INFO
, "Order Allow,Deny");
726 LogMessage(L_INFO
, "Allow @OWNER");
728 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
729 po
->order_type
= POLICY_DENY
;
731 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
733 for (i
= 0; i
< NumSystemGroups
; i
++)
735 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
736 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
737 LogMessage(L_INFO
, "Allow @%s", groupname
);
740 AddPolicyOp(p
, po
, IPP_SEND_URI
);
741 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
742 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
743 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
744 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
745 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
746 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
747 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
748 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
749 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
750 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
751 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
752 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
753 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
754 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
755 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
757 LogMessage(L_INFO
, "</Limit>");
759 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
760 "Set-Printer-Attributes Enable-Printer "
761 "Disable-Printer Pause-Printer-After-Current-Job "
762 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
763 "Activate-Printer Restart-Printer Shutdown-Printer "
764 "Startup-Printer Promote-Job Schedule-Job-After "
765 "CUPS-Add-Printer CUPS-Delete-Printer "
766 "CUPS-Add-Class CUPS-Delete-Class "
767 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
768 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
769 LogMessage(L_INFO
, "Order Allow,Deny");
770 LogMessage(L_INFO
, "Authenticate yes");
772 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
773 po
->order_type
= POLICY_DENY
;
774 po
->authenticate
= 1;
776 for (i
= 0; i
< NumSystemGroups
; i
++)
778 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
779 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
780 LogMessage(L_INFO
, "Allow @%s", groupname
);
783 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
784 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
785 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
786 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
787 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
788 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
789 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
790 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
791 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
792 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
793 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
794 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
795 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
796 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
797 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
798 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
799 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
800 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
801 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
802 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
803 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
804 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
805 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
807 LogMessage(L_INFO
, "</Limit>");
809 LogMessage(L_INFO
, "<Limit All>");
810 LogMessage(L_INFO
, "Order Deny,Allow");
812 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
813 po
->order_type
= POLICY_ALLOW
;
815 LogMessage(L_INFO
, "</Limit>");
816 LogMessage(L_INFO
, "</Policy>");
821 * If we are doing a full reload or the server root has changed, flush
822 * the jobs, printers, etc. and start from scratch...
825 if (NeedReload
== RELOAD_ALL
||
826 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
827 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
829 LogMessage(L_INFO
, "Full reload is required.");
839 DefaultPrinter
= NULL
;
841 if (MimeDatabase
!= NULL
)
842 mimeDelete(MimeDatabase
);
846 for (i
= 0; i
< NumMimeTypes
; i
++)
847 free((void *)MimeTypes
[i
]);
853 * Read the MIME type and conversion database...
856 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
858 MimeDatabase
= mimeLoad(ServerRoot
, temp
);
860 LogMessage(L_INFO
, "Loaded MIME database from \'%s\': %d types, %d filters...",
861 ServerRoot
, MimeDatabase
->num_types
, MimeDatabase
->num_filters
);
864 * Create a list of MIME types for the document-format-supported
868 NumMimeTypes
= MimeDatabase
->num_types
;
869 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
872 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
874 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
876 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
877 MimeDatabase
->types
[i
]->type
);
879 MimeTypes
[i
] = strdup(type
);
882 if (i
< NumMimeTypes
)
883 MimeTypes
[i
] = strdup("application/octet-stream");
889 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
893 * Load printers and classes...
902 * Load queued jobs...
907 LogMessage(L_INFO
, "Full reload complete.");
913 LogMessage(L_INFO
, "Partial reload complete.");
917 * Reset the reload state...
920 NeedReload
= RELOAD_NONE
;
922 ClearString(&old_serverroot
);
923 ClearString(&old_requestroot
);
926 * Startup the server and return...
936 * 'read_configuration()' - Read a configuration file.
939 static int /* O - 1 on success, 0 on failure */
940 read_configuration(cups_file_t
*fp
) /* I - File to read from */
942 int i
; /* Looping var */
943 int linenum
; /* Current line number */
944 char line
[HTTP_MAX_BUFFER
], /* Line from file */
945 temp
[HTTP_MAX_BUFFER
], /* Temporary buffer for value */
946 temp2
[HTTP_MAX_BUFFER
], /* Temporary buffer 2 for value */
947 *ptr
, /* Pointer into line/temp */
948 *value
; /* Pointer to value */
949 int valuelen
; /* Length of value */
950 var_t
*var
; /* Current variable */
951 unsigned ip
[4], /* Address value */
952 mask
[4]; /* Netmask value */
953 dirsvc_relay_t
*relay
; /* Relay data */
954 dirsvc_poll_t
*poll
; /* Polling data */
955 http_addr_t polladdr
; /* Polling address */
956 location_t
*location
; /* Browse location */
957 cups_file_t
*incfile
; /* Include file */
958 char incname
[1024]; /* Include filename */
962 * Loop through each line in the file...
967 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
970 * Decode the directive...
973 if (!strcasecmp(line
, "Include"))
980 strlcpy(incname
, value
, sizeof(incname
));
982 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
984 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
985 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
986 incname
, strerror(errno
));
989 read_configuration(incfile
);
990 cupsFileClose(incfile
);
993 else if (!strcasecmp(line
, "<Location"))
1001 linenum
= read_location(fp
, value
, linenum
);
1007 LogMessage(L_ERROR
, "Syntax error on line %d.",
1012 else if (!strcasecmp(line
, "<Policy"))
1020 linenum
= read_policy(fp
, value
, linenum
);
1026 LogMessage(L_ERROR
, "Syntax error on line %d.",
1031 else if (!strcasecmp(line
, "DefaultAuthType"))
1034 * DefaultAuthType {none,basic,digest,basicdigest}
1037 if (!strcasecmp(value
, "none"))
1038 DefaultAuthType
= AUTH_NONE
;
1039 else if (!strcasecmp(value
, "basic"))
1040 DefaultAuthType
= AUTH_BASIC
;
1041 else if (!strcasecmp(value
, "digest"))
1042 DefaultAuthType
= AUTH_DIGEST
;
1043 else if (!strcasecmp(value
, "basicdigest"))
1044 DefaultAuthType
= AUTH_BASICDIGEST
;
1046 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1049 else if (!strcasecmp(line
, "Port") || !strcasecmp(line
, "Listen"))
1052 * Add a listening address to the list...
1055 listener_t
*lis
; /* New listeners array */
1058 if (NumListeners
== 0)
1059 lis
= malloc(sizeof(listener_t
));
1061 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1065 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1066 line
, linenum
, strerror(errno
));
1071 lis
+= NumListeners
;
1073 memset(lis
, 0, sizeof(listener_t
));
1075 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1077 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1080 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1081 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1082 ntohs(lis
->address
.ipv6
.sin6_port
));
1084 #endif /* AF_INET6 */
1085 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1086 ntohs(lis
->address
.ipv4
.sin_port
));
1090 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1094 else if (!strcasecmp(line
, "SSLPort") || !strcasecmp(line
, "SSLListen"))
1097 * Add a listening address to the list...
1100 listener_t
*lis
; /* New listeners array */
1103 if (NumListeners
== 0)
1104 lis
= malloc(sizeof(listener_t
));
1106 lis
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1110 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1111 line
, linenum
, strerror(errno
));
1116 lis
+= NumListeners
;
1118 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(lis
->address
)))
1120 httpAddrString(&(lis
->address
), temp
, sizeof(temp
));
1123 if (lis
->address
.addr
.sa_family
== AF_INET6
)
1124 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", temp
,
1125 ntohs(lis
->address
.ipv6
.sin6_port
));
1127 #endif /* AF_INET6 */
1128 LogMessage(L_INFO
, "Listening to %s:%d", temp
,
1129 ntohs(lis
->address
.ipv4
.sin_port
));
1130 lis
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1134 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", line
,
1137 #endif /* HAVE_SSL */
1138 else if (!strcasecmp(line
, "BrowseAddress"))
1141 * Add a browse address to the list...
1144 dirsvc_addr_t
*dira
; /* New browse address array */
1147 if (NumBrowsers
== 0)
1148 dira
= malloc(sizeof(dirsvc_addr_t
));
1150 dira
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1154 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1155 linenum
, strerror(errno
));
1160 dira
+= NumBrowsers
;
1162 memset(dira
, 0, sizeof(dirsvc_addr_t
));
1164 if (!strcasecmp(value
, "@LOCAL"))
1167 * Send browse data to all local interfaces...
1170 strcpy(dira
->iface
, "*");
1173 else if (!strncasecmp(value
, "@IF(", 4))
1176 * Send browse data to the named interface...
1179 strlcpy(dira
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1181 ptr
= dira
->iface
+ strlen(dira
->iface
) - 1;
1187 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(dira
->to
)))
1189 httpAddrString(&(dira
->to
), temp
, sizeof(temp
));
1192 if (dira
->to
.addr
.sa_family
== AF_INET6
)
1193 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", temp
,
1194 ntohs(dira
->to
.ipv6
.sin6_port
));
1196 #endif /* AF_INET6 */
1197 LogMessage(L_INFO
, "Sending browsing info to %s:%d", temp
,
1198 ntohs(dira
->to
.ipv4
.sin_port
));
1203 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1206 else if (!strcasecmp(line
, "BrowseOrder"))
1209 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1212 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1213 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1215 if (location
== NULL
)
1216 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1217 else if (!strncasecmp(value
, "deny", 4))
1218 location
->order_type
= AUTH_ALLOW
;
1219 else if (!strncasecmp(value
, "allow", 5))
1220 location
->order_type
= AUTH_DENY
;
1222 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1225 else if (!strcasecmp(line
, "BrowseProtocols"))
1228 * "BrowseProtocol name [... name]"
1231 BrowseProtocols
= 0;
1235 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1236 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1239 if (value
[valuelen
])
1241 value
[valuelen
] = '\0';
1245 if (!strcasecmp(value
, "cups"))
1246 BrowseProtocols
|= BROWSE_CUPS
;
1247 else if (!strcasecmp(value
, "slp"))
1248 BrowseProtocols
|= BROWSE_SLP
;
1249 else if (!strcasecmp(value
, "ldap"))
1250 BrowseProtocols
|= BROWSE_LDAP
;
1251 else if (!strcasecmp(value
, "all"))
1252 BrowseProtocols
|= BROWSE_ALL
;
1255 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1260 for (value
+= valuelen
; *value
; value
++)
1261 if (!isspace(*value
) || *value
!= ',')
1265 else if (!strcasecmp(line
, "BrowseAllow") ||
1266 !strcasecmp(line
, "BrowseDeny"))
1269 * BrowseAllow [From] host/ip...
1270 * BrowseDeny [From] host/ip...
1273 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1274 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1276 if (location
== NULL
)
1277 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1280 if (!strncasecmp(value
, "from ", 5))
1283 * Strip leading "from"...
1288 while (isspace(*value
))
1293 * Figure out what form the allow/deny address takes:
1304 * nnn.nnn.nnn.nnn/mm
1305 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1308 if (!strcasecmp(value
, "all"))
1314 if (!strcasecmp(line
, "BrowseAllow"))
1315 AllowIP(location
, zeros
, zeros
);
1317 DenyIP(location
, zeros
, zeros
);
1319 else if (!strcasecmp(value
, "none"))
1325 if (!strcasecmp(line
, "BrowseAllow"))
1326 AllowIP(location
, ones
, zeros
);
1328 DenyIP(location
, ones
, zeros
);
1330 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1333 * Host or domain name...
1336 if (value
[0] == '*')
1339 if (!strcasecmp(line
, "BrowseAllow"))
1340 AllowHost(location
, value
);
1342 DenyHost(location
, value
);
1347 * One of many IP address forms...
1350 if (!get_addr_and_mask(value
, ip
, mask
))
1352 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1357 if (!strcasecmp(line
, "BrowseAllow"))
1358 AllowIP(location
, ip
, mask
);
1360 DenyIP(location
, ip
, mask
);
1364 else if (!strcasecmp(line
, "BrowseRelay"))
1367 * BrowseRelay [from] source [to] destination
1371 relay
= malloc(sizeof(dirsvc_relay_t
));
1373 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1377 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1378 linenum
, strerror(errno
));
1385 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1387 if (!strncasecmp(value
, "from ", 5))
1390 * Strip leading "from"...
1395 while (isspace(*value
))
1400 * Figure out what form the from address takes:
1409 * nnn.nnn.nnn.nnn/mm
1410 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1413 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1416 * Host or domain name...
1419 if (value
[0] == '*')
1422 strlcpy(temp
, value
, sizeof(temp
));
1423 if ((ptr
= strchr(temp
, ' ')) != NULL
)
1426 relay
->from
.type
= AUTH_NAME
;
1427 relay
->from
.mask
.name
.name
= strdup(temp
);
1428 relay
->from
.mask
.name
.length
= strlen(temp
);
1433 * One of many IP address forms...
1436 if (!get_addr_and_mask(value
, ip
, mask
))
1438 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1443 relay
->from
.type
= AUTH_IP
;
1444 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1445 sizeof(relay
->from
.mask
.ip
.address
));
1446 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1447 sizeof(relay
->from
.mask
.ip
.netmask
));
1451 * Skip value and trailing whitespace...
1454 for (; *value
; value
++)
1455 if (isspace(*value
))
1458 while (isspace(*value
))
1461 if (!strncasecmp(value
, "to ", 3))
1464 * Strip leading "to"...
1469 while (isspace(*value
))
1474 * Get "to" address and port...
1477 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1479 httpAddrString(&(relay
->to
), temp
, sizeof(temp
));
1481 if (relay
->from
.type
== AUTH_IP
)
1482 snprintf(temp2
, sizeof(temp2
), "%u.%u.%u.%u/%u.%u.%u.%u",
1483 relay
->from
.mask
.ip
.address
[0],
1484 relay
->from
.mask
.ip
.address
[1],
1485 relay
->from
.mask
.ip
.address
[2],
1486 relay
->from
.mask
.ip
.address
[3],
1487 relay
->from
.mask
.ip
.netmask
[0],
1488 relay
->from
.mask
.ip
.netmask
[1],
1489 relay
->from
.mask
.ip
.netmask
[2],
1490 relay
->from
.mask
.ip
.netmask
[3]);
1492 strlcpy(temp2
, relay
->from
.mask
.name
.name
, sizeof(temp2
));
1495 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1496 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1497 ntohs(relay
->to
.ipv6
.sin6_port
));
1499 #endif /* AF_INET6 */
1500 LogMessage(L_INFO
, "Relaying from %s to %s:%d", temp
, temp2
,
1501 ntohs(relay
->to
.ipv4
.sin_port
));
1507 if (relay
->from
.type
== AUTH_NAME
)
1508 free(relay
->from
.mask
.name
.name
);
1510 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1513 else if (!strcasecmp(line
, "BrowsePoll"))
1516 * BrowsePoll address[:port]
1520 poll
= malloc(sizeof(dirsvc_poll_t
));
1522 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1526 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1527 linenum
, strerror(errno
));
1535 * Get poll address and port...
1538 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1541 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1543 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1546 if (polladdr
.addr
.sa_family
== AF_INET6
)
1547 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1549 #endif /* AF_INET6 */
1550 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1552 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1555 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1557 else if (!strcasecmp(line
, "User"))
1560 * User ID to run as...
1563 if (isdigit(value
[0]))
1567 struct passwd
*p
; /* Password information */
1570 p
= getpwnam(value
);
1575 LogMessage(L_WARN
, "Unknown username \"%s\"", value
);
1578 else if (!strcasecmp(line
, "Group"))
1581 * Group ID to run as...
1584 if (isdigit(value
[0]))
1585 Group
= atoi(value
);
1588 struct group
*g
; /* Group information */
1591 g
= getgrnam(value
);
1596 LogMessage(L_WARN
, "Unknown groupname \"%s\"", value
);
1599 else if (!strcasecmp(line
, "SystemGroup"))
1602 * System (admin) group(s)...
1605 char *valueptr
, /* Pointer into value */
1606 quote
; /* Quote character */
1609 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1611 if (*value
== '\'' || *value
== '\"')
1614 * Scan quoted name...
1619 for (valueptr
= value
; *valueptr
; valueptr
++)
1620 if (*valueptr
== quote
)
1626 * Scan space or comma-delimited name...
1629 for (valueptr
= value
; *valueptr
; valueptr
++)
1630 if (isspace(*valueptr
) || *valueptr
== ',')
1637 SetString(SystemGroups
+ i
, value
);
1641 while (*value
== ',' || isspace(*value
))
1646 NumSystemGroups
= i
;
1648 else if (!strcasecmp(line
, "HostNameLookups"))
1651 * Do hostname lookups?
1654 if (!strcasecmp(value
, "off"))
1655 HostNameLookups
= 0;
1656 else if (!strcasecmp(value
, "on"))
1657 HostNameLookups
= 1;
1658 else if (!strcasecmp(value
, "double"))
1659 HostNameLookups
= 2;
1661 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1664 else if (!strcasecmp(line
, "LogLevel"))
1667 * Amount of logging to do...
1670 if (!strcasecmp(value
, "debug2"))
1671 LogLevel
= L_DEBUG2
;
1672 else if (!strcasecmp(value
, "debug"))
1674 else if (!strcasecmp(value
, "info"))
1676 else if (!strcasecmp(value
, "notice"))
1677 LogLevel
= L_NOTICE
;
1678 else if (!strcasecmp(value
, "warn"))
1680 else if (!strcasecmp(value
, "error"))
1682 else if (!strcasecmp(value
, "crit"))
1684 else if (!strcasecmp(value
, "alert"))
1686 else if (!strcasecmp(value
, "emerg"))
1688 else if (!strcasecmp(value
, "none"))
1691 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1693 else if (!strcasecmp(line
, "PrintcapFormat"))
1696 * Format of printcap file?
1699 if (!strcasecmp(value
, "bsd"))
1700 PrintcapFormat
= PRINTCAP_BSD
;
1701 else if (!strcasecmp(value
, "solaris"))
1702 PrintcapFormat
= PRINTCAP_SOLARIS
;
1704 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1707 else if (!strcasecmp(line
, "ServerTokens"))
1710 * Set the string used for the Server header...
1713 struct utsname plat
; /* Platform info */
1718 if (!strcasecmp(value
, "ProductOnly"))
1719 SetString(&ServerHeader
, "CUPS");
1720 else if (!strcasecmp(value
, "Major"))
1721 SetString(&ServerHeader
, "CUPS/1");
1722 else if (!strcasecmp(value
, "Minor"))
1723 SetString(&ServerHeader
, "CUPS/1.1");
1724 else if (!strcasecmp(value
, "Minimal"))
1725 SetString(&ServerHeader
, CUPS_MINIMAL
);
1726 else if (!strcasecmp(value
, "OS"))
1727 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1728 else if (!strcasecmp(value
, "Full"))
1729 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1730 else if (!strcasecmp(value
, "None"))
1731 ClearString(&ServerHeader
);
1733 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1738 * Find a simple variable in the list...
1741 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1742 if (!strcasecmp(line
, var
->name
))
1748 * Unknown directive! Output an error message and continue...
1751 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", line
,
1761 char *units
; /* Units */
1764 n
= strtol(value
, &units
, 0);
1766 if (units
&& *units
)
1768 if (tolower(units
[0] & 255) == 'g')
1769 n
*= 1024 * 1024 * 1024;
1770 else if (tolower(units
[0] & 255) == 'm')
1772 else if (tolower(units
[0] & 255) == 'k')
1774 else if (tolower(units
[0] & 255) == 't')
1778 *((int *)var
->ptr
) = n
;
1783 if (!strcasecmp(value
, "true") ||
1784 !strcasecmp(value
, "on") ||
1785 !strcasecmp(value
, "enabled") ||
1786 !strcasecmp(value
, "yes") ||
1788 *((int *)var
->ptr
) = TRUE
;
1789 else if (!strcasecmp(value
, "false") ||
1790 !strcasecmp(value
, "off") ||
1791 !strcasecmp(value
, "disabled") ||
1792 !strcasecmp(value
, "no") ||
1793 !strcasecmp(value
, "0"))
1794 *((int *)var
->ptr
) = FALSE
;
1796 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1801 SetString((char **)var
->ptr
, value
);
1812 * 'read_location()' - Read a <Location path> definition.
1815 static int /* O - New line number or 0 on error */
1816 read_location(cups_file_t
*fp
, /* I - Configuration file */
1817 char *location
, /* I - Location name/path */
1818 int linenum
) /* I - Current line number */
1820 int i
; /* Looping var */
1821 location_t
*loc
, /* New location */
1822 *parent
; /* Parent location */
1823 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1824 *value
, /* Value for directive */
1825 *valptr
; /* Pointer into value */
1826 unsigned ip
[4], /* IP address components */
1827 mask
[4]; /* IP netmask components */
1830 if ((parent
= AddLocation(location
)) == NULL
)
1833 parent
->limit
= AUTH_LIMIT_ALL
;
1836 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
1839 * Decode the directive...
1842 if (!strcasecmp(line
, "</Location>"))
1844 else if (!strcasecmp(line
, "<Limit") ||
1845 !strcasecmp(line
, "<LimitExcept"))
1849 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
1853 if ((loc
= CopyLocation(&parent
)) == NULL
)
1859 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
1864 if (!strcmp(value
, "ALL"))
1865 loc
->limit
= AUTH_LIMIT_ALL
;
1866 else if (!strcmp(value
, "GET"))
1867 loc
->limit
|= AUTH_LIMIT_GET
;
1868 else if (!strcmp(value
, "HEAD"))
1869 loc
->limit
|= AUTH_LIMIT_HEAD
;
1870 else if (!strcmp(value
, "OPTIONS"))
1871 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1872 else if (!strcmp(value
, "POST"))
1873 loc
->limit
|= AUTH_LIMIT_POST
;
1874 else if (!strcmp(value
, "PUT"))
1875 loc
->limit
|= AUTH_LIMIT_PUT
;
1876 else if (!strcmp(value
, "TRACE"))
1877 loc
->limit
|= AUTH_LIMIT_TRACE
;
1879 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1882 for (value
= valptr
; isspace(*value
& 255); value
++);
1885 if (!strcasecmp(line
, "<LimitExcept"))
1886 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1888 parent
->limit
&= ~loc
->limit
;
1890 else if (!strcasecmp(line
, "</Limit>"))
1892 else if (!strcasecmp(line
, "Encryption"))
1895 * "Encryption xxx" - set required encryption level...
1898 if (!strcasecmp(value
, "never"))
1899 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1900 else if (!strcasecmp(value
, "always"))
1902 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1903 "Using \"required\" instead.", value
, linenum
);
1905 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1907 else if (!strcasecmp(value
, "required"))
1908 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1909 else if (!strcasecmp(value
, "ifrequested"))
1910 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1912 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1915 else if (!strcasecmp(line
, "Order"))
1918 * "Order Deny,Allow" or "Order Allow,Deny"...
1921 if (!strncasecmp(value
, "deny", 4))
1922 loc
->order_type
= AUTH_ALLOW
;
1923 else if (!strncasecmp(value
, "allow", 5))
1924 loc
->order_type
= AUTH_DENY
;
1926 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1929 else if (!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny"))
1932 * Allow [From] host/ip...
1933 * Deny [From] host/ip...
1936 if (!strncasecmp(value
, "from", 4))
1939 * Strip leading "from"...
1944 while (isspace(*value
& 255))
1949 * Figure out what form the allow/deny address takes:
1960 * nnn.nnn.nnn.nnn/mm
1961 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1964 if (!strcasecmp(value
, "all"))
1970 if (!strcasecmp(line
, "Allow"))
1971 AllowIP(loc
, zeros
, zeros
);
1973 DenyIP(loc
, zeros
, zeros
);
1975 else if (!strcasecmp(value
, "none"))
1981 if (!strcasecmp(line
, "Allow"))
1982 AllowIP(loc
, ones
, zeros
);
1984 DenyIP(loc
, ones
, zeros
);
1986 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1989 * Host or domain name...
1992 if (value
[0] == '*')
1995 if (!strcasecmp(line
, "Allow"))
1996 AllowHost(loc
, value
);
1998 DenyHost(loc
, value
);
2003 * One of many IP address forms...
2006 if (!get_addr_and_mask(value
, ip
, mask
))
2008 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2013 if (!strcasecmp(line
, "Allow"))
2014 AllowIP(loc
, ip
, mask
);
2016 DenyIP(loc
, ip
, mask
);
2019 else if (!strcasecmp(line
, "AuthType"))
2022 * AuthType {none,basic,digest,basicdigest}
2025 if (!strcasecmp(value
, "none"))
2027 loc
->type
= AUTH_NONE
;
2028 loc
->level
= AUTH_ANON
;
2030 else if (!strcasecmp(value
, "basic"))
2032 loc
->type
= AUTH_BASIC
;
2034 if (loc
->level
== AUTH_ANON
)
2035 loc
->level
= AUTH_USER
;
2037 else if (!strcasecmp(value
, "digest"))
2039 loc
->type
= AUTH_DIGEST
;
2041 if (loc
->level
== AUTH_ANON
)
2042 loc
->level
= AUTH_USER
;
2044 else if (!strcasecmp(value
, "basicdigest"))
2046 loc
->type
= AUTH_BASICDIGEST
;
2048 if (loc
->level
== AUTH_ANON
)
2049 loc
->level
= AUTH_USER
;
2052 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2055 else if (!strcasecmp(line
, "AuthClass"))
2058 * AuthClass anonymous, user, system, group
2061 if (!strcasecmp(value
, "anonymous"))
2063 loc
->type
= AUTH_NONE
;
2064 loc
->level
= AUTH_ANON
;
2066 else if (!strcasecmp(value
, "user"))
2067 loc
->level
= AUTH_USER
;
2068 else if (!strcasecmp(value
, "group"))
2069 loc
->level
= AUTH_GROUP
;
2070 else if (!strcasecmp(value
, "system"))
2072 loc
->level
= AUTH_GROUP
;
2075 * Use the default system group if none is defined so far...
2078 if (NumSystemGroups
)
2079 NumSystemGroups
= 1;
2081 for (i
= 0; i
< NumSystemGroups
; i
++)
2082 AddName(loc
, SystemGroups
[i
]);
2085 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2089 * Make sure that authentication is set to DefaultAuthType
2093 if (loc
->type
== AUTH_NONE
&& strcasecmp(value
, "anonymous"))
2094 loc
->type
= DefaultAuthType
;
2096 else if (!strcasecmp(line
, "AuthGroupName"))
2097 AddName(loc
, value
);
2098 else if (!strcasecmp(line
, "Require"))
2101 * Apache synonym for AuthClass and AuthGroupName...
2105 * Require valid-user
2106 * Require group names
2107 * Require user names
2110 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2115 if (!strcasecmp(value
, "valid-user") ||
2116 !strcasecmp(value
, "user"))
2117 loc
->level
= AUTH_USER
;
2118 else if (!strcasecmp(value
, "group"))
2119 loc
->level
= AUTH_GROUP
;
2122 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2128 * Get the list of names from the line...
2131 for (value
= valptr
; *value
;)
2133 while (isspace(*value
& 255))
2136 if (*value
== '\"' || *value
== '\'')
2139 * Grab quoted name...
2142 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2149 * Grab literal name.
2152 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2158 AddName(loc
, value
);
2160 for (value
= valptr
; isspace(*value
& 255); value
++);
2164 * Make sure that authentication is set to DefaultAuthType
2168 if (loc
->type
== AUTH_NONE
)
2169 loc
->type
= DefaultAuthType
;
2171 else if (!strcasecmp(line
, "Satisfy"))
2173 if (!strcasecmp(value
, "all"))
2174 loc
->satisfy
= AUTH_SATISFY_ALL
;
2175 else if (!strcasecmp(value
, "any"))
2176 loc
->satisfy
= AUTH_SATISFY_ANY
;
2178 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2182 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2186 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2194 * 'read_policy()' - Read a <Policy name> definition.
2197 static int /* O - New line number or 0 on error */
2198 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2199 char *policy
, /* I - Location name/path */
2200 int linenum
) /* I - Current line number */
2202 int i
; /* Looping var */
2203 policy_t
*pol
; /* Policy */
2204 policyop_t
*op
; /* Policy operation */
2205 int num_ops
; /* Number of IPP operations */
2206 ipp_op_t ops
[100]; /* Operations */
2207 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2208 *value
, /* Value for directive */
2209 *valptr
; /* Pointer into value */
2213 * Create the policy...
2216 if ((pol
= AddPolicy(policy
)) == NULL
)
2220 * Read from the file...
2226 while (cupsFileGetConf(fp
, line
, sizeof(line
), &value
, &linenum
))
2229 * Decode the directive...
2232 if (!strcasecmp(line
, "</Policy>"))
2235 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2240 else if (!strcasecmp(line
, "<Limit") && !op
)
2244 LogMessage(L_ERROR
, "Syntax error on line %d.", linenum
);
2249 * Scan for IPP operation names...
2256 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2261 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2263 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2264 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2270 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2273 for (value
= valptr
; isspace(*value
& 255); value
++);
2277 * If none are specified, apply the policy to all operations...
2282 ops
[0] = IPP_ANY_OPERATION
;
2287 * Add a new policy for the first operation...
2290 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2292 else if (!strcasecmp(line
, "</Limit>") && op
)
2295 * Finish the current operation limit...
2301 * Copy the policy to the other operations...
2304 for (i
= 1; i
< num_ops
; i
++)
2305 AddPolicyOp(pol
, op
, ops
[i
]);
2310 else if (!strcasecmp(line
, "Authenticate") && op
)
2313 * Authenticate boolean
2316 if (!strcasecmp(value
, "on") ||
2317 !strcasecmp(value
, "yes") ||
2318 !strcasecmp(value
, "true"))
2319 op
->authenticate
= 1;
2320 else if (!strcasecmp(value
, "off") ||
2321 !strcasecmp(value
, "no") ||
2322 !strcasecmp(value
, "false"))
2323 op
->authenticate
= 0;
2325 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2328 else if (!strcasecmp(line
, "Order") && op
)
2331 * "Order Deny,Allow" or "Order Allow,Deny"...
2334 if (!strncasecmp(value
, "deny", 4))
2335 op
->order_type
= POLICY_ALLOW
;
2336 else if (!strncasecmp(value
, "allow", 5))
2337 op
->order_type
= POLICY_DENY
;
2339 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2342 else if ((!strcasecmp(line
, "Allow") || !strcasecmp(line
, "Deny")) && op
)
2345 * Allow line, @group, @OWNER
2346 * Deny line, @group, @OWNER
2351 while (isspace(*value
& 255))
2354 if (*value
== '\"' || *value
== '\'')
2357 * Grab quoted name...
2360 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2367 * Grab literal name.
2370 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2376 if (!strcasecmp(line
, "Allow"))
2377 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2379 AddPolicyOpName(op
, POLICY_DENY
, value
);
2381 for (value
= valptr
; isspace(*value
& 255); value
++);
2385 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2388 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2392 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2400 * 'get_address()' - Get an address + port number from a line.
2403 static int /* O - 1 if address good, 0 if bad */
2404 get_address(const char *value
, /* I - Value string */
2405 unsigned defaddress
, /* I - Default address */
2406 int defport
, /* I - Default port */
2407 int deffamily
, /* I - Default family */
2408 http_addr_t
*address
) /* O - Socket address */
2410 char hostname
[256], /* Hostname or IP */
2411 portname
[256]; /* Port number or name */
2412 struct hostent
*host
; /* Host address */
2413 struct servent
*port
; /* Port number */
2417 * Initialize the socket address to the defaults...
2420 memset(address
, 0, sizeof(http_addr_t
));
2423 if (deffamily
== AF_INET6
)
2425 address
->ipv6
.sin6_family
= AF_INET6
;
2426 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2427 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2428 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2429 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2430 address
->ipv6
.sin6_port
= htons(defport
);
2433 #endif /* AF_INET6 */
2435 address
->ipv4
.sin_family
= AF_INET
;
2436 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2437 address
->ipv4
.sin_port
= htons(defport
);
2442 * If the address starts with a "/", it is a domain socket...
2447 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2449 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2453 address
->un
.sun_family
= AF_LOCAL
;
2454 strcpy(address
->un
.sun_path
, value
);
2458 #endif /* AF_LOCAL */
2461 * Try to grab a hostname and port number...
2464 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2467 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2470 * Hostname is a port number...
2473 strlcpy(portname
, hostname
, sizeof(portname
));
2484 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2489 * Decode the hostname and port number as needed...
2492 if (hostname
[0] && strcmp(hostname
, "*"))
2494 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2496 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2497 hstrerror(h_errno
));
2501 httpAddrLoad(host
, defport
, 0, address
);
2504 if (portname
[0] != '\0')
2506 if (isdigit(portname
[0] & 255))
2509 if (address
->addr
.sa_family
== AF_INET6
)
2510 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2512 #endif /* AF_INET6 */
2513 address
->ipv4
.sin_port
= htons(atoi(portname
));
2517 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2519 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2526 if (address
->addr
.sa_family
== AF_INET6
)
2527 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2529 #endif /* AF_INET6 */
2530 address
->ipv4
.sin_port
= htons(port
->s_port
);
2540 * 'get_addr_and_mask()' - Get an IP address and netmask.
2543 static int /* O - 1 on success, 0 on failure */
2544 get_addr_and_mask(const char *value
, /* I - String from config file */
2545 unsigned *ip
, /* O - Address value */
2546 unsigned *mask
) /* O - Mask value */
2548 int i
, /* Looping var */
2549 family
, /* Address family */
2550 ipcount
; /* Count of fields in address */
2551 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2553 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2554 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2555 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2556 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2561 * Get the address...
2564 memset(ip
, 0, sizeof(unsigned) * 4);
2566 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2570 * See if we have any values > 255; if so, this is an IPv6 address only.
2573 for (i
= 0; i
< ipcount
; i
++)
2579 #endif /* AF_INET6 */
2581 if ((value
= strchr(value
, '/')) != NULL
)
2584 * Get the netmask value(s)...
2588 memset(mask
, 0, sizeof(unsigned) * 4);
2589 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2590 mask
+ 2, mask
+ 3))
2597 if (family
== AF_INET6
)
2602 mask
[0] = 0xffffffff;
2604 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2607 mask
[1] = 0xffffffff;
2611 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2614 mask
[1] = 0xffffffff;
2618 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2623 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2626 #endif /* AF_INET6 */
2631 mask
[0] = 0xffffffff;
2633 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2636 mask
[1] = 0xffffffff;
2640 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2643 mask
[1] = 0xffffffff;
2647 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2652 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2663 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2666 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2669 if ((ip
[0] & ~mask
[0]) != 0 ||
2670 (ip
[1] & ~mask
[1]) != 0 ||
2671 (ip
[2] & ~mask
[2]) != 0 ||
2672 (ip
[3] & ~mask
[3]) != 0)
2680 * 'get_operation()' - Get an IPP opcode from an operation name...
2683 static ipp_op_t
/* O - Operation code or -1 on error */
2684 get_operation(const char *name
) /* I - Operating name */
2686 int i
; /* Looping var */
2687 static const char * const ipp_ops
[] = /* List of standard operations */
2691 /* 0x0002 */ "print-job",
2692 /* 0x0003 */ "print-uri",
2693 /* 0x0004 */ "validate-job",
2694 /* 0x0005 */ "create-job",
2695 /* 0x0006 */ "send-document",
2696 /* 0x0007 */ "send-uri",
2697 /* 0x0008 */ "cancel-job",
2698 /* 0x0009 */ "get-job-attributes",
2699 /* 0x000a */ "get-jobs",
2700 /* 0x000b */ "get-printer-attributes",
2701 /* 0x000c */ "hold-job",
2702 /* 0x000d */ "release-job",
2703 /* 0x000e */ "restart-job",
2705 /* 0x0010 */ "pause-printer",
2706 /* 0x0011 */ "resume-printer",
2707 /* 0x0012 */ "purge-jobs",
2708 /* 0x0013 */ "set-printer-attributes",
2709 /* 0x0014 */ "set-job-attributes",
2710 /* 0x0015 */ "get-printer-supported-values",
2711 /* 0x0016 */ "create-printer-subscription",
2712 /* 0x0017 */ "create-job-subscription",
2713 /* 0x0018 */ "get-subscription-attributes",
2714 /* 0x0019 */ "get-subscriptions",
2715 /* 0x001a */ "renew-subscription",
2716 /* 0x001b */ "cancel-subscription",
2717 /* 0x001c */ "get-notifications",
2718 /* 0x001d */ "send-notifications",
2722 /* 0x0021 */ "get-print-support-files",
2723 /* 0x0022 */ "enable-printer",
2724 /* 0x0023 */ "disable-printer",
2725 /* 0x0024 */ "pause-printer-after-current-job",
2726 /* 0x0025 */ "hold-new-jobs",
2727 /* 0x0026 */ "release-held-new-jobs",
2728 /* 0x0027 */ "deactivate-printer",
2729 /* 0x0028 */ "activate-printer",
2730 /* 0x0029 */ "restart-printer",
2731 /* 0x002a */ "shutdown-printer",
2732 /* 0x002b */ "startup-printer",
2733 /* 0x002c */ "reprocess-job",
2734 /* 0x002d */ "cancel-current-job",
2735 /* 0x002e */ "suspend-current-job",
2736 /* 0x002f */ "resume-job",
2737 /* 0x0030 */ "promote-job",
2738 /* 0x0031 */ "schedule-job-after"
2740 *cups_ops
[] = /* List of CUPS operations */
2742 /* 0x4001 */ "cups-get-default",
2743 /* 0x4002 */ "cups-get-printers",
2744 /* 0x4003 */ "cups-add-printer",
2745 /* 0x4004 */ "cups-delete-printer",
2746 /* 0x4005 */ "cups-get-classes",
2747 /* 0x4006 */ "cups-add-class",
2748 /* 0x4007 */ "cups-delete-class",
2749 /* 0x4008 */ "cups-accept-jobs",
2750 /* 0x4009 */ "cups-reject-jobs",
2751 /* 0x400a */ "cups-set-default",
2752 /* 0x400b */ "cups-get-devices",
2753 /* 0x400c */ "cups-get-ppds",
2754 /* 0x400d */ "cups-move-job",
2755 /* 0x400e */ "cups-add-device",
2756 /* 0x400f */ "cups-delete-device"
2760 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2761 if (!strcasecmp(name
, ipp_ops
[i
]))
2762 return ((ipp_op_t
)i
);
2764 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2765 if (!strcasecmp(name
, cups_ops
[i
]))
2766 return ((ipp_op_t
)(i
+ 0x4001));
2768 return ((ipp_op_t
)-1);
2774 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2775 * required by SSLSetCertificate.
2777 * For now we assumes that there is exactly one SecIdentity in the
2778 * keychain - i.e. there is exactly one matching cert/private key pair.
2779 * In the future we will search a keychain for a SecIdentity matching a
2780 * specific criteria. We also skip the operation of adding additional
2781 * non-signing certs from the keychain to the CFArrayRef.
2783 * To create a self-signed certificate for testing use the certtool.
2784 * Executing the following as root will do it:
2786 * certtool c c v k=CUPS
2790 CDSAGetServerCerts(void)
2792 OSStatus err
; /* Error info */
2793 SecKeychainRef kcRef
; /* Keychain reference */
2794 SecIdentitySearchRef srchRef
; /* Search reference */
2795 SecIdentityRef identity
; /* Identity */
2796 CFArrayRef ca
; /* Certificate array */
2803 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2806 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2807 ServerCertificate
, err
);
2811 * Search for "any" identity matching specified key use;
2812 * in this app, we expect there to be exactly one.
2815 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2819 "Cannot find signing key in keychain \"%s\", error %d",
2820 ServerCertificate
, err
);
2823 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2827 "Cannot find signing key in keychain \"%s\", error %d",
2828 ServerCertificate
, err
);
2831 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2832 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2836 * Found one. Place it in a CFArray.
2837 * TBD: snag other (non-identity) certs from keychain and add them
2841 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2844 LogMessage(L_ERROR
, "CFArrayCreate error");
2847 /*CFRelease(identity);*/
2850 /*CFRelease(srchRef);*/
2853 /*CFRelease(kcRef);*/
2858 #endif /* HAVE_CDSASSL */