2 * "$Id: conf.c,v 1.149 2004/07/06 00:34:56 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 * get_address() - Get an address + port number from a line.
30 * CDSAGetServerCerts() - Convert a keychain name into the CFArrayRef
31 * required by SSLSetCertificate.
35 * Include necessary headers...
42 #include <sys/utsname.h>
45 # include <Security/SecureTransport.h>
46 # include <Security/SecIdentitySearch.h>
47 #endif /* HAVE_CDSASSL */
51 #endif /* HAVE_VSYSLOG */
55 * Possibly missing network definitions...
59 # define INADDR_NONE 0xffffffff
60 #endif /* !INADDR_NONE */
64 * Configuration variable structure...
69 char *name
; /* Name of variable */
70 void *ptr
; /* Pointer to variable */
71 int type
; /* Type (int, string, address) */
83 static var_t variables
[] =
85 { "AccessLog", &AccessLog
, VAR_STRING
},
86 { "AutoPurgeJobs", &JobAutoPurge
, VAR_BOOLEAN
},
87 { "BrowseInterval", &BrowseInterval
, VAR_INTEGER
},
88 { "BrowsePort", &BrowsePort
, VAR_INTEGER
},
89 { "BrowseShortNames", &BrowseShortNames
, VAR_BOOLEAN
},
90 { "BrowseTimeout", &BrowseTimeout
, VAR_INTEGER
},
91 { "Browsing", &Browsing
, VAR_BOOLEAN
},
92 { "Classification", &Classification
, VAR_STRING
},
93 { "ClassifyOverride", &ClassifyOverride
, VAR_BOOLEAN
},
94 { "ConfigFilePerm", &ConfigFilePerm
, VAR_INTEGER
},
95 { "DataDir", &DataDir
, VAR_STRING
},
96 { "DefaultCharset", &DefaultCharset
, VAR_STRING
},
97 { "DefaultLanguage", &DefaultLanguage
, VAR_STRING
},
98 { "DocumentRoot", &DocumentRoot
, VAR_STRING
},
99 { "ErrorLog", &ErrorLog
, VAR_STRING
},
100 { "FaxRetryLimit", &FaxRetryLimit
, VAR_INTEGER
},
101 { "FaxRetryInterval", &FaxRetryInterval
, VAR_INTEGER
},
102 { "FileDevice", &FileDevice
, VAR_BOOLEAN
},
103 { "FilterLimit", &FilterLimit
, VAR_INTEGER
},
104 { "FilterNice", &FilterNice
, VAR_INTEGER
},
105 { "FontPath", &FontPath
, VAR_STRING
},
106 { "HideImplicitMembers", &HideImplicitMembers
, VAR_BOOLEAN
},
107 { "ImplicitClasses", &ImplicitClasses
, VAR_BOOLEAN
},
108 { "ImplicitAnyClasses", &ImplicitAnyClasses
, VAR_BOOLEAN
},
109 { "KeepAliveTimeout", &KeepAliveTimeout
, VAR_INTEGER
},
110 { "KeepAlive", &KeepAlive
, VAR_BOOLEAN
},
111 { "LimitRequestBody", &MaxRequestSize
, VAR_INTEGER
},
112 { "ListenBackLog", &ListenBackLog
, VAR_INTEGER
},
113 { "LogFilePerm", &LogFilePerm
, VAR_INTEGER
},
114 { "MaxClients", &MaxClients
, VAR_INTEGER
},
115 { "MaxClientsPerHost", &MaxClientsPerHost
, VAR_INTEGER
},
116 { "MaxCopies", &MaxCopies
, VAR_INTEGER
},
117 { "MaxJobs", &MaxJobs
, VAR_INTEGER
},
118 { "MaxJobsPerPrinter", &MaxJobsPerPrinter
, VAR_INTEGER
},
119 { "MaxJobsPerUser", &MaxJobsPerUser
, VAR_INTEGER
},
120 { "MaxLogSize", &MaxLogSize
, VAR_INTEGER
},
121 { "MaxPrinterHistory", &MaxPrinterHistory
, VAR_INTEGER
},
122 { "MaxRequestSize", &MaxRequestSize
, VAR_INTEGER
},
123 { "PageLog", &PageLog
, VAR_STRING
},
124 { "PreserveJobFiles", &JobFiles
, VAR_BOOLEAN
},
125 { "PreserveJobHistory", &JobHistory
, VAR_BOOLEAN
},
126 { "Printcap", &Printcap
, VAR_STRING
},
127 { "PrintcapGUI", &PrintcapGUI
, VAR_STRING
},
128 { "RemoteRoot", &RemoteRoot
, VAR_STRING
},
129 { "RequestRoot", &RequestRoot
, VAR_STRING
},
130 { "RIPCache", &RIPCache
, VAR_STRING
},
131 { "RunAsUser", &RunAsUser
, VAR_BOOLEAN
},
132 { "RootCertDuration", &RootCertDuration
, VAR_INTEGER
},
133 { "ServerAdmin", &ServerAdmin
, VAR_STRING
},
134 { "ServerBin", &ServerBin
, VAR_STRING
},
136 { "ServerCertificate", &ServerCertificate
, VAR_STRING
},
137 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
138 { "ServerKey", &ServerKey
, VAR_STRING
},
139 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
140 #endif /* HAVE_SSL */
141 { "ServerName", &ServerName
, VAR_STRING
},
142 { "ServerRoot", &ServerRoot
, VAR_STRING
},
143 { "TempDir", &TempDir
, VAR_STRING
},
144 { "Timeout", &Timeout
, VAR_INTEGER
}
146 #define NUM_VARS (sizeof(variables) / sizeof(variables[0]))
153 static int read_configuration(cups_file_t
*fp
);
154 static int read_location(cups_file_t
*fp
, char *name
, int linenum
);
155 static int get_address(char *value
, unsigned defaddress
, int defport
,
156 struct sockaddr_in
*address
);
159 static CFArrayRef
CDSAGetServerCerts();
160 #endif /* HAVE_CDSASSL */
164 * 'ReadConfiguration()' - Read the cupsd.conf file.
167 int /* O - 1 on success, 0 otherwise */
168 ReadConfiguration(void)
170 int i
; /* Looping var */
171 cups_file_t
*fp
; /* Configuration file */
172 int status
; /* Return status */
173 char temp
[1024], /* Temporary buffer */
174 *slash
; /* Directory separator */
175 char type
[MIME_MAX_SUPER
+ MIME_MAX_TYPE
];
177 char *language
; /* Language string */
178 struct passwd
*user
; /* Default user */
179 struct group
*group
; /* Default group */
180 char *old_serverroot
, /* Old ServerRoot */
181 *old_requestroot
; /* Old RequestRoot */
185 * Shutdown the server...
191 * Save the old root paths...
194 old_serverroot
= NULL
;
195 SetString(&old_serverroot
, ServerRoot
);
196 old_requestroot
= NULL
;
197 SetString(&old_requestroot
, RequestRoot
);
200 * Reset the server configuration data...
203 DeleteAllLocations();
221 for (i
= 0; i
< NumRelays
; i
++)
222 if (Relays
[i
].from
.type
== AUTH_NAME
)
223 free(Relays
[i
].from
.mask
.name
.name
);
230 if (NumListeners
> 0)
241 gethostname(temp
, sizeof(temp
));
242 SetString(&ServerName
, temp
);
243 SetStringf(&ServerAdmin
, "root@%s", temp
);
244 SetString(&ServerBin
, CUPS_SERVERBIN
);
245 SetString(&RequestRoot
, CUPS_REQUESTS
);
246 SetString(&DocumentRoot
, CUPS_DOCROOT
);
247 SetString(&DataDir
, CUPS_DATADIR
);
248 SetString(&AccessLog
, CUPS_LOGDIR
"/access_log");
249 SetString(&ErrorLog
, CUPS_LOGDIR
"/error_log");
250 SetString(&PageLog
, CUPS_LOGDIR
"/page_log");
251 SetString(&Printcap
, "/etc/printcap");
252 SetString(&PrintcapGUI
, "/usr/bin/glpoptions");
253 SetString(&FontPath
, CUPS_FONTPATH
);
254 SetString(&RemoteRoot
, "remroot");
255 SetString(&ServerHeader
, "CUPS/1.1");
257 strlcpy(temp
, ConfigurationFile
, sizeof(temp
));
258 if ((slash
= strrchr(temp
, '/')) != NULL
)
261 SetString(&ServerRoot
, temp
);
263 ClearString(&Classification
);
264 ClassifyOverride
= 0;
268 SetString(&ServerCertificate
, "/var/root/Library/Keychains/CUPS");
270 SetString(&ServerCertificate
, "ssl/server.crt");
271 SetString(&ServerKey
, "ssl/server.key");
272 # endif /* HAVE_CDSASSL */
273 #endif /* HAVE_SSL */
275 if ((language
= DEFAULT_LANGUAGE
) == NULL
)
277 else if (strcmp(language
, "C") == 0 || strcmp(language
, "POSIX") == 0)
280 SetString(&DefaultLanguage
, language
);
281 SetString(&DefaultCharset
, DEFAULT_CHARSET
);
283 SetString(&RIPCache
, "8m");
285 if (getenv("TMPDIR") == NULL
)
286 SetString(&TempDir
, CUPS_REQUESTS
"/tmp");
288 SetString(&TempDir
, getenv("TMPDIR"));
291 * Find the default system group: "sys", "system", or "root"...
294 group
= getgrnam(CUPS_DEFAULT_GROUP
);
301 SetString(&SystemGroups
[0], CUPS_DEFAULT_GROUP
);
302 Group
= group
->gr_gid
;
311 SetString(&SystemGroups
[0], group
->gr_name
);
316 SetString(&SystemGroups
[0], "unknown");
322 * Find the default user...
325 if ((user
= getpwnam(CUPS_DEFAULT_USER
)) == NULL
)
326 User
= 1; /* Force to a non-priviledged account */
336 ConfigFilePerm
= 0640;
340 FaxRetryInterval
= 300;
345 HostNameLookups
= FALSE
;
346 ImplicitClasses
= TRUE
;
347 ImplicitAnyClasses
= FALSE
;
348 HideImplicitMembers
= TRUE
;
350 KeepAliveTimeout
= DEFAULT_KEEPALIVE
;
351 ListenBackLog
= SOMAXCONN
;
354 MaxClientsPerHost
= 0;
355 MaxLogSize
= 1024 * 1024;
356 MaxPrinterHistory
= 10;
358 RootCertDuration
= 300;
360 Timeout
= DEFAULT_TIMEOUT
;
362 BrowseInterval
= DEFAULT_INTERVAL
;
363 BrowsePort
= ippPort();
364 BrowseProtocols
= BROWSE_CUPS
;
365 BrowseShortNames
= TRUE
;
366 BrowseTimeout
= DEFAULT_TIMEOUT
;
369 JobHistory
= DEFAULT_HISTORY
;
370 JobFiles
= DEFAULT_FILES
;
374 MaxJobsPerPrinter
= 0;
378 * Read the configuration file...
381 if ((fp
= cupsFileOpen(ConfigurationFile
, "r")) == NULL
)
384 status
= read_configuration(fp
);
397 * Use the default system group if none was supplied in cupsd.conf...
400 if (NumSystemGroups
== 0)
404 * Get the access control list for browsing...
407 BrowseACL
= FindLocation("CUPS_INTERNAL_BROWSE_ACL");
410 * Open the system log for cupsd if necessary...
414 if (strcmp(AccessLog
, "syslog") == 0 ||
415 strcmp(ErrorLog
, "syslog") == 0 ||
416 strcmp(PageLog
, "syslog") == 0)
417 openlog("cupsd", LOG_PID
| LOG_NOWAIT
| LOG_NDELAY
, LOG_LPR
);
418 #endif /* HAVE_VSYSLOG */
421 * Log the configuration file that was used...
424 LogMessage(L_INFO
, "Loaded configuration file \"%s\"", ConfigurationFile
);
427 * Check that we have at least one listen/port line; if not, report this
428 * as an error and exit!
431 if (NumListeners
== 0)
437 LogMessage(L_EMERG
, "No valid Listen or Port lines were found in the configuration file!");
443 kill(getpid(), SIGTERM
);
447 * Set the default locale using the language and charset...
450 SetStringf(&DefaultLocale
, "%s.%s", DefaultLanguage
, DefaultCharset
);
453 * Update all relative filenames to include the full path from ServerRoot...
456 if (DocumentRoot
[0] != '/')
457 SetStringf(&DocumentRoot
, "%s/%s", ServerRoot
, DocumentRoot
);
459 if (RequestRoot
[0] != '/')
460 SetStringf(&RequestRoot
, "%s/%s", ServerRoot
, RequestRoot
);
462 if (ServerBin
[0] != '/')
463 SetStringf(&ServerBin
, "%s/%s", ServerRoot
, ServerBin
);
466 if (ServerCertificate
[0] != '/')
467 SetStringf(&ServerCertificate
, "%s/%s", ServerRoot
, ServerCertificate
);
469 # if defined(HAVE_LIBSSL) || defined(HAVE_GNUTLS)
470 chown(ServerCertificate
, RunUser
, Group
);
471 chmod(ServerCertificate
, ConfigFilePerm
);
473 if (ServerKey
[0] != '/')
474 SetStringf(&ServerKey
, "%s/%s", ServerRoot
, ServerKey
);
476 chown(ServerKey
, RunUser
, Group
);
477 chmod(ServerKey
, ConfigFilePerm
);
478 # endif /* HAVE_LIBSSL || HAVE_GNUTLS */
479 #endif /* HAVE_SSL */
482 * Make sure that ServerRoot and the config files are owned and
483 * writable by the user and group in the cupsd.conf file...
486 chown(ServerRoot
, RunUser
, Group
);
487 chmod(ServerRoot
, 0775);
489 snprintf(temp
, sizeof(temp
), "%s/certs", ServerRoot
);
490 chown(temp
, RunUser
, Group
);
493 snprintf(temp
, sizeof(temp
), "%s/ppd", ServerRoot
);
494 chown(temp
, RunUser
, Group
);
497 snprintf(temp
, sizeof(temp
), "%s/ssl", ServerRoot
);
498 chown(temp
, RunUser
, Group
);
501 snprintf(temp
, sizeof(temp
), "%s/cupsd.conf", ServerRoot
);
502 chown(temp
, RunUser
, Group
);
503 chmod(temp
, ConfigFilePerm
);
505 snprintf(temp
, sizeof(temp
), "%s/classes.conf", ServerRoot
);
506 chown(temp
, RunUser
, Group
);
510 chmod(temp
, ConfigFilePerm
);
511 #endif /* __APPLE__ */
513 snprintf(temp
, sizeof(temp
), "%s/printers.conf", ServerRoot
);
514 chown(temp
, RunUser
, Group
);
518 chmod(temp
, ConfigFilePerm
);
519 #endif /* __APPLE__ */
521 snprintf(temp
, sizeof(temp
), "%s/passwd.md5", ServerRoot
);
522 chown(temp
, User
, Group
);
526 * Make sure the request and temporary directories have the right
530 chown(RequestRoot
, RunUser
, Group
);
531 chmod(RequestRoot
, 0710);
533 if (strncmp(TempDir
, RequestRoot
, strlen(RequestRoot
)) == 0)
536 * Only update ownership and permissions if the CUPS temp directory
537 * is under the spool directory...
540 chown(TempDir
, RunUser
, Group
);
541 chmod(TempDir
, 01770);
545 * Check the MaxClients setting, and then allocate memory for it...
548 if (MaxClients
> (MaxFDs
/ 3) || MaxClients
<= 0)
551 LogMessage(L_INFO
, "MaxClients limited to 1/3 of the file descriptor limit (%d)...",
554 MaxClients
= MaxFDs
/ 3;
557 if ((Clients
= calloc(sizeof(client_t
), MaxClients
)) == NULL
)
559 LogMessage(L_ERROR
, "ReadConfiguration: Unable to allocate memory for %d clients: %s",
560 MaxClients
, strerror(errno
));
564 LogMessage(L_INFO
, "Configured for up to %d clients.", MaxClients
);
566 if (Classification
&& strcasecmp(Classification
, "none") == 0)
567 ClearString(&Classification
);
570 LogMessage(L_INFO
, "Security set to \"%s\"", Classification
);
573 * Update the MaxClientsPerHost value, as needed...
576 if (MaxClientsPerHost
<= 0)
577 MaxClientsPerHost
= MaxClients
;
579 if (MaxClientsPerHost
> MaxClients
)
580 MaxClientsPerHost
= MaxClients
;
582 LogMessage(L_INFO
, "Allowing up to %d client connections per host.",
586 * If we are doing a full reload or the server root has changed, flush
587 * the jobs, printers, etc. and start from scratch...
590 if (NeedReload
== RELOAD_ALL
||
591 !old_serverroot
|| !ServerRoot
|| strcmp(old_serverroot
, ServerRoot
) ||
592 !old_requestroot
|| !RequestRoot
|| strcmp(old_requestroot
, RequestRoot
))
594 LogMessage(L_INFO
, "Full reload is required.");
604 DefaultPrinter
= NULL
;
618 if (MimeDatabase
!= NULL
)
619 mimeDelete(MimeDatabase
);
623 for (i
= 0; i
< NumMimeTypes
; i
++)
624 free((void *)MimeTypes
[i
]);
630 * Read the MIME type and conversion database...
633 snprintf(temp
, sizeof(temp
), "%s/filter", ServerBin
);
635 MimeDatabase
= mimeNew();
636 mimeMerge(MimeDatabase
, ServerRoot
, temp
);
639 * Create a list of MIME types for the document-format-supported
643 NumMimeTypes
= MimeDatabase
->num_types
;
644 if (!mimeType(MimeDatabase
, "application", "octet-stream"))
647 MimeTypes
= calloc(NumMimeTypes
, sizeof(const char *));
649 for (i
= 0; i
< MimeDatabase
->num_types
; i
++)
651 snprintf(type
, sizeof(type
), "%s/%s", MimeDatabase
->types
[i
]->super
,
652 MimeDatabase
->types
[i
]->type
);
654 MimeTypes
[i
] = strdup(type
);
657 if (i
< NumMimeTypes
)
658 MimeTypes
[i
] = strdup("application/octet-stream");
664 snprintf(temp
, sizeof(temp
), "%s/banners", DataDir
);
668 * Load printers and classes...
677 * Load devices and PPDs...
680 snprintf(temp
, sizeof(temp
), "%s/backend", ServerBin
);
683 snprintf(temp
, sizeof(temp
), "%s/model", DataDir
);
687 * Load queued jobs...
692 LogMessage(L_INFO
, "Full reload complete.");
698 LogMessage(L_INFO
, "Partial reload complete.");
702 * Reset the reload state...
705 NeedReload
= RELOAD_NONE
;
707 ClearString(&old_serverroot
);
708 ClearString(&old_requestroot
);
711 * Startup the server and return...
721 * 'read_configuration()' - Read a configuration file.
724 static int /* O - 1 on success, 0 on failure */
725 read_configuration(cups_file_t
*fp
) /* I - File to read from */
727 int i
; /* Looping var */
728 int linenum
; /* Current line number */
729 int len
; /* Length of line */
730 char line
[HTTP_MAX_BUFFER
], /* Line from file */
731 name
[256], /* Parameter name */
732 *nameptr
, /* Pointer into name */
733 *value
; /* Pointer to value */
734 int valuelen
; /* Length of value */
735 var_t
*var
; /* Current variable */
736 unsigned address
, /* Address value */
737 netmask
; /* Netmask value */
738 int ip
[4], /* IP address components */
739 ipcount
, /* Number of components provided */
740 mask
[4]; /* IP netmask components */
741 dirsvc_relay_t
*relay
; /* Relay data */
742 dirsvc_poll_t
*poll
; /* Polling data */
743 struct sockaddr_in polladdr
; /* Polling address */
744 location_t
*location
; /* Browse location */
745 cups_file_t
*incfile
; /* Include file */
746 char incname
[1024]; /* Include filename */
747 static unsigned netmasks
[4] = /* Standard netmasks... */
757 * Loop through each line in the file...
762 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
767 * Skip comment lines...
774 * Strip trailing whitespace, if any...
779 while (len
> 0 && isspace(line
[len
- 1]))
786 * Extract the name from the beginning of the line...
789 for (value
= line
; isspace(*value
); value
++);
791 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
) &&
792 nameptr
< (name
+ sizeof(name
) - 1);)
793 *nameptr
++ = *value
++;
796 while (isspace(*value
))
803 * Decode the directive...
806 if (strcasecmp(name
, "Include") == 0)
813 strlcpy(incname
, value
, sizeof(incname
));
815 snprintf(incname
, sizeof(incname
), "%s/%s", ServerRoot
, value
);
817 if ((incfile
= cupsFileOpen(incname
, "rb")) == NULL
)
818 LogMessage(L_ERROR
, "Unable to include config file \"%s\" - %s",
819 incname
, strerror(errno
));
822 read_configuration(incfile
);
823 cupsFileClose(incfile
);
826 else if (strcasecmp(name
, "<Location") == 0)
832 if (line
[len
- 1] == '>')
834 line
[len
- 1] = '\0';
836 linenum
= read_location(fp
, value
, linenum
);
842 LogMessage(L_ERROR
, "Syntax error on line %d.",
847 else if (strcasecmp(name
, "Port") == 0 ||
848 strcasecmp(name
, "Listen") == 0)
851 * Add a listening address to the list...
854 listener_t
*temp
; /* New listeners array */
857 if (NumListeners
== 0)
858 temp
= malloc(sizeof(listener_t
));
860 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
864 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
865 name
, linenum
, strerror(errno
));
870 temp
+= NumListeners
;
872 memset(temp
, 0, sizeof(listener_t
));
874 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
876 LogMessage(L_INFO
, "Listening to %x:%d",
877 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
878 ntohs(temp
->address
.sin_port
));
882 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
886 else if (strcasecmp(name
, "SSLPort") == 0 ||
887 strcasecmp(name
, "SSLListen") == 0)
890 * Add a listening address to the list...
893 listener_t
*temp
; /* New listeners array */
896 if (NumListeners
== 0)
897 temp
= malloc(sizeof(listener_t
));
899 temp
= realloc(Listeners
, (NumListeners
+ 1) * sizeof(listener_t
));
903 LogMessage(L_ERROR
, "Unable to allocate %s at line %d - %s.",
904 name
, linenum
, strerror(errno
));
909 temp
+= NumListeners
;
911 if (get_address(value
, INADDR_ANY
, IPP_PORT
, &(temp
->address
)))
913 LogMessage(L_INFO
, "Listening to %x:%d (SSL)",
914 (unsigned)ntohl(temp
->address
.sin_addr
.s_addr
),
915 ntohs(temp
->address
.sin_port
));
916 temp
->encryption
= HTTP_ENCRYPT_ALWAYS
;
920 LogMessage(L_ERROR
, "Bad %s address %s at line %d.", name
,
923 #endif /* HAVE_SSL */
924 else if (strcasecmp(name
, "BrowseAddress") == 0)
927 * Add a browse address to the list...
930 dirsvc_addr_t
*temp
; /* New browse address array */
933 if (NumBrowsers
== 0)
934 temp
= malloc(sizeof(dirsvc_addr_t
));
936 temp
= realloc(Browsers
, (NumBrowsers
+ 1) * sizeof(dirsvc_addr_t
));
940 LogMessage(L_ERROR
, "Unable to allocate BrowseAddress at line %d - %s.",
941 linenum
, strerror(errno
));
948 memset(temp
, 0, sizeof(dirsvc_addr_t
));
950 if (strcasecmp(value
, "@LOCAL") == 0)
953 * Send browse data to all local interfaces...
956 strcpy(temp
->iface
, "*");
959 else if (strncasecmp(value
, "@IF(", 4) == 0)
962 * Send browse data to the named interface...
965 strlcpy(temp
->iface
, value
+ 4, sizeof(Browsers
[0].iface
));
967 nameptr
= temp
->iface
+ strlen(temp
->iface
) - 1;
973 else if (get_address(value
, INADDR_NONE
, BrowsePort
, &(temp
->to
)))
975 LogMessage(L_INFO
, "Sending browsing info to %x:%d",
976 (unsigned)ntohl(temp
->to
.sin_addr
.s_addr
),
977 ntohs(temp
->to
.sin_port
));
982 LogMessage(L_ERROR
, "Bad BrowseAddress %s at line %d.", value
,
985 else if (strcasecmp(name
, "BrowseOrder") == 0)
988 * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"...
991 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
992 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
994 if (location
== NULL
)
995 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
996 else if (strncasecmp(value
, "deny", 4) == 0)
997 location
->order_type
= AUTH_ALLOW
;
998 else if (strncasecmp(value
, "allow", 5) == 0)
999 location
->order_type
= AUTH_DENY
;
1001 LogMessage(L_ERROR
, "Unknown BrowseOrder value %s on line %d.",
1004 else if (strcasecmp(name
, "BrowseProtocols") == 0)
1007 * "BrowseProtocol name [... name]"
1010 BrowseProtocols
= 0;
1014 for (valuelen
= 0; value
[valuelen
]; valuelen
++)
1015 if (isspace(value
[valuelen
]) || value
[valuelen
] == ',')
1018 if (value
[valuelen
])
1020 value
[valuelen
] = '\0';
1024 if (strcasecmp(value
, "cups") == 0)
1025 BrowseProtocols
|= BROWSE_CUPS
;
1026 else if (strcasecmp(value
, "slp") == 0)
1027 BrowseProtocols
|= BROWSE_SLP
;
1028 else if (strcasecmp(value
, "ldap") == 0)
1029 BrowseProtocols
|= BROWSE_LDAP
;
1030 else if (strcasecmp(value
, "all") == 0)
1031 BrowseProtocols
|= BROWSE_ALL
;
1034 LogMessage(L_ERROR
, "Unknown browse protocol \"%s\" on line %d.",
1039 for (value
+= valuelen
; *value
; value
++)
1040 if (!isspace(*value
) || *value
!= ',')
1044 else if (strcasecmp(name
, "BrowseAllow") == 0 ||
1045 strcasecmp(name
, "BrowseDeny") == 0)
1048 * BrowseAllow [From] host/ip...
1049 * BrowseDeny [From] host/ip...
1052 if ((location
= FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL
)
1053 location
= AddLocation("CUPS_INTERNAL_BROWSE_ACL");
1055 if (location
== NULL
)
1056 LogMessage(L_ERROR
, "Unable to initialize browse access control list!");
1059 if (strncasecmp(value
, "from ", 5) == 0)
1062 * Strip leading "from"...
1067 while (isspace(*value
))
1072 * Figure out what form the allow/deny address takes:
1083 * nnn.nnn.nnn.nnn/mm
1084 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1087 if (strcasecmp(value
, "all") == 0)
1093 if (strcasecmp(name
, "BrowseAllow") == 0)
1094 AllowIP(location
, 0, 0);
1096 DenyIP(location
, 0, 0);
1098 else if (strcasecmp(value
, "none") == 0)
1104 if (strcasecmp(name
, "BrowseAllow") == 0)
1105 AllowIP(location
, ~0, 0);
1107 DenyIP(location
, ~0, 0);
1109 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1112 * Host or domain name...
1115 if (value
[0] == '*')
1118 if (strcasecmp(name
, "BrowseAllow") == 0)
1119 AllowHost(location
, value
);
1121 DenyHost(location
, value
);
1126 * One of many IP address forms...
1129 memset(ip
, 0, sizeof(ip
));
1130 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1131 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1133 if ((value
= strchr(value
, '/')) != NULL
)
1136 memset(mask
, 0, sizeof(mask
));
1137 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1138 mask
+ 2, mask
+ 3))
1141 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1144 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1145 mask
[2]) << 8) | mask
[3];
1148 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1150 netmask
= 0xffffffff;
1155 netmask
= netmasks
[ipcount
- 1];
1157 if ((address
& ~netmask
) != 0)
1159 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1160 name
, address
, netmask
);
1164 if (strcasecmp(name
, "BrowseAllow") == 0)
1165 AllowIP(location
, address
, netmask
);
1167 DenyIP(location
, address
, netmask
);
1171 else if (strcasecmp(name
, "BrowseRelay") == 0)
1174 * BrowseRelay [from] source [to] destination
1178 relay
= malloc(sizeof(dirsvc_relay_t
));
1180 relay
= realloc(Relays
, (NumRelays
+ 1) * sizeof(dirsvc_relay_t
));
1184 LogMessage(L_ERROR
, "Unable to allocate BrowseRelay at line %d - %s.",
1185 linenum
, strerror(errno
));
1192 memset(relay
, 0, sizeof(dirsvc_relay_t
));
1194 if (strncasecmp(value
, "from ", 5) == 0)
1197 * Strip leading "from"...
1202 while (isspace(*value
))
1207 * Figure out what form the from address takes:
1216 * nnn.nnn.nnn.nnn/mm
1217 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1220 if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0]))
1223 * Host or domain name...
1226 if (value
[0] == '*')
1229 strlcpy(name
, value
, sizeof(name
));
1230 if ((nameptr
= strchr(name
, ' ')) != NULL
)
1233 relay
->from
.type
= AUTH_NAME
;
1234 relay
->from
.mask
.name
.name
= strdup(name
);
1235 relay
->from
.mask
.name
.length
= strlen(name
);
1240 * One of many IP address forms...
1243 memset(ip
, 0, sizeof(ip
));
1244 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1245 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1247 for (; *value
; value
++)
1248 if (*value
== '/' || isspace(*value
))
1254 memset(mask
, 0, sizeof(mask
));
1255 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1256 mask
+ 2, mask
+ 3))
1259 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1262 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1263 mask
[2]) << 8) | mask
[3];
1266 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1268 netmask
= 0xffffffff;
1273 netmask
= netmasks
[ipcount
- 1];
1275 relay
->from
.type
= AUTH_IP
;
1276 relay
->from
.mask
.ip
.address
= address
;
1277 relay
->from
.mask
.ip
.netmask
= netmask
;
1281 * Skip value and trailing whitespace...
1284 for (; *value
; value
++)
1285 if (isspace(*value
))
1288 while (isspace(*value
))
1291 if (strncasecmp(value
, "to ", 3) == 0)
1294 * Strip leading "to"...
1299 while (isspace(*value
))
1304 * Get "to" address and port...
1307 if (get_address(value
, INADDR_BROADCAST
, BrowsePort
, &(relay
->to
)))
1309 if (relay
->from
.type
== AUTH_NAME
)
1310 LogMessage(L_INFO
, "Relaying from %s to %x:%d",
1311 relay
->from
.mask
.name
.name
,
1312 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1313 ntohs(relay
->to
.sin_port
));
1315 LogMessage(L_INFO
, "Relaying from %x/%x to %x:%d",
1316 relay
->from
.mask
.ip
.address
, relay
->from
.mask
.ip
.netmask
,
1317 (unsigned)ntohl(relay
->to
.sin_addr
.s_addr
),
1318 ntohs(relay
->to
.sin_port
));
1324 if (relay
->from
.type
== AUTH_NAME
)
1325 free(relay
->from
.mask
.name
.name
);
1327 LogMessage(L_ERROR
, "Bad relay address %s at line %d.", value
, linenum
);
1330 else if (strcasecmp(name
, "BrowsePoll") == 0)
1333 * BrowsePoll address[:port]
1337 poll
= malloc(sizeof(dirsvc_poll_t
));
1339 poll
= realloc(Polled
, (NumPolled
+ 1) * sizeof(dirsvc_poll_t
));
1343 LogMessage(L_ERROR
, "Unable to allocate BrowsePoll at line %d - %s.",
1344 linenum
, strerror(errno
));
1352 * Get poll address and port...
1355 if (get_address(value
, INADDR_NONE
, ippPort(), &polladdr
))
1357 LogMessage(L_INFO
, "Polling %x:%d",
1358 (unsigned)ntohl(polladdr
.sin_addr
.s_addr
),
1359 ntohs(polladdr
.sin_port
));
1362 memset(poll
, 0, sizeof(dirsvc_poll_t
));
1364 address
= ntohl(polladdr
.sin_addr
.s_addr
);
1366 sprintf(poll
->hostname
, "%d.%d.%d.%d", address
>> 24,
1367 (address
>> 16) & 255, (address
>> 8) & 255, address
& 255);
1368 poll
->port
= ntohs(polladdr
.sin_port
);
1371 LogMessage(L_ERROR
, "Bad poll address %s at line %d.", value
, linenum
);
1373 else if (strcasecmp(name
, "User") == 0)
1376 * User ID to run as...
1379 if (isdigit(value
[0]))
1383 struct passwd
*p
; /* Password information */
1386 p
= getpwnam(value
);
1391 LogMessage(L_WARN
, "Unknown username \"%s\"",
1395 else if (strcasecmp(name
, "Group") == 0)
1398 * Group ID to run as...
1401 if (isdigit(value
[0]))
1402 Group
= atoi(value
);
1405 struct group
*g
; /* Group information */
1408 g
= getgrnam(value
);
1413 LogMessage(L_WARN
, "Unknown groupname \"%s\"",
1417 else if (strcasecmp(name
, "SystemGroup") == 0)
1420 * System (admin) group(s)...
1423 char *valueptr
, /* Pointer into value */
1424 quote
; /* Quote character */
1427 for (i
= NumSystemGroups
; *value
&& i
< MAX_SYSTEM_GROUPS
; i
++)
1429 if (*value
== '\'' || *value
== '\"')
1432 * Scan quoted name...
1437 for (valueptr
= value
; *valueptr
; valueptr
++)
1438 if (*valueptr
== quote
)
1444 * Scan space or comma-delimited name...
1447 for (valueptr
= value
; *valueptr
; valueptr
++)
1448 if (isspace(*valueptr
) || *valueptr
== ',')
1455 SetString(SystemGroups
+ i
, value
);
1459 while (*value
== ',' || isspace(*value
))
1464 NumSystemGroups
= i
;
1466 else if (strcasecmp(name
, "HostNameLookups") == 0)
1469 * Do hostname lookups?
1472 if (strcasecmp(value
, "off") == 0)
1473 HostNameLookups
= 0;
1474 else if (strcasecmp(value
, "on") == 0)
1475 HostNameLookups
= 1;
1476 else if (strcasecmp(value
, "double") == 0)
1477 HostNameLookups
= 2;
1479 LogMessage(L_WARN
, "Unknown HostNameLookups %s on line %d.",
1482 else if (strcasecmp(name
, "LogLevel") == 0)
1485 * Amount of logging to do...
1488 if (strcasecmp(value
, "debug2") == 0)
1489 LogLevel
= L_DEBUG2
;
1490 else if (strcasecmp(value
, "debug") == 0)
1492 else if (strcasecmp(value
, "info") == 0)
1494 else if (strcasecmp(value
, "notice") == 0)
1495 LogLevel
= L_NOTICE
;
1496 else if (strcasecmp(value
, "warn") == 0)
1498 else if (strcasecmp(value
, "error") == 0)
1500 else if (strcasecmp(value
, "crit") == 0)
1502 else if (strcasecmp(value
, "alert") == 0)
1504 else if (strcasecmp(value
, "emerg") == 0)
1506 else if (strcasecmp(value
, "none") == 0)
1509 LogMessage(L_WARN
, "Unknown LogLevel %s on line %d.", value
, linenum
);
1511 else if (strcasecmp(name
, "PrintcapFormat") == 0)
1514 * Format of printcap file?
1517 if (strcasecmp(value
, "bsd") == 0)
1518 PrintcapFormat
= PRINTCAP_BSD
;
1519 else if (strcasecmp(value
, "solaris") == 0)
1520 PrintcapFormat
= PRINTCAP_SOLARIS
;
1522 LogMessage(L_WARN
, "Unknown PrintcapFormat %s on line %d.",
1525 else if (!strcasecmp(name
, "ServerTokens"))
1528 * Set the string used for the Server header...
1531 struct utsname plat
; /* Platform info */
1536 if (!strcasecmp(value
, "ProductOnly"))
1537 SetString(&ServerHeader
, "CUPS");
1538 else if (!strcasecmp(value
, "Major"))
1539 SetString(&ServerHeader
, "CUPS/1");
1540 else if (!strcasecmp(value
, "Minor"))
1541 SetString(&ServerHeader
, "CUPS/1.1");
1542 else if (!strcasecmp(value
, "Minimal"))
1543 SetString(&ServerHeader
, CUPS_MINIMAL
);
1544 else if (!strcasecmp(value
, "OS"))
1545 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s)", plat
.sysname
);
1546 else if (!strcasecmp(value
, "Full"))
1547 SetStringf(&ServerHeader
, CUPS_MINIMAL
" (%s) IPP/1.1", plat
.sysname
);
1548 else if (!strcasecmp(value
, "None"))
1549 ClearString(&ServerHeader
);
1551 LogMessage(L_WARN
, "Unknown ServerTokens %s on line %d.", value
, linenum
);
1556 * Find a simple variable in the list...
1559 for (i
= NUM_VARS
, var
= variables
; i
> 0; i
--, var
++)
1560 if (strcasecmp(name
, var
->name
) == 0)
1566 * Unknown directive! Output an error message and continue...
1569 LogMessage(L_ERROR
, "Unknown directive %s on line %d.", name
,
1579 char *units
; /* Units */
1582 n
= strtol(value
, &units
, 0);
1584 if (units
&& *units
)
1586 if (tolower(units
[0] & 255) == 'g')
1587 n
*= 1024 * 1024 * 1024;
1588 else if (tolower(units
[0] & 255) == 'm')
1590 else if (tolower(units
[0] & 255) == 'k')
1592 else if (tolower(units
[0] & 255) == 't')
1596 *((int *)var
->ptr
) = n
;
1601 if (strcasecmp(value
, "true") == 0 ||
1602 strcasecmp(value
, "on") == 0 ||
1603 strcasecmp(value
, "enabled") == 0 ||
1604 strcasecmp(value
, "yes") == 0 ||
1606 *((int *)var
->ptr
) = TRUE
;
1607 else if (strcasecmp(value
, "false") == 0 ||
1608 strcasecmp(value
, "off") == 0 ||
1609 strcasecmp(value
, "disabled") == 0 ||
1610 strcasecmp(value
, "no") == 0 ||
1611 strcasecmp(value
, "0") == 0)
1612 *((int *)var
->ptr
) = FALSE
;
1614 LogMessage(L_ERROR
, "Unknown boolean value %s on line %d.",
1619 SetString((char **)var
->ptr
, value
);
1630 * 'read_location()' - Read a <Location path> definition.
1633 static int /* O - New line number or 0 on error */
1634 read_location(cups_file_t
*fp
, /* I - Configuration file */
1635 char *location
, /* I - Location name/path */
1636 int linenum
) /* I - Current line number */
1638 int i
; /* Looping var */
1639 location_t
*loc
, /* New location */
1640 *parent
; /* Parent location */
1641 int len
; /* Length of line */
1642 char line
[HTTP_MAX_BUFFER
], /* Line buffer */
1643 name
[256], /* Configuration directive */
1644 *nameptr
, /* Pointer into name */
1645 *value
, /* Value for directive */
1646 *valptr
; /* Pointer into value */
1647 unsigned address
, /* Address value */
1648 netmask
; /* Netmask value */
1649 int ip
[4], /* IP address components */
1650 ipcount
, /* Number of components provided */
1651 mask
[4]; /* IP netmask components */
1652 static unsigned netmasks
[4] = /* Standard netmasks... */
1661 if ((parent
= AddLocation(location
)) == NULL
)
1664 parent
->limit
= AUTH_LIMIT_ALL
;
1667 while (cupsFileGets(fp
, line
, sizeof(line
)) != NULL
)
1672 * Skip comment lines...
1679 * Strip trailing whitespace, if any...
1684 while (len
> 0 && isspace(line
[len
- 1] & 255))
1691 * Extract the name from the beginning of the line...
1694 for (value
= line
; isspace(*value
& 255); value
++);
1696 for (nameptr
= name
; *value
!= '\0' && !isspace(*value
& 255) &&
1697 nameptr
< (name
+ sizeof(name
) - 1);)
1698 *nameptr
++ = *value
++;
1701 while (isspace(*value
& 255))
1704 if (name
[0] == '\0')
1708 * Decode the directive...
1711 if (strcasecmp(name
, "</Location>") == 0)
1713 else if (strcasecmp(name
, "<Limit") == 0 ||
1714 strcasecmp(name
, "<LimitExcept") == 0)
1716 if ((loc
= CopyLocation(&parent
)) == NULL
)
1722 for (valptr
= value
;
1723 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
1729 if (strcmp(value
, "ALL") == 0)
1730 loc
->limit
= AUTH_LIMIT_ALL
;
1731 else if (strcmp(value
, "GET") == 0)
1732 loc
->limit
|= AUTH_LIMIT_GET
;
1733 else if (strcmp(value
, "HEAD") == 0)
1734 loc
->limit
|= AUTH_LIMIT_HEAD
;
1735 else if (strcmp(value
, "OPTIONS") == 0)
1736 loc
->limit
|= AUTH_LIMIT_OPTIONS
;
1737 else if (strcmp(value
, "POST") == 0)
1738 loc
->limit
|= AUTH_LIMIT_POST
;
1739 else if (strcmp(value
, "PUT") == 0)
1740 loc
->limit
|= AUTH_LIMIT_PUT
;
1741 else if (strcmp(value
, "TRACE") == 0)
1742 loc
->limit
|= AUTH_LIMIT_TRACE
;
1744 LogMessage(L_WARN
, "Unknown request type %s on line %d!", value
,
1747 for (value
= valptr
; isspace(*value
& 255) || *value
== '>'; value
++);
1750 if (strcasecmp(name
, "<LimitExcept") == 0)
1751 loc
->limit
= AUTH_LIMIT_ALL
^ loc
->limit
;
1753 parent
->limit
&= ~loc
->limit
;
1755 else if (strcasecmp(name
, "</Limit>") == 0)
1757 else if (strcasecmp(name
, "Encryption") == 0)
1760 * "Encryption xxx" - set required encryption level...
1763 if (strcasecmp(value
, "never") == 0)
1764 loc
->encryption
= HTTP_ENCRYPT_NEVER
;
1765 else if (strcasecmp(value
, "always") == 0)
1767 LogMessage(L_ERROR
, "Encryption value \"%s\" on line %d is invalid in this context. "
1768 "Using \"required\" instead.", value
, linenum
);
1770 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1772 else if (strcasecmp(value
, "required") == 0)
1773 loc
->encryption
= HTTP_ENCRYPT_REQUIRED
;
1774 else if (strcasecmp(value
, "ifrequested") == 0)
1775 loc
->encryption
= HTTP_ENCRYPT_IF_REQUESTED
;
1777 LogMessage(L_ERROR
, "Unknown Encryption value %s on line %d.",
1780 else if (strcasecmp(name
, "Order") == 0)
1783 * "Order Deny,Allow" or "Order Allow,Deny"...
1786 if (strncasecmp(value
, "deny", 4) == 0)
1787 loc
->order_type
= AUTH_ALLOW
;
1788 else if (strncasecmp(value
, "allow", 5) == 0)
1789 loc
->order_type
= AUTH_DENY
;
1791 LogMessage(L_ERROR
, "Unknown Order value %s on line %d.",
1794 else if (strcasecmp(name
, "Allow") == 0 ||
1795 strcasecmp(name
, "Deny") == 0)
1798 * Allow [From] host/ip...
1799 * Deny [From] host/ip...
1802 if (strncasecmp(value
, "from", 4) == 0)
1805 * Strip leading "from"...
1810 while (isspace(*value
& 255))
1815 * Figure out what form the allow/deny address takes:
1826 * nnn.nnn.nnn.nnn/mm
1827 * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm
1830 if (strcasecmp(value
, "all") == 0)
1836 if (strcasecmp(name
, "Allow") == 0)
1841 else if (strcasecmp(value
, "none") == 0)
1847 if (strcasecmp(name
, "Allow") == 0)
1848 AllowIP(loc
, ~0, 0);
1852 else if (value
[0] == '*' || value
[0] == '.' || !isdigit(value
[0] & 255))
1855 * Host or domain name...
1858 if (value
[0] == '*')
1861 if (strcasecmp(name
, "Allow") == 0)
1862 AllowHost(loc
, value
);
1864 DenyHost(loc
, value
);
1869 * One of many IP address forms...
1872 memset(ip
, 0, sizeof(ip
));
1873 ipcount
= sscanf(value
, "%d.%d.%d.%d", ip
+ 0, ip
+ 1, ip
+ 2, ip
+ 3);
1874 address
= (((((ip
[0] << 8) | ip
[1]) << 8) | ip
[2]) << 8) | ip
[3];
1876 if ((value
= strchr(value
, '/')) != NULL
)
1879 memset(mask
, 0, sizeof(mask
));
1880 switch (sscanf(value
, "%d.%d.%d.%d", mask
+ 0, mask
+ 1,
1881 mask
+ 2, mask
+ 3))
1884 netmask
= (0xffffffff << (32 - mask
[0])) & 0xffffffff;
1887 netmask
= (((((mask
[0] << 8) | mask
[1]) << 8) |
1888 mask
[2]) << 8) | mask
[3];
1891 LogMessage(L_ERROR
, "Bad netmask value %s on line %d.",
1893 netmask
= 0xffffffff;
1898 netmask
= netmasks
[ipcount
- 1];
1900 if ((address
& ~netmask
) != 0)
1902 LogMessage(L_WARN
, "Discarding extra bits in %s address %08x for netmask %08x...",
1903 name
, address
, netmask
);
1907 if (strcasecmp(name
, "Allow") == 0)
1908 AllowIP(loc
, address
, netmask
);
1910 DenyIP(loc
, address
, netmask
);
1913 else if (strcasecmp(name
, "AuthType") == 0)
1916 * AuthType {none,basic,digest,basicdigest}
1919 if (strcasecmp(value
, "none") == 0)
1921 loc
->type
= AUTH_NONE
;
1922 loc
->level
= AUTH_ANON
;
1924 else if (strcasecmp(value
, "basic") == 0)
1926 loc
->type
= AUTH_BASIC
;
1928 if (loc
->level
== AUTH_ANON
)
1929 loc
->level
= AUTH_USER
;
1931 else if (strcasecmp(value
, "digest") == 0)
1933 loc
->type
= AUTH_DIGEST
;
1935 if (loc
->level
== AUTH_ANON
)
1936 loc
->level
= AUTH_USER
;
1938 else if (strcasecmp(value
, "basicdigest") == 0)
1940 loc
->type
= AUTH_BASICDIGEST
;
1942 if (loc
->level
== AUTH_ANON
)
1943 loc
->level
= AUTH_USER
;
1946 LogMessage(L_WARN
, "Unknown authorization type %s on line %d.",
1949 else if (strcasecmp(name
, "AuthClass") == 0)
1952 * AuthClass anonymous, user, system, group
1955 if (strcasecmp(value
, "anonymous") == 0)
1957 loc
->type
= AUTH_NONE
;
1958 loc
->level
= AUTH_ANON
;
1960 else if (strcasecmp(value
, "user") == 0)
1961 loc
->level
= AUTH_USER
;
1962 else if (strcasecmp(value
, "group") == 0)
1963 loc
->level
= AUTH_GROUP
;
1964 else if (strcasecmp(value
, "system") == 0)
1966 loc
->level
= AUTH_GROUP
;
1969 * Use the default system group if none is defined so far...
1972 if (NumSystemGroups
== 0)
1973 NumSystemGroups
= 1;
1975 for (i
= 0; i
< NumSystemGroups
; i
++)
1976 AddName(loc
, SystemGroups
[i
]);
1979 LogMessage(L_WARN
, "Unknown authorization class %s on line %d.",
1982 else if (strcasecmp(name
, "AuthGroupName") == 0)
1983 AddName(loc
, value
);
1984 else if (strcasecmp(name
, "Require") == 0)
1987 * Apache synonym for AuthClass and AuthGroupName...
1991 * Require valid-user
1992 * Require group names
1993 * Require user names
1996 for (valptr
= value
;
1997 !isspace(*valptr
& 255) && *valptr
!= '>' && *valptr
;
2003 if (strcasecmp(value
, "valid-user") == 0 ||
2004 strcasecmp(value
, "user") == 0)
2005 loc
->level
= AUTH_USER
;
2006 else if (strcasecmp(value
, "group") == 0)
2007 loc
->level
= AUTH_GROUP
;
2010 LogMessage(L_WARN
, "Unknown Require type %s on line %d.",
2016 * Get the list of names from the line...
2019 for (value
= valptr
; *value
;)
2021 for (valptr
= value
; !isspace(*valptr
& 255) && *valptr
; valptr
++);
2026 AddName(loc
, value
);
2028 for (value
= valptr
; isspace(*value
& 255); value
++);
2031 else if (strcasecmp(name
, "Satisfy") == 0)
2033 if (strcasecmp(value
, "all") == 0)
2034 loc
->satisfy
= AUTH_SATISFY_ALL
;
2035 else if (strcasecmp(value
, "any") == 0)
2036 loc
->satisfy
= AUTH_SATISFY_ANY
;
2038 LogMessage(L_WARN
, "Unknown Satisfy value %s on line %d.", value
,
2042 LogMessage(L_ERROR
, "Unknown Location directive %s on line %d.",
2051 * 'get_address()' - Get an address + port number from a line.
2054 static int /* O - 1 if address good, 0 if bad */
2055 get_address(char *value
, /* I - Value string */
2056 unsigned defaddress
, /* I - Default address */
2057 int defport
, /* I - Default port */
2058 struct sockaddr_in
*address
) /* O - Socket address */
2060 char hostname
[256], /* Hostname or IP */
2061 portname
[256]; /* Port number or name */
2062 struct hostent
*host
; /* Host address */
2063 struct servent
*port
; /* Port number */
2067 * Initialize the socket address to the defaults...
2070 memset(address
, 0, sizeof(struct sockaddr_in
));
2071 address
->sin_family
= AF_INET
;
2072 address
->sin_addr
.s_addr
= htonl(defaddress
);
2073 address
->sin_port
= htons(defport
);
2076 * Try to grab a hostname and port number...
2079 switch (sscanf(value
, "%255[^:]:%255s", hostname
, portname
))
2082 if (strchr(hostname
, '.') == NULL
&& defaddress
== INADDR_ANY
)
2085 * Hostname is a port number...
2088 strlcpy(portname
, hostname
, sizeof(portname
));
2097 LogMessage(L_ERROR
, "Unable to decode address \"%s\"!", value
);
2102 * Decode the hostname and port number as needed...
2105 if (hostname
[0] && strcmp(hostname
, "*"))
2107 if ((host
= httpGetHostByName(hostname
)) == NULL
)
2109 LogMessage(L_ERROR
, "httpGetHostByName(\"%s\") failed - %s!", hostname
,
2110 hstrerror(h_errno
));
2114 memcpy(&(address
->sin_addr
), host
->h_addr
, host
->h_length
);
2115 address
->sin_port
= htons(defport
);
2118 if (portname
[0] != '\0')
2120 if (isdigit(portname
[0] & 255))
2121 address
->sin_port
= htons(atoi(portname
));
2124 if ((port
= getservbyname(portname
, NULL
)) == NULL
)
2126 LogMessage(L_ERROR
, "getservbyname(\"%s\") failed - %s!", portname
,
2131 address
->sin_port
= htons(port
->s_port
);
2141 * 'CDSAGetServerCerts()' - Convert a keychain name into the CFArrayRef
2142 * required by SSLSetCertificate.
2144 * For now we assumes that there is exactly one SecIdentity in the
2145 * keychain - i.e. there is exactly one matching cert/private key pair.
2146 * In the future we will search a keychain for a SecIdentity matching a
2147 * specific criteria. We also skip the operation of adding additional
2148 * non-signing certs from the keychain to the CFArrayRef.
2150 * To create a self-signed certificate for testing use the certtool.
2151 * Executing the following as root will do it:
2153 * certtool c c v k=CUPS
2157 CDSAGetServerCerts(void)
2159 OSStatus err
; /* Error info */
2160 SecKeychainRef kcRef
; /* Keychain reference */
2161 SecIdentitySearchRef srchRef
; /* Search reference */
2162 SecIdentityRef identity
; /* Identity */
2163 CFArrayRef ca
; /* Certificate array */
2170 err
= SecKeychainOpen(ServerCertificate
, &kcRef
);
2173 LogMessage(L_ERROR
, "Cannot open keychain \"%s\", error %d.",
2174 ServerCertificate
, err
);
2178 * Search for "any" identity matching specified key use;
2179 * in this app, we expect there to be exactly one.
2182 err
= SecIdentitySearchCreate(kcRef
, CSSM_KEYUSE_SIGN
, &srchRef
);
2186 "Cannot find signing key in keychain \"%s\", error %d",
2187 ServerCertificate
, err
);
2190 err
= SecIdentitySearchCopyNext(srchRef
, &identity
);
2194 "Cannot find signing key in keychain \"%s\", error %d",
2195 ServerCertificate
, err
);
2198 if (CFGetTypeID(identity
) != SecIdentityGetTypeID())
2199 LogMessage(L_ERROR
, "SecIdentitySearchCopyNext CFTypeID failure!");
2203 * Found one. Place it in a CFArray.
2204 * TBD: snag other (non-identity) certs from keychain and add them
2208 ca
= CFArrayCreate(NULL
, (const void **)&identity
, 1, NULL
);
2211 LogMessage(L_ERROR
, "CFArrayCreate error");
2214 /*CFRelease(identity);*/
2217 /*CFRelease(srchRef);*/
2220 /*CFRelease(kcRef);*/
2225 #endif /* HAVE_CDSASSL */
2229 * End of "$Id: conf.c,v 1.149 2004/07/06 00:34:56 mike Exp $".