2 * "$Id: conf.c,v 1.77.2.59 2004/07/02 04:51:45 mike Exp $"
4 * Configuration routines for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2004 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-3142 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * ReadConfiguration() - Read the cupsd.conf file.
27 * read_configuration() - Read a configuration file.
28 * read_location() - Read a <Location path> definition.
29 * read_policy() - Read a <Policy name> definition.
30 * get_address() - Get an address + port number from a line.
31 * get_addr_and_mask() - Get an IP address and netmask.
32 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
33 * required by SSLSetCertificate.
37 * Include necessary headers...
44 #include <sys/utsname.h>
46 #ifdef HAVE_DOMAINSOCKETS
48 #endif /* HAVE_DOMAINSOCKETS */
51 # include <Security/SecureTransport.h>
52 # include <Security/SecIdentitySearch.h>
53 #endif /* HAVE_CDSASSL */
57 #endif /* HAVE_VSYSLOG */
61 * Possibly missing network definitions...
65 # define INADDR_NONE 0xffffffff
66 #endif /* !INADDR_NONE */
70 * Configuration variable structure...
75 char *name
; /* Name of variable */
76 void *ptr
; /* Pointer to variable */
77 int type
; /* Type (int, string, address) */
89 static var_t variables
[] =
91 { "AccessLog", &AccessLog
, VAR_STRING
},
92 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
93 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
94 { "BrowseLocalOptions", &BrowseLocalOptions
, VAR_STRING
},
95 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
96 { "BrowseRemoteOptions", &BrowseRemoteOptions
, VAR_STRING
},
97 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
98 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
99 { "Browsing", &Browsing
, VAR_BOOLEAN
},
100 { "Classification", &Classification
, VAR_STRING
},
101 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
102 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
103 { "DataDir", &DataDir
, VAR_STRING
},
104 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
105 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
106 { "DefaultPolicy", &DefaultPolicy
, VAR_STRING
},
107 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
108 { "ErrorLog", &ErrorLog
, VAR_STRING
},
109 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
110 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
111 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
112 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
113 { "FilterNice", &FilterNice
, VAR_INTEGER
},
114 { "FontPath", &FontPath
, VAR_STRING
},
115 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
116 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
117 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
118 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
119 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
120 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
121 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
122 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
123 { "MaxActiveJobs", &MaxActiveJobs
, VAR_INTEGER
},
124 { "MaxClients", &MaxClients
, VAR_INTEGER
},
125 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
126 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
127 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
128 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
129 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
130 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
131 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
132 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
133 { "PageLog", &PageLog
, VAR_STRING
},
134 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
135 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
136 { "Printcap", &Printcap
, VAR_STRING
},
137 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
138 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
139 { "RequestRoot", &RequestRoot
, VAR_STRING
},
140 { "RIPCache", &RIPCache
, VAR_STRING
},
141 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
142 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
143 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
144 { "ServerBin", &ServerBin
, VAR_STRING
},
146 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
147 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
148 { "ServerKey", &ServerKey
, VAR_STRING
},
149 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
150 #endif /* HAVE_SSL */
151 { "ServerName", &ServerName
, VAR_STRING
},
152 { "ServerRoot", &ServerRoot
, VAR_STRING
},
153 { "TempDir", &TempDir
, VAR_STRING
},
154 { "Timeout", &Timeout
, VAR_INTEGER
}
156 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
159 static unsigned ones
[4] =
161 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff
163 static unsigned zeros
[4] =
165 0x00000000, 0x00000000, 0x00000000, 0x00000000
169 static CFArrayRef
CDSAGetServerCerts();
170 #endif /* HAVE_CDSASSL */
177 static int read_configuration(cups_file_t
*fp
);
178 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
179 static int read_policy(cups_file_t
*fp
, char *name
, int linenum
);
180 static int get_address(const char *value
, unsigned defaddress
, int defport
,
181 int deffamily
, http_addr_t
*address
);
182 static int get_addr_and_mask(const char *value
, unsigned *ip
,
184 static ipp_op_t
get_operation(const char *name
);
188 * 'ReadConfiguration:' - Read the cupsd.conf file.
191 int /* O - 1 on success, 0 otherwise */
192 ReadConfiguration(void)
194 int i
; /* Looping var */
195 cups_file_t
*fp
; /* Configuration file */
196 int status
; /* Return status */
197 char temp
[1024], /* Temporary buffer */
198 *slash
; /* Directory separator */
199 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
201 char *language
; /* Language string */
202 struct passwd
*user
; /* Default user */
203 struct group
*group
; /* Default group */
204 char *old_serverroot
, /* Old ServerRoot */
205 *old_requestroot
; /* Old RequestRoot */
209 * Shutdown the server...
215 * Save the old root paths...
218 old_serverroot
= NULL
;
219 SetString(&old_serverroot
, ServerRoot
);
220 old_requestroot
= NULL
;
221 SetString(&old_requestroot
, RequestRoot
);
224 * Reset the server configuration data...
227 DeleteAllLocations();
245 for (i
= 0; i
< NumRelays
; i
++)
246 if (Relays
[i
].from
.type
== AUTH_NAME
)
247 free(Relays
[i
].from
.mask
.name
.name
);
254 if (NumListeners
> 0)
256 #ifdef HAVE_DOMAINSOCKETS
257 int i
; /* Looping var */
258 listener_t
*lis
; /* Current listening socket */
260 for (i
= NumListeners
, lis
= Listeners
; i
> 0; i
--, lis
++)
261 if (lis
->address
.sin_family
== AF_LOCAL
)
262 ClearString((char **)&lis
->address
.sin_addr
);
263 #endif /* HAVE_DOMAINSOCKETS */
274 gethostname(temp
, sizeof(temp
));
275 SetString(&ServerName
, temp
);
276 SetStringf(&ServerAdmin
, "root@%s", temp
);
277 SetString(&ServerBin
, CUPS_SERVERBIN
);
278 SetString(&RequestRoot
, CUPS_REQUESTS
);
279 SetString(&DocumentRoot
, CUPS_DOCROOT
);
280 SetString(&DataDir
, CUPS_DATADIR
);
281 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
282 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
283 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
284 SetString(&Printcap
, "/etc/printcap");
285 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
286 SetString(&FontPath
, CUPS_FONTPATH
);
287 SetString(&RemoteRoot
, "remroot");
288 SetString(&ServerHeader
, "CUPS/1.1");
290 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
291 if ((slash
= strrchr(temp
, '/')) != NULL
)
294 SetString(&ServerRoot
, temp
);
296 ClearString(&Classification
);
297 ClassifyOverride
= 0;
301 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
303 SetString(&ServerCertificate
, "ssl/server.crt");
304 SetString(&ServerKey
, "ssl/server.key");
305 # endif /* HAVE_CDSASSL */
306 #endif /* HAVE_SSL */
308 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
310 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
313 SetString(&DefaultLanguage
, language
);
314 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
316 SetString(&RIPCache
, "8m");
318 if (getenv("TMPDIR") == NULL
)
319 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
321 SetString(&TempDir
, getenv("TMPDIR"));
324 * Find the default system group: "sys", "system", or "root"...
327 group
= getgrnam(CUPS_DEFAULT_GROUP
);
334 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
335 Group
= group
->gr_gid
;
344 SetString(&SystemGroups
[0], group
->gr_name
);
349 SetString(&SystemGroups
[0], "unknown");
355 * Find the default user...
358 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
359 User
= 1; /* Force to a non-priviledged account */
369 ConfigFilePerm
= 0640;
373 FaxRetryInterval
= 300;
378 HostNameLookups
= FALSE
;
379 ImplicitClasses
= TRUE
;
380 ImplicitAnyClasses
= FALSE
;
381 HideImplicitMembers
= TRUE
;
383 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
384 ListenBackLog
= SOMAXCONN
;
387 MaxClientsPerHost
= 0;
388 MaxLogSize
= 1024 * 1024;
389 MaxPrinterHistory
= 10;
391 RootCertDuration
= 300;
393 Timeout
= DEFAULT_TIMEOUT
;
395 BrowseInterval
= DEFAULT_INTERVAL
;
396 BrowsePort
= ippPort();
397 BrowseProtocols
= BROWSE_CUPS
;
398 BrowseShortNames
= TRUE
;
399 BrowseTimeout
= DEFAULT_TIMEOUT
;
402 ClearString(&BrowseLocalOptions
);
403 ClearString(&BrowseRemoteOptions
);
405 JobHistory
= DEFAULT_HISTORY
;
406 JobFiles
= DEFAULT_FILES
;
410 MaxJobsPerPrinter
= 0;
414 ClearString(&DefaultPolicy
);
417 * Read the configuration file...
420 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
423 status
= read_configuration(fp
);
436 * Use the default system group if none was supplied in cupsd.conf...
439 if (NumSystemGroups
== 0)
443 * Get the access control list for browsing...
446 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
449 * Open the system log for cupsd if necessary...
453 if (strcmp(AccessLog
, "syslog") == 0 ||
454 strcmp(ErrorLog
, "syslog") == 0 ||
455 strcmp(PageLog
, "syslog") == 0)
456 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
457 #endif /* HAVE_VSYSLOG */
460 * Log the configuration file that was used...
463 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
466 * Check that we have at least one listen/port line; if not, report this
467 * as an error and exit!
470 if (NumListeners
== 0)
476 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
482 kill(getpid(), SIGTERM
);
486 * Set the default locale using the language and charset...
489 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
492 * Update all relative filenames to include the full path from ServerRoot...
495 if (DocumentRoot
[0] != '/')
496 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
498 if (RequestRoot
[0] != '/')
499 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
501 if (ServerBin
[0] != '/')
502 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
505 if (ServerCertificate
[0] != '/')
506 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
508 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
509 chown(ServerCertificate
, RunUser
, Group
);
510 chmod(ServerCertificate
, ConfigFilePerm
);
512 if (ServerKey
[0] != '/')
513 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
515 chown(ServerKey
, RunUser
, Group
);
516 chmod(ServerKey
, ConfigFilePerm
);
517 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
518 #endif /* HAVE_SSL */
521 * Make sure that ServerRoot and the config files are owned and
522 * writable by the user and group in the cupsd.conf file...
525 chown(ServerRoot
, RunUser
, Group
);
526 chmod(ServerRoot
, 0775);
528 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
529 chown(temp
, RunUser
, Group
);
532 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
533 chown(temp
, RunUser
, Group
);
536 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
537 chown(temp
, RunUser
, Group
);
540 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
541 chown(temp
, RunUser
, Group
);
542 chmod(temp
, ConfigFilePerm
);
544 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
545 chown(temp
, RunUser
, Group
);
549 chmod(temp
, ConfigFilePerm
);
550 #endif /* __APPLE__ */
552 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
553 chown(temp
, RunUser
, Group
);
557 chmod(temp
, ConfigFilePerm
);
558 #endif /* __APPLE__ */
560 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
561 chown(temp
, User
, Group
);
565 * Make sure the request and temporary directories have the right
569 chown(RequestRoot
, RunUser
, Group
);
570 chmod(RequestRoot
, 0710);
572 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
575 * Only update ownership and permissions if the CUPS temp directory
576 * is under the spool directory...
579 chown(TempDir
, RunUser
, Group
);
580 chmod(TempDir
, 01770);
584 * Check the MaxClients setting, and then allocate memory for it...
587 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
590 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
593 MaxClients
= MaxFDs
/ 3;
596 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
598 LogMessage(L_ERROR
, "Unable to allocate memory for %d clients: %s",
599 MaxClients
, strerror(errno
));
603 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
606 * Check the MaxActiveJobs setting; limit to 1/3 the available
607 * file descriptors, since we need a pipe for each job...
610 if (MaxActiveJobs
> (MaxFDs
/ 3))
611 MaxActiveJobs
= MaxFDs
/ 3;
613 if (Classification
&& strcasecmp(Classification
, "none") == 0)
614 ClearString(&Classification
);
617 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
620 * Update the MaxClientsPerHost value, as needed...
623 if (MaxClientsPerHost
<= 0)
624 MaxClientsPerHost
= MaxClients
;
626 if (MaxClientsPerHost
> MaxClients
)
627 MaxClientsPerHost
= MaxClients
;
629 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
633 * Update the default policy, as needed...
637 DefaultPolicyPtr
= FindPolicy(DefaultPolicy
);
639 DefaultPolicyPtr
= NULL
;
641 if (!DefaultPolicyPtr
)
643 policy_t
*p
; /* New policy */
644 policyop_t
*po
; /* New policy operation */
645 char groupname
[255]; /* Group name */
649 LogMessage(L_ERROR
, "Default policy \"%s\" not found!", DefaultPolicy
);
651 if ((DefaultPolicyPtr
= FindPolicy("default")) != NULL
)
652 LogMessage(L_INFO
, "Using policy \"default\" as the default!");
655 LogMessage(L_INFO
, "Creating CUPS default administrative policy:");
657 DefaultPolicyPtr
= p
= AddPolicy("default");
659 LogMessage(L_INFO
, "<Policy default>");
660 LogMessage(L_INFO
, "<Limit Send-Document Send-URI Cancel-Job Hold-Job "
661 "Release-Job Restart-Job Purge-Jobs "
662 "Set-Job-Attributes Create-Job-Subscription "
663 "Renew-Subscription Cancel-Subscription "
664 "Get-Notifications Reprocess-Job Cancel-Current-Job "
665 "Suspend-Current-Job Resume-Job CUPS-Move-Job>");
666 LogMessage(L_INFO
, "Order Allow,Deny");
667 LogMessage(L_INFO
, "Allow @OWNER");
669 po
= AddPolicyOp(p
, NULL
, IPP_SEND_DOCUMENT
);
670 po
->order_type
= POLICY_DENY
;
672 AddPolicyOpName(po
, POLICY_ALLOW
, "@OWNER");
674 for (i
= 0; i
< NumSystemGroups
; i
++)
676 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
677 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
678 LogMessage(L_INFO
, "Allow %s", groupname
);
681 AddPolicyOp(p
, po
, IPP_SEND_URI
);
682 AddPolicyOp(p
, po
, IPP_CANCEL_JOB
);
683 AddPolicyOp(p
, po
, IPP_HOLD_JOB
);
684 AddPolicyOp(p
, po
, IPP_RELEASE_JOB
);
685 AddPolicyOp(p
, po
, IPP_RESTART_JOB
);
686 AddPolicyOp(p
, po
, IPP_PURGE_JOBS
);
687 AddPolicyOp(p
, po
, IPP_SET_JOB_ATTRIBUTES
);
688 AddPolicyOp(p
, po
, IPP_CREATE_JOB_SUBSCRIPTION
);
689 AddPolicyOp(p
, po
, IPP_RENEW_SUBSCRIPTION
);
690 AddPolicyOp(p
, po
, IPP_CANCEL_SUBSCRIPTION
);
691 AddPolicyOp(p
, po
, IPP_GET_NOTIFICATIONS
);
692 AddPolicyOp(p
, po
, IPP_REPROCESS_JOB
);
693 AddPolicyOp(p
, po
, IPP_CANCEL_CURRENT_JOB
);
694 AddPolicyOp(p
, po
, IPP_SUSPEND_CURRENT_JOB
);
695 AddPolicyOp(p
, po
, IPP_RESUME_JOB
);
696 AddPolicyOp(p
, po
, CUPS_MOVE_JOB
);
698 LogMessage(L_INFO
, "</Limit>");
700 LogMessage(L_INFO
, "<Limit Pause-Printer Resume-Printer "
701 "Set-Printer-Attributes Enable-Printer "
702 "Disable-Printer Pause-Printer-After-Current-Job "
703 "Hold-New-Jobs Release-Held-New-Jobs Deactivate-Printer "
704 "Activate-Printer Restart-Printer Shutdown-Printer "
705 "Startup-Printer Promote-Job Schedule-Job-After "
706 "CUPS-Add-Printer CUPS-Delete-Printer "
707 "CUPS-Add-Class CUPS-Delete-Class "
708 "CUPS-Accept-Jobs CUPS-Reject-Jobs "
709 "CUPS-Set-Default CUPS-Add-Device CUPS-Delete-Device>");
710 LogMessage(L_INFO
, "Order Allow,Deny");
711 LogMessage(L_INFO
, "Authenticate yes");
713 po
= AddPolicyOp(p
, NULL
, IPP_PAUSE_PRINTER
);
714 po
->order_type
= POLICY_DENY
;
715 po
->authenticate
= 1;
717 for (i
= 0; i
< NumSystemGroups
; i
++)
719 snprintf(groupname
, sizeof(groupname
), "@%s", SystemGroups
[i
]);
720 AddPolicyOpName(po
, POLICY_ALLOW
, groupname
);
721 LogMessage(L_INFO
, "Allow %s", groupname
);
724 AddPolicyOp(p
, po
, IPP_RESUME_PRINTER
);
725 AddPolicyOp(p
, po
, IPP_SET_PRINTER_ATTRIBUTES
);
726 AddPolicyOp(p
, po
, IPP_ENABLE_PRINTER
);
727 AddPolicyOp(p
, po
, IPP_DISABLE_PRINTER
);
728 AddPolicyOp(p
, po
, IPP_PAUSE_PRINTER_AFTER_CURRENT_JOB
);
729 AddPolicyOp(p
, po
, IPP_HOLD_NEW_JOBS
);
730 AddPolicyOp(p
, po
, IPP_RELEASE_HELD_NEW_JOBS
);
731 AddPolicyOp(p
, po
, IPP_DEACTIVATE_PRINTER
);
732 AddPolicyOp(p
, po
, IPP_ACTIVATE_PRINTER
);
733 AddPolicyOp(p
, po
, IPP_RESTART_PRINTER
);
734 AddPolicyOp(p
, po
, IPP_SHUTDOWN_PRINTER
);
735 AddPolicyOp(p
, po
, IPP_STARTUP_PRINTER
);
736 AddPolicyOp(p
, po
, IPP_PROMOTE_JOB
);
737 AddPolicyOp(p
, po
, IPP_SCHEDULE_JOB_AFTER
);
738 AddPolicyOp(p
, po
, CUPS_ADD_PRINTER
);
739 AddPolicyOp(p
, po
, CUPS_DELETE_PRINTER
);
740 AddPolicyOp(p
, po
, CUPS_ADD_CLASS
);
741 AddPolicyOp(p
, po
, CUPS_DELETE_CLASS
);
742 AddPolicyOp(p
, po
, CUPS_ACCEPT_JOBS
);
743 AddPolicyOp(p
, po
, CUPS_REJECT_JOBS
);
744 AddPolicyOp(p
, po
, CUPS_SET_DEFAULT
);
745 AddPolicyOp(p
, po
, CUPS_ADD_DEVICE
);
746 AddPolicyOp(p
, po
, CUPS_DELETE_DEVICE
);
748 LogMessage(L_INFO
, "</Limit>");
750 LogMessage(L_INFO
, "<Limit All>");
751 LogMessage(L_INFO
, "Order Deny,Allow");
753 po
= AddPolicyOp(p
, NULL
, IPP_ANY_OPERATION
);
754 po
->order_type
= POLICY_ALLOW
;
756 LogMessage(L_INFO
, "</Limit>");
757 LogMessage(L_INFO
, "</Policy>");
762 * If we are doing a full reload or the server root has changed, flush
763 * the jobs, printers, etc. and start from scratch...
766 if (NeedReload
== RELOAD_ALL
||
767 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
768 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
770 LogMessage(L_INFO
, "Full reload is required.");
780 DefaultPrinter
= NULL
;
794 if (MimeDatabase
!= NULL
)
795 mimeDelete(MimeDatabase
);
799 for (i
= 0; i
< NumMimeTypes
; i
++)
800 free((void *)MimeTypes
[i
]);
806 * Read the MIME type and conversion database...
809 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
811 MimeDatabase
= mimeNew();
812 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
815 * Create a list of MIME types for the document-format-supported
819 NumMimeTypes
= MimeDatabase
->num_types
;
820 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
823 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
825 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
827 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
828 MimeDatabase
->types
[i
]->type
);
830 MimeTypes
[i
] = strdup(type
);
833 if (i
< NumMimeTypes
)
834 MimeTypes
[i
] = strdup("application/octet-stream");
840 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
844 * Load printers and classes...
853 * Load devices and PPDs...
856 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
859 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
863 * Load queued jobs...
868 LogMessage(L_INFO
, "Full reload complete.");
874 LogMessage(L_INFO
, "Partial reload complete.");
878 * Reset the reload state...
881 NeedReload
= RELOAD_NONE
;
883 ClearString(&old_serverroot
);
884 ClearString(&old_requestroot
);
887 * Startup the server and return...
897 * 'read_configuration()' - Read a configuration file.
900 static int /* O - 1 on success, 0 on failure */
901 read_configuration(cups_file_t
*fp
) /* I - File to read from */
903 int i
; /* Looping var */
904 int linenum
; /* Current line number */
905 int len
; /* Length of line */
906 char line
[HTTP_MAX_BUFFER
], /* Line from file */
907 name
[256], /* Parameter name */
908 *nameptr
, /* Pointer into name */
909 *value
; /* Pointer to value */
910 int valuelen
; /* Length of value */
911 var_t
*var
; /* Current variable */
912 unsigned ip
[4], /* Address value */
913 mask
[4]; /* Netmask value */
914 dirsvc_relay_t
*relay
; /* Relay data */
915 dirsvc_poll_t
*poll
; /* Polling data */
916 http_addr_t polladdr
; /* Polling address */
917 location_t
*location
; /* Browse location */
918 cups_file_t
*incfile
; /* Include file */
919 char incname
[1024]; /* Include filename */
923 * Loop through each line in the file...
928 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
933 * Skip comment lines...
940 * Strip trailing whitespace, if any...
945 while (len
> 0 && isspace(line
[len
- 1]))
952 * Extract the name from the beginning of the line...
955 for (value
= line
; isspace(*value
); value
++);
957 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
958 nameptr
< (name
+ sizeof(name
) - 1);)
959 *nameptr
++ = *value
++;
962 while (isspace(*value
))
969 * Decode the directive...
972 if (strcasecmp(name
, "Include") == 0)
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(name
, "<Location") == 0)
998 if (line
[len
- 1] == '>')
1000 line
[len
- 1] = '\0';
1002 linenum
= read_location(fp
, value
, linenum
);
1008 LogMessage(L_ERROR
, "Syntax error on line %d.",
1013 else if (!strcasecmp(name
, "<Policy"))
1019 if (line
[len
- 1] == '>')
1021 line
[len
- 1] = '\0';
1023 linenum
= read_policy(fp
, value
, linenum
);
1029 LogMessage(L_ERROR
, "Syntax error on line %d.",
1034 else if (strcasecmp(name
, "Port") == 0 ||
1035 strcasecmp(name
, "Listen") == 0)
1038 * Add a listening address to the list...
1041 listener_t
*temp
; /* New listeners array */
1044 if (NumListeners
== 0)
1045 temp
= malloc(sizeof(listener_t
));
1047 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1051 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1052 name
, linenum
, strerror(errno
));
1057 temp
+= NumListeners
;
1059 memset(temp
, 0, sizeof(listener_t
));
1061 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
1063 httpAddrString(&(temp
->address
), line
, sizeof(line
));
1066 if (temp
->address
.addr
.sa_family
== AF_INET6
)
1067 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
1068 ntohs(temp
->address
.ipv6
.sin6_port
));
1070 #endif /* AF_INET6 */
1071 LogMessage(L_INFO
, "Listening to %s:%d", line
,
1072 ntohs(temp
->address
.ipv4
.sin_port
));
1076 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
1080 else if (strcasecmp(name
, "SSLPort") == 0 ||
1081 strcasecmp(name
, "SSLListen") == 0)
1084 * Add a listening address to the list...
1087 listener_t
*temp
; /* New listeners array */
1090 if (NumListeners
== 0)
1091 temp
= malloc(sizeof(listener_t
));
1093 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
1097 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
1098 name
, linenum
, strerror(errno
));
1103 temp
+= NumListeners
;
1105 if (get_address(value
, INADDR_ANY
, IPP_PORT
, AF_INET
, &(temp
->address
)))
1107 httpAddrString(&(temp
->address
), line
, sizeof(line
));
1110 if (temp
->address
.addr
.sa_family
== AF_INET6
)
1111 LogMessage(L_INFO
, "Listening to %s:%d (IPv6)", line
,
1112 ntohs(temp
->address
.ipv6
.sin6_port
));
1114 #endif /* AF_INET6 */
1115 LogMessage(L_INFO
, "Listening to %s:%d", line
,
1116 ntohs(temp
->address
.ipv4
.sin_port
));
1117 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
1121 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
1124 #endif /* HAVE_SSL */
1125 else if (strcasecmp(name
, "BrowseAddress") == 0)
1128 * Add a browse address to the list...
1131 dirsvc_addr_t
*temp
; /* New browse address array */
1134 if (NumBrowsers
== 0)
1135 temp
= malloc(sizeof(dirsvc_addr_t
));
1137 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
1141 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
1142 linenum
, strerror(errno
));
1147 temp
+= NumBrowsers
;
1149 memset(temp
, 0, sizeof(dirsvc_addr_t
));
1151 if (strcasecmp(value
, "@LOCAL") == 0)
1154 * Send browse data to all local interfaces...
1157 strcpy(temp
->iface
, "*");
1160 else if (strncasecmp(value
, "@IF(", 4) == 0)
1163 * Send browse data to the named interface...
1166 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
1168 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
1169 if (*nameptr
== ')')
1174 else if (get_address(value
, INADDR_NONE
, BrowsePort
, AF_INET
, &(temp
->to
)))
1176 httpAddrString(&(temp
->to
), line
, sizeof(line
));
1179 if (temp
->to
.addr
.sa_family
== AF_INET6
)
1180 LogMessage(L_INFO
, "Sending browsing info to %s:%d (IPv6)", line
,
1181 ntohs(temp
->to
.ipv6
.sin6_port
));
1183 #endif /* AF_INET6 */
1184 LogMessage(L_INFO
, "Sending browsing info to %s:%d", line
,
1185 ntohs(temp
->to
.ipv4
.sin_port
));
1190 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
1193 else if (strcasecmp(name
, "BrowseOrder") == 0)
1196 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
1199 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1200 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1202 if (location
== NULL
)
1203 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1204 else if (strncasecmp(value
, "deny", 4) == 0)
1205 location
->order_type
= AUTH_ALLOW
;
1206 else if (strncasecmp(value
, "allow", 5) == 0)
1207 location
->order_type
= AUTH_DENY
;
1209 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1212 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1215 * "BrowseProtocol name [... name]"
1218 BrowseProtocols
= 0;
1222 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1223 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1226 if (value
[valuelen
])
1228 value
[valuelen
] = '\0';
1232 if (strcasecmp(value
, "cups") == 0)
1233 BrowseProtocols
|= BROWSE_CUPS
;
1234 else if (strcasecmp(value
, "slp") == 0)
1235 BrowseProtocols
|= BROWSE_SLP
;
1236 else if (strcasecmp(value
, "ldap") == 0)
1237 BrowseProtocols
|= BROWSE_LDAP
;
1238 else if (strcasecmp(value
, "all") == 0)
1239 BrowseProtocols
|= BROWSE_ALL
;
1242 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1247 for (value
+= valuelen
; *value
; value
++)
1248 if (!isspace(*value
) || *value
!= ',')
1252 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1253 strcasecmp(name
, "BrowseDeny") == 0)
1256 * BrowseAllow [From] host/ip...
1257 * BrowseDeny [From] host/ip...
1260 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1261 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1263 if (location
== NULL
)
1264 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1267 if (strncasecmp(value
, "from ", 5) == 0)
1270 * Strip leading "from"...
1275 while (isspace(*value
))
1280 * Figure out what form the allow/deny address takes:
1291 * nnn.nnn.nnn.nnn/mm
1292 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1295 if (strcasecmp(value
, "all") == 0)
1301 if (strcasecmp(name
, "BrowseAllow") == 0)
1302 AllowIP(location
, zeros
, zeros
);
1304 DenyIP(location
, zeros
, zeros
);
1306 else if (strcasecmp(value
, "none") == 0)
1312 if (strcasecmp(name
, "BrowseAllow") == 0)
1313 AllowIP(location
, ones
, zeros
);
1315 DenyIP(location
, ones
, zeros
);
1317 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1320 * Host or domain name...
1323 if (value
[0] == '*')
1326 if (strcasecmp(name
, "BrowseAllow") == 0)
1327 AllowHost(location
, value
);
1329 DenyHost(location
, value
);
1334 * One of many IP address forms...
1337 if (!get_addr_and_mask(value
, ip
, mask
))
1339 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1344 if (strcasecmp(name
, "BrowseAllow") == 0)
1345 AllowIP(location
, ip
, mask
);
1347 DenyIP(location
, ip
, mask
);
1351 else if (strcasecmp(name
, "BrowseRelay") == 0)
1354 * BrowseRelay [from] source [to] destination
1358 relay
= malloc(sizeof(dirsvc_relay_t
));
1360 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1364 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1365 linenum
, strerror(errno
));
1372 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1374 if (strncasecmp(value
, "from ", 5) == 0)
1377 * Strip leading "from"...
1382 while (isspace(*value
))
1387 * Figure out what form the from address takes:
1396 * nnn.nnn.nnn.nnn/mm
1397 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1400 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1403 * Host or domain name...
1406 if (value
[0] == '*')
1409 strlcpy(name
, value
, sizeof(name
));
1410 if ((nameptr
= strchr(name
, ' ')) != NULL
)
1413 relay
->from
.type
= AUTH_NAME
;
1414 relay
->from
.mask
.name
.name
= strdup(name
);
1415 relay
->from
.mask
.name
.length
= strlen(name
);
1420 * One of many IP address forms...
1423 if (!get_addr_and_mask(value
, ip
, mask
))
1425 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1430 relay
->from
.type
= AUTH_IP
;
1431 memcpy(relay
->from
.mask
.ip
.address
, ip
,
1432 sizeof(relay
->from
.mask
.ip
.address
));
1433 memcpy(relay
->from
.mask
.ip
.netmask
, mask
,
1434 sizeof(relay
->from
.mask
.ip
.netmask
));
1438 * Skip value and trailing whitespace...
1441 for (; *value
; value
++)
1442 if (isspace(*value
))
1445 while (isspace(*value
))
1448 if (strncasecmp(value
, "to ", 3) == 0)
1451 * Strip leading "to"...
1456 while (isspace(*value
))
1461 * Get "to" address and port...
1464 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, AF_INET
, &(relay
->to
)))
1466 httpAddrString(&(relay
->to
), line
, sizeof(line
));
1468 if (relay
->from
.type
== AUTH_IP
)
1469 snprintf(name
, sizeof(name
), "%u.%u.%u.%u/%u.%u.%u.%u",
1470 relay
->from
.mask
.ip
.address
[0],
1471 relay
->from
.mask
.ip
.address
[1],
1472 relay
->from
.mask
.ip
.address
[2],
1473 relay
->from
.mask
.ip
.address
[3],
1474 relay
->from
.mask
.ip
.netmask
[0],
1475 relay
->from
.mask
.ip
.netmask
[1],
1476 relay
->from
.mask
.ip
.netmask
[2],
1477 relay
->from
.mask
.ip
.netmask
[3]);
1480 strncpy(name
, relay
->from
.mask
.name
.name
, sizeof(name
) - 1);
1481 name
[sizeof(name
) - 1] = '\0';
1485 if (relay
->to
.addr
.sa_family
== AF_INET6
)
1486 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1487 ntohs(relay
->to
.ipv6
.sin6_port
));
1489 #endif /* AF_INET6 */
1490 LogMessage(L_INFO
, "Relaying from %s to %s:%d", name
, line
,
1491 ntohs(relay
->to
.ipv4
.sin_port
));
1497 if (relay
->from
.type
== AUTH_NAME
)
1498 free(relay
->from
.mask
.name
.name
);
1500 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1503 else if (strcasecmp(name
, "BrowsePoll") == 0)
1506 * BrowsePoll address[:port]
1510 poll
= malloc(sizeof(dirsvc_poll_t
));
1512 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1516 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1517 linenum
, strerror(errno
));
1525 * Get poll address and port...
1528 if (get_address(value
, INADDR_NONE
, ippPort(), AF_INET
, &polladdr
))
1531 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1533 httpAddrString(&polladdr
, poll
->hostname
, sizeof(poll
->hostname
));
1536 if (polladdr
.addr
.sa_family
== AF_INET6
)
1537 poll
->port
= ntohs(polladdr
.ipv6
.sin6_port
);
1539 #endif /* AF_INET6 */
1540 poll
->port
= ntohs(polladdr
.ipv4
.sin_port
);
1542 LogMessage(L_INFO
, "Polling %s:%d", poll
->hostname
, poll
->port
);
1545 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1547 else if (strcasecmp(name
, "User") == 0)
1550 * User ID to run as...
1553 if (isdigit(value
[0]))
1557 struct passwd
*p
; /* Password information */
1560 p
= getpwnam(value
);
1565 LogMessage(L_WARN
, "Unknown username \"%s\"",
1569 else if (strcasecmp(name
, "Group") == 0)
1572 * Group ID to run as...
1575 if (isdigit(value
[0]))
1576 Group
= atoi(value
);
1579 struct group
*g
; /* Group information */
1582 g
= getgrnam(value
);
1587 LogMessage(L_WARN
, "Unknown groupname \"%s\"",
1591 else if (strcasecmp(name
, "SystemGroup") == 0)
1594 * System (admin) group(s)...
1597 char *valueptr
, /* Pointer into value */
1598 quote
; /* Quote character */
1601 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1603 if (*value
== '\'' || *value
== '\"')
1606 * Scan quoted name...
1611 for (valueptr
= value
; *valueptr
; valueptr
++)
1612 if (*valueptr
== quote
)
1618 * Scan space or comma-delimited name...
1621 for (valueptr
= value
; *valueptr
; valueptr
++)
1622 if (isspace(*valueptr
) || *valueptr
== ',')
1629 SetString(SystemGroups
+ i
, value
);
1633 while (*value
== ',' || isspace(*value
))
1638 NumSystemGroups
= i
;
1640 else if (strcasecmp(name
, "HostNameLookups") == 0)
1643 * Do hostname lookups?
1646 if (strcasecmp(value
, "off") == 0)
1647 HostNameLookups
= 0;
1648 else if (strcasecmp(value
, "on") == 0)
1649 HostNameLookups
= 1;
1650 else if (strcasecmp(value
, "double") == 0)
1651 HostNameLookups
= 2;
1653 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1656 else if (strcasecmp(name
, "LogLevel") == 0)
1659 * Amount of logging to do...
1662 if (strcasecmp(value
, "debug2") == 0)
1663 LogLevel
= L_DEBUG2
;
1664 else if (strcasecmp(value
, "debug") == 0)
1666 else if (strcasecmp(value
, "info") == 0)
1668 else if (strcasecmp(value
, "notice") == 0)
1669 LogLevel
= L_NOTICE
;
1670 else if (strcasecmp(value
, "warn") == 0)
1672 else if (strcasecmp(value
, "error") == 0)
1674 else if (strcasecmp(value
, "crit") == 0)
1676 else if (strcasecmp(value
, "alert") == 0)
1678 else if (strcasecmp(value
, "emerg") == 0)
1680 else if (strcasecmp(value
, "none") == 0)
1683 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1685 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1688 * Format of printcap file?
1691 if (strcasecmp(value
, "bsd") == 0)
1692 PrintcapFormat
= PRINTCAP_BSD
;
1693 else if (strcasecmp(value
, "solaris") == 0)
1694 PrintcapFormat
= PRINTCAP_SOLARIS
;
1696 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1699 else if (!strcasecmp(name
, "ServerTokens"))
1702 * Set the string used for the Server header...
1705 struct utsname plat
; /* Platform info */
1710 if (!strcasecmp(value
, "ProductOnly"))
1711 SetString(&ServerHeader
, "CUPS");
1712 else if (!strcasecmp(value
, "Major"))
1713 SetString(&ServerHeader
, "CUPS/1");
1714 else if (!strcasecmp(value
, "Minor"))
1715 SetString(&ServerHeader
, "CUPS/1.1");
1716 else if (!strcasecmp(value
, "Minimal"))
1717 SetString(&ServerHeader
, CUPS_MINIMAL
);
1718 else if (!strcasecmp(value
, "OS"))
1719 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1720 else if (!strcasecmp(value
, "Full"))
1721 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1722 else if (!strcasecmp(value
, "None"))
1723 ClearString(&ServerHeader
);
1725 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1730 * Find a simple variable in the list...
1733 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1734 if (strcasecmp(name
, var
->name
) == 0)
1740 * Unknown directive! Output an error message and continue...
1743 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1753 char *units
; /* Units */
1756 n
= strtol(value
, &units
, 0);
1758 if (units
&& *units
)
1760 if (tolower(units
[0] & 255) == 'g')
1761 n
*= 1024 * 1024 * 1024;
1762 else if (tolower(units
[0] & 255) == 'm')
1764 else if (tolower(units
[0] & 255) == 'k')
1766 else if (tolower(units
[0] & 255) == 't')
1770 *((int *)var
->ptr
) = n
;
1775 if (strcasecmp(value
, "true") == 0 ||
1776 strcasecmp(value
, "on") == 0 ||
1777 strcasecmp(value
, "enabled") == 0 ||
1778 strcasecmp(value
, "yes") == 0 ||
1780 *((int *)var
->ptr
) = TRUE
;
1781 else if (strcasecmp(value
, "false") == 0 ||
1782 strcasecmp(value
, "off") == 0 ||
1783 strcasecmp(value
, "disabled") == 0 ||
1784 strcasecmp(value
, "no") == 0 ||
1785 strcasecmp(value
, "0") == 0)
1786 *((int *)var
->ptr
) = FALSE
;
1788 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1793 SetString((char **)var
->ptr
, value
);
1804 * 'read_location()' - Read a <Location path> definition.
1807 static int /* O - New line number or 0 on error */
1808 read_location(cups_file_t
*fp
, /* I - Configuration file */
1809 char *location
, /* I - Location name/path */
1810 int linenum
) /* I - Current line number */
1812 int i
; /* Looping var */
1813 location_t
*loc
, /* New location */
1814 *parent
; /* Parent location */
1815 int len
; /* Length of line */
1816 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1817 name
[256], /* Configuration directive */
1818 *nameptr
, /* Pointer into name */
1819 *value
, /* Value for directive */
1820 *valptr
; /* Pointer into value */
1821 unsigned ip
[4], /* IP address components */
1822 mask
[4]; /* IP netmask components */
1825 if ((parent
= AddLocation(location
)) == NULL
)
1828 parent
->limit
= AUTH_LIMIT_ALL
;
1831 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1836 * Skip comment lines...
1843 * Strip trailing whitespace, if any...
1848 while (len
> 0 && isspace(line
[len
- 1] & 255))
1855 * Extract the name from the beginning of the line...
1858 for (value
= line
; isspace(*value
& 255); value
++);
1860 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
1861 nameptr
< (name
+ sizeof(name
) - 1);)
1862 *nameptr
++ = *value
++;
1865 while (isspace(*value
& 255))
1868 if (name
[0] == '\0')
1872 * Decode the directive...
1875 if (strcasecmp(name
, "</Location>") == 0)
1877 else if (strcasecmp(name
, "<Limit") == 0 ||
1878 strcasecmp(name
, "<LimitExcept") == 0)
1880 if ((loc
= CopyLocation(&parent
)) == NULL
)
1886 for (valptr
= value
;
1887 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1893 if (strcmp(value
, "ALL") == 0)
1894 loc
->limit
= AUTH_LIMIT_ALL
;
1895 else if (strcmp(value
, "GET") == 0)
1896 loc
->limit
|= AUTH_LIMIT_GET
;
1897 else if (strcmp(value
, "HEAD") == 0)
1898 loc
->limit
|= AUTH_LIMIT_HEAD
;
1899 else if (strcmp(value
, "OPTIONS") == 0)
1900 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1901 else if (strcmp(value
, "POST") == 0)
1902 loc
->limit
|= AUTH_LIMIT_POST
;
1903 else if (strcmp(value
, "PUT") == 0)
1904 loc
->limit
|= AUTH_LIMIT_PUT
;
1905 else if (strcmp(value
, "TRACE") == 0)
1906 loc
->limit
|= AUTH_LIMIT_TRACE
;
1908 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1911 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
1914 if (strcasecmp(name
, "<LimitExcept") == 0)
1915 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1917 parent
->limit
&= ~loc
->limit
;
1919 else if (strcasecmp(name
, "</Limit>") == 0)
1921 else if (strcasecmp(name
, "Encryption") == 0)
1924 * "Encryption xxx" - set required encryption level...
1927 if (strcasecmp(value
, "never") == 0)
1928 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1929 else if (strcasecmp(value
, "always") == 0)
1931 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1932 "Using \"required\" instead.", value
, linenum
);
1934 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1936 else if (strcasecmp(value
, "required") == 0)
1937 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1938 else if (strcasecmp(value
, "ifrequested") == 0)
1939 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1941 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1944 else if (strcasecmp(name
, "Order") == 0)
1947 * "Order Deny,Allow" or "Order Allow,Deny"...
1950 if (strncasecmp(value
, "deny", 4) == 0)
1951 loc
->order_type
= AUTH_ALLOW
;
1952 else if (strncasecmp(value
, "allow", 5) == 0)
1953 loc
->order_type
= AUTH_DENY
;
1955 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1958 else if (strcasecmp(name
, "Allow") == 0 ||
1959 strcasecmp(name
, "Deny") == 0)
1962 * Allow [From] host/ip...
1963 * Deny [From] host/ip...
1966 if (strncasecmp(value
, "from", 4) == 0)
1969 * Strip leading "from"...
1974 while (isspace(*value
& 255))
1979 * Figure out what form the allow/deny address takes:
1990 * nnn.nnn.nnn.nnn/mm
1991 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1994 if (strcasecmp(value
, "all") == 0)
2000 if (strcasecmp(name
, "Allow") == 0)
2001 AllowIP(loc
, zeros
, zeros
);
2003 DenyIP(loc
, zeros
, zeros
);
2005 else if (strcasecmp(value
, "none") == 0)
2011 if (strcasecmp(name
, "Allow") == 0)
2012 AllowIP(loc
, ones
, zeros
);
2014 DenyIP(loc
, ones
, zeros
);
2016 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
2019 * Host or domain name...
2022 if (value
[0] == '*')
2025 if (strcasecmp(name
, "Allow") == 0)
2026 AllowHost(loc
, value
);
2028 DenyHost(loc
, value
);
2033 * One of many IP address forms...
2036 if (!get_addr_and_mask(value
, ip
, mask
))
2038 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
2043 if (strcasecmp(name
, "Allow") == 0)
2044 AllowIP(loc
, ip
, mask
);
2046 DenyIP(loc
, ip
, mask
);
2049 else if (strcasecmp(name
, "AuthType") == 0)
2052 * AuthType {none,basic,digest,basicdigest}
2055 if (strcasecmp(value
, "none") == 0)
2057 loc
->type
= AUTH_NONE
;
2058 loc
->level
= AUTH_ANON
;
2060 else if (strcasecmp(value
, "basic") == 0)
2062 loc
->type
= AUTH_BASIC
;
2064 if (loc
->level
== AUTH_ANON
)
2065 loc
->level
= AUTH_USER
;
2067 else if (strcasecmp(value
, "digest") == 0)
2069 loc
->type
= AUTH_DIGEST
;
2071 if (loc
->level
== AUTH_ANON
)
2072 loc
->level
= AUTH_USER
;
2074 else if (strcasecmp(value
, "basicdigest") == 0)
2076 loc
->type
= AUTH_BASICDIGEST
;
2078 if (loc
->level
== AUTH_ANON
)
2079 loc
->level
= AUTH_USER
;
2082 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
2085 else if (strcasecmp(name
, "AuthClass") == 0)
2088 * AuthClass anonymous, user, system, group
2091 if (strcasecmp(value
, "anonymous") == 0)
2093 loc
->type
= AUTH_NONE
;
2094 loc
->level
= AUTH_ANON
;
2096 else if (strcasecmp(value
, "user") == 0)
2097 loc
->level
= AUTH_USER
;
2098 else if (strcasecmp(value
, "group") == 0)
2099 loc
->level
= AUTH_GROUP
;
2100 else if (strcasecmp(value
, "system") == 0)
2102 loc
->level
= AUTH_GROUP
;
2105 * Use the default system group if none is defined so far...
2108 if (NumSystemGroups
== 0)
2109 NumSystemGroups
= 1;
2111 for (i
= 0; i
< NumSystemGroups
; i
++)
2112 AddName(loc
, SystemGroups
[i
]);
2115 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
2118 else if (strcasecmp(name
, "AuthGroupName") == 0)
2119 AddName(loc
, value
);
2120 else if (strcasecmp(name
, "Require") == 0)
2123 * Apache synonym for AuthClass and AuthGroupName...
2127 * Require valid-user
2128 * Require group names
2129 * Require user names
2132 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2137 if (strcasecmp(value
, "valid-user") == 0 ||
2138 strcasecmp(value
, "user") == 0)
2139 loc
->level
= AUTH_USER
;
2140 else if (strcasecmp(value
, "group") == 0)
2141 loc
->level
= AUTH_GROUP
;
2144 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2150 * Get the list of names from the line...
2153 for (value
= valptr
; *value
;)
2155 while (isspace(*value
& 255))
2158 if (*value
== '\"' || *value
== '\'')
2161 * Grab quoted name...
2164 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2171 * Grab literal name.
2174 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2180 AddName(loc
, value
);
2182 for (value
= valptr
; isspace(*value
& 255); value
++);
2185 else if (strcasecmp(name
, "Satisfy") == 0)
2187 if (strcasecmp(value
, "all") == 0)
2188 loc
->satisfy
= AUTH_SATISFY_ALL
;
2189 else if (strcasecmp(value
, "any") == 0)
2190 loc
->satisfy
= AUTH_SATISFY_ANY
;
2192 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2196 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2200 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading location!",
2208 * 'read_policy()' - Read a <Policy name> definition.
2211 static int /* O - New line number or 0 on error */
2212 read_policy(cups_file_t
*fp
, /* I - Configuration file */
2213 char *policy
, /* I - Location name/path */
2214 int linenum
) /* I - Current line number */
2216 int i
; /* Looping var */
2217 policy_t
*pol
; /* Policy */
2218 policyop_t
*op
; /* Policy operation */
2219 int num_ops
; /* Number of IPP operations */
2220 ipp_op_t ops
[100]; /* Operations */
2221 int len
; /* Length of line */
2222 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
2223 name
[256], /* Configuration directive */
2224 *nameptr
, /* Pointer into name */
2225 *value
, /* Value for directive */
2226 *valptr
; /* Pointer into value */
2230 * Create the policy...
2233 if ((pol
= AddPolicy(policy
)) == NULL
)
2237 * Read from the file...
2243 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
2248 * Skip comment lines...
2255 * Strip trailing whitespace, if any...
2260 while (len
> 0 && isspace(line
[len
- 1] & 255))
2267 * Extract the name from the beginning of the line...
2270 for (value
= line
; isspace(*value
& 255); value
++);
2272 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
2273 nameptr
< (name
+ sizeof(name
) - 1);)
2274 *nameptr
++ = *value
++;
2277 while (isspace(*value
& 255))
2280 if (name
[0] == '\0')
2284 * Decode the directive...
2287 if (!strcasecmp(name
, "</Policy>"))
2290 LogMessage(L_WARN
, "Missing </Limit> before </Policy> on line %d!",
2295 else if (!strcasecmp(name
, "<Limit") && !op
)
2298 * Scan for IPP operation names...
2305 for (valptr
= value
;
2306 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
2312 if (num_ops
< (int)(sizeof(ops
) / sizeof(ops
[0])))
2314 if ((ops
[num_ops
] = get_operation(value
)) == IPP_BAD_OPERATION
)
2315 LogMessage(L_ERROR
, "Bad IPP operation name \"%s\" on line %d!",
2321 LogMessage(L_ERROR
, "Too many operations listed on line %d!",
2324 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
2328 * If none are specified, apply the policy to all operations...
2333 ops
[0] = IPP_ANY_OPERATION
;
2338 * Add a new policy for the first operation...
2341 op
= AddPolicyOp(pol
, NULL
, ops
[0]);
2343 else if (!strcasecmp(name
, "</Limit>") && op
)
2346 * Finish the current operation limit...
2352 * Copy the policy to the other operations...
2355 for (i
= 1; i
< num_ops
; i
++)
2356 AddPolicyOp(pol
, op
, ops
[i
]);
2361 else if (!strcasecmp(name
, "Authenticate") && op
)
2364 * Authenticate boolean
2367 if (!strcasecmp(value
, "on") ||
2368 !strcasecmp(value
, "yes") ||
2369 !strcasecmp(value
, "true"))
2370 op
->authenticate
= 1;
2371 else if (!strcasecmp(value
, "off") ||
2372 !strcasecmp(value
, "no") ||
2373 !strcasecmp(value
, "false"))
2374 op
->authenticate
= 0;
2376 LogMessage(L_ERROR
, "Invalid Authenticate value \"%s\" on line %d!\n",
2379 else if (!strcasecmp(name
, "Order") && op
)
2382 * "Order Deny,Allow" or "Order Allow,Deny"...
2385 if (!strncasecmp(value
, "deny", 4))
2386 op
->order_type
= POLICY_ALLOW
;
2387 else if (!strncasecmp(value
, "allow", 5))
2388 op
->order_type
= POLICY_DENY
;
2390 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
2393 else if ((!strcasecmp(name
, "Allow") || !strcasecmp(name
, "Deny")) && op
)
2396 * Allow name, @group, @OWNER
2397 * Deny name, @group, @OWNER
2400 for (value
= valptr
; *value
;)
2402 while (isspace(*value
& 255))
2405 if (*value
== '\"' || *value
== '\'')
2408 * Grab quoted name...
2411 for (valptr
= value
+ 1; *valptr
!= *value
&& *valptr
; valptr
++);
2418 * Grab literal name.
2421 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2427 if (!strcasecmp(name
, "Allow"))
2428 AddPolicyOpName(op
, POLICY_ALLOW
, value
);
2430 AddPolicyOpName(op
, POLICY_DENY
, value
);
2432 for (value
= valptr
; isspace(*value
& 255); value
++);
2436 LogMessage(L_ERROR
, "Unknown Policy Limit directive %s on line %d.",
2439 LogMessage(L_ERROR
, "Unknown Policy directive %s on line %d.",
2443 LogMessage(L_ERROR
, "Unexpected end-of-file at line %d while reading policy \"%s\"!",
2451 * 'get_address()' - Get an address + port number from a line.
2454 static int /* O - 1 if address good, 0 if bad */
2455 get_address(const char *value
, /* I - Value string */
2456 unsigned defaddress
, /* I - Default address */
2457 int defport
, /* I - Default port */
2458 int deffamily
, /* I - Default family */
2459 http_addr_t
*address
) /* O - Socket address */
2461 char hostname
[256], /* Hostname or IP */
2462 portname
[256]; /* Port number or name */
2463 struct hostent
*host
; /* Host address */
2464 struct servent
*port
; /* Port number */
2468 * Initialize the socket address to the defaults...
2471 memset(address
, 0, sizeof(http_addr_t
));
2474 if (deffamily
== AF_INET6
)
2476 address
->ipv6
.sin6_family
= AF_INET6
;
2477 address
->ipv6
.sin6_addr
.s6_addr32
[0] = htonl(defaddress
);
2478 address
->ipv6
.sin6_addr
.s6_addr32
[1] = htonl(defaddress
);
2479 address
->ipv6
.sin6_addr
.s6_addr32
[2] = htonl(defaddress
);
2480 address
->ipv6
.sin6_addr
.s6_addr32
[3] = htonl(defaddress
);
2481 address
->ipv6
.sin6_port
= htons(defport
);
2484 #endif /* AF_INET6 */
2486 address
->ipv4
.sin_family
= AF_INET
;
2487 address
->ipv4
.sin_addr
.s_addr
= htonl(defaddress
);
2488 address
->ipv4
.sin_port
= htons(defport
);
2493 * If the address starts with a "/", it is a domain socket...
2498 if (strlen(value
) >= sizeof(address
->un
.sun_path
))
2500 LogMessage(L_ERROR
, "Domain socket name \"%s\" too long!", value
);
2504 address
->un
.sun_family
= AF_LOCAL
;
2505 strcpy(address
->un
.sun_path
, value
);
2509 #endif /* AF_LOCAL */
2512 * Try to grab a hostname and port number...
2515 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2518 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2521 * Hostname is a port number...
2524 strlcpy(portname
, hostname
, sizeof(portname
));
2535 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2540 * Decode the hostname and port number as needed...
2543 if (hostname
[0] && strcmp(hostname
, "*"))
2545 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2547 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2548 hstrerror(h_errno
));
2552 httpAddrLoad(host
, defport
, 0, address
);
2555 if (portname
[0] != '\0')
2557 if (isdigit(portname
[0] & 255))
2560 if (address
->addr
.sa_family
== AF_INET6
)
2561 address
->ipv6
.sin6_port
= htons(atoi(portname
));
2563 #endif /* AF_INET6 */
2564 address
->ipv4
.sin_port
= htons(atoi(portname
));
2568 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2570 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2577 if (address
->addr
.sa_family
== AF_INET6
)
2578 address
->ipv6
.sin6_port
= htons(port
->s_port
);
2580 #endif /* AF_INET6 */
2581 address
->ipv4
.sin_port
= htons(port
->s_port
);
2591 * 'get_addr_and_mask()' - Get an IP address and netmask.
2594 static int /* O - 1 on success, 0 on failure */
2595 get_addr_and_mask(const char *value
, /* I - String from config file */
2596 unsigned *ip
, /* O - Address value */
2597 unsigned *mask
) /* O - Mask value */
2599 int i
, /* Looping var */
2600 family
, /* Address family */
2601 ipcount
; /* Count of fields in address */
2602 static unsigned netmasks
[4][4] = /* Standard netmasks... */
2604 { 0xffffffff, 0x00000000, 0x00000000, 0x00000000 },
2605 { 0xffffffff, 0xffffffff, 0x00000000, 0x00000000 },
2606 { 0xffffffff, 0xffffffff, 0xffffffff, 0x00000000 },
2607 { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff }
2612 * Get the address...
2615 memset(ip
, 0, sizeof(unsigned) * 4);
2617 ipcount
= sscanf(value
, "%u.%u.%u.%u", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
2621 * See if we have any values > 255; if so, this is an IPv6 address only.
2624 for (i
= 0; i
< ipcount
; i
++)
2630 #endif /* AF_INET6 */
2632 if ((value
= strchr(value
, '/')) != NULL
)
2635 * Get the netmask value(s)...
2639 memset(mask
, 0, sizeof(unsigned) * 4);
2640 switch (sscanf(value
, "%u.%u.%u.%u", mask
+ 0, mask
+ 1,
2641 mask
+ 2, mask
+ 3))
2648 if (family
== AF_INET6
)
2653 mask
[0] = 0xffffffff;
2655 mask
[0] = (0xffffffff << (128 - mask
[0])) & 0xffffffff;
2658 mask
[1] = 0xffffffff;
2662 mask
[1] = (0xffffffff << (96 - mask
[0])) & 0xffffffff;
2665 mask
[1] = 0xffffffff;
2669 mask
[1] = (0xffffffff << (64 - mask
[0])) & 0xffffffff;
2674 mask
[1] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2677 #endif /* AF_INET6 */
2682 mask
[0] = 0xffffffff;
2684 mask
[0] = (0xffffffff << (32 - mask
[0])) & 0xffffffff;
2687 mask
[1] = 0xffffffff;
2691 mask
[1] = (0xffffffff << (24 - mask
[0])) & 0xffffffff;
2694 mask
[1] = 0xffffffff;
2698 mask
[1] = (0xffffffff << (16 - mask
[0])) & 0xffffffff;
2703 mask
[1] = (0xffffffff << (8 - mask
[0])) & 0xffffffff;
2714 memcpy(mask
, netmasks
[ipcount
- 1], sizeof(unsigned) * 4);
2717 * Check for a valid netmask; no fallback like in CUPS 1.1.x!
2720 if ((ip
[0] & ~mask
[0]) != 0 ||
2721 (ip
[1] & ~mask
[1]) != 0 ||
2722 (ip
[2] & ~mask
[2]) != 0 ||
2723 (ip
[3] & ~mask
[3]) != 0)
2731 * 'get_operation()' - Get an IPP opcode from an operation name...
2734 static ipp_op_t
/* O - Operation code or -1 on error */
2735 get_operation(const char *name
) /* I - Operating name */
2737 int i
; /* Looping var */
2738 static const char * const ipp_ops
[] = /* List of standard operations */
2742 /* 0x0002 */ "print-job",
2743 /* 0x0003 */ "print-uri",
2744 /* 0x0004 */ "validate-job",
2745 /* 0x0005 */ "create-job",
2746 /* 0x0006 */ "send-document",
2747 /* 0x0007 */ "send-uri",
2748 /* 0x0008 */ "cancel-job",
2749 /* 0x0009 */ "get-job-attributes",
2750 /* 0x000a */ "get-jobs",
2751 /* 0x000b */ "get-printer-attributes",
2752 /* 0x000c */ "hold-job",
2753 /* 0x000d */ "release-job",
2754 /* 0x000e */ "restart-job",
2756 /* 0x0010 */ "pause-printer",
2757 /* 0x0011 */ "resume-printer",
2758 /* 0x0012 */ "purge-jobs",
2759 /* 0x0013 */ "set-printer-attributes",
2760 /* 0x0014 */ "set-job-attributes",
2761 /* 0x0015 */ "get-printer-supported-values",
2762 /* 0x0016 */ "create-printer-subscription",
2763 /* 0x0017 */ "create-job-subscription",
2764 /* 0x0018 */ "get-subscription-attributes",
2765 /* 0x0019 */ "get-subscriptions",
2766 /* 0x001a */ "renew-subscription",
2767 /* 0x001b */ "cancel-subscription",
2768 /* 0x001c */ "get-notifications",
2769 /* 0x001d */ "send-notifications",
2773 /* 0x0021 */ "get-print-support-files",
2774 /* 0x0022 */ "enable-printer",
2775 /* 0x0023 */ "disable-printer",
2776 /* 0x0024 */ "pause-printer-after-current-job",
2777 /* 0x0025 */ "hold-new-jobs",
2778 /* 0x0026 */ "release-held-new-jobs",
2779 /* 0x0027 */ "deactivate-printer",
2780 /* 0x0028 */ "activate-printer",
2781 /* 0x0029 */ "restart-printer",
2782 /* 0x002a */ "shutdown-printer",
2783 /* 0x002b */ "startup-printer",
2784 /* 0x002c */ "reprocess-job",
2785 /* 0x002d */ "cancel-current-job",
2786 /* 0x002e */ "suspend-current-job",
2787 /* 0x002f */ "resume-job",
2788 /* 0x0030 */ "promote-job",
2789 /* 0x0031 */ "schedule-job-after"
2791 *cups_ops
[] = /* List of CUPS operations */
2793 /* 0x4001 */ "cups-get-default",
2794 /* 0x4002 */ "cups-get-printers",
2795 /* 0x4003 */ "cups-add-printer",
2796 /* 0x4004 */ "cups-delete-printer",
2797 /* 0x4005 */ "cups-get-classes",
2798 /* 0x4006 */ "cups-add-class",
2799 /* 0x4007 */ "cups-delete-class",
2800 /* 0x4008 */ "cups-accept-jobs",
2801 /* 0x4009 */ "cups-reject-jobs",
2802 /* 0x400a */ "cups-set-default",
2803 /* 0x400b */ "cups-get-devices",
2804 /* 0x400c */ "cups-get-ppds",
2805 /* 0x400d */ "cups-move-job",
2806 /* 0x400e */ "cups-add-device",
2807 /* 0x400f */ "cups-delete-device"
2811 for (i
= 0; i
< (int)(sizeof(ipp_ops
) / sizeof(ipp_ops
[0])); i
++)
2812 if (!strcasecmp(name
, ipp_ops
[i
]))
2813 return ((ipp_op_t
)i
);
2815 for (i
= 0; i
< (int)(sizeof(cups_ops
) / sizeof(cups_ops
[0])); i
++)
2816 if (!strcasecmp(name
, cups_ops
[i
]))
2817 return ((ipp_op_t
)(i
+ 0x4001));
2819 return ((ipp_op_t
)-1);
2825 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2826 * required by SSLSetCertificate.
2828 * For now we assumes that there is exactly one SecIdentity in the
2829 * keychain - i.e. there is exactly one matching cert/private key pair.
2830 * In the future we will search a keychain for a SecIdentity matching a
2831 * specific criteria. We also skip the operation of adding additional
2832 * non-signing certs from the keychain to the CFArrayRef.
2834 * To create a self-signed certificate for testing use the certtool.
2835 * Executing the following as root will do it:
2837 * certtool c c v k=CUPS
2841 CDSAGetServerCerts(void)
2843 OSStatus err
; /* Error info */
2844 SecKeychainRef kcRef
; /* Keychain reference */
2845 SecIdentitySearchRef srchRef
; /* Search reference */
2846 SecIdentityRef identity
; /* Identity */
2847 CFArrayRef ca
; /* Certificate array */
2854 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2857 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2858 ServerCertificate
, err
);
2862 * Search for "any" identity matching specified key use;
2863 * in this app, we expect there to be exactly one.
2866 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2870 "Cannot find signing key in keychain \"%s\", error %d",
2871 ServerCertificate
, err
);
2874 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2878 "Cannot find signing key in keychain \"%s\", error %d",
2879 ServerCertificate
, err
);
2882 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2883 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2887 * Found one. Place it in a CFArray.
2888 * TBD: snag other (non-identity) certs from keychain and add them
2892 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2895 LogMessage(L_ERROR
, "CFArrayCreate error");
2898 /*CFRelease(identity);*/
2901 /*CFRelease(srchRef);*/
2904 /*CFRelease(kcRef);*/
2909 #endif /* HAVE_CDSASSL */
2913 * End of "$Id: conf.c,v 1.77.2.59 2004/07/02 04:51:45 mike Exp $".