📄 conf.c
字号:
/* * Check the MaxClients setting, and then allocate memory for it... */ if (MaxClients > (MaxFDs / 3) || MaxClients <= 0) { if (MaxClients > 0) LogMessage(L_INFO, "MaxClients limited to 1/3 of the file descriptor limit (%d)...", MaxFDs); MaxClients = MaxFDs / 3; } if ((Clients = calloc(sizeof(client_t), MaxClients)) == NULL) { LogMessage(L_ERROR, "ReadConfiguration: Unable to allocate memory for %d clients: %s", MaxClients, strerror(errno)); exit(1); } else LogMessage(L_INFO, "Configured for up to %d clients.", MaxClients); if (Classification && strcasecmp(Classification, "none") == 0) ClearString(&Classification); if (Classification) LogMessage(L_INFO, "Security set to \"%s\"", Classification); /* * Update the MaxClientsPerHost value, as needed... */ if (MaxClientsPerHost <= 0) MaxClientsPerHost = MaxClients; if (MaxClientsPerHost > MaxClients) MaxClientsPerHost = MaxClients; LogMessage(L_INFO, "Allowing up to %d client connections per host.", MaxClientsPerHost); /* * If we are doing a full reload or the server root has changed, flush * the jobs, printers, etc. and start from scratch... */ DEBUG_printf(("test 05\n")); if (NeedReload == RELOAD_ALL || !old_serverroot || !ServerRoot || strcmp(old_serverroot, ServerRoot) || !old_requestroot || !RequestRoot || strcmp(old_requestroot, RequestRoot)) { LogMessage(L_INFO, "Full reload is required.");#if 0 /* * Free all memory... */ FreeAllJobs(); DeleteAllClasses(); DeleteAllPrinters(); DefaultPrinter = NULL; if (Devices) { ippDelete(Devices); Devices = NULL; } if (PPDs) { ippDelete(PPDs); PPDs = NULL; } if (MimeDatabase != NULL) mimeDelete(MimeDatabase); if (NumMimeTypes) { for (i = 0; i < NumMimeTypes; i ++) free((void *)MimeTypes[i]); free(MimeTypes); } /* * Read the MIME type and conversion database... */ snprintf(temp, sizeof(temp), "%s/filter", ServerBin); MimeDatabase = mimeNew(); mimeMerge(MimeDatabase, ServerRoot, temp); /* * Create a list of MIME types for the document-format-supported * attribute... */ NumMimeTypes = MimeDatabase->num_types; if (!mimeType(MimeDatabase, "application", "octet-stream")) NumMimeTypes ++; MimeTypes = calloc(NumMimeTypes, sizeof(const char *)); for (i = 0; i < MimeDatabase->num_types; i ++) { snprintf(type, sizeof(type), "%s/%s", MimeDatabase->types[i]->super, MimeDatabase->types[i]->type); MimeTypes[i] = strdup(type); } if (i < NumMimeTypes) MimeTypes[i] = strdup("application/octet-stream"); /* * Load banners... */ snprintf(temp, sizeof(temp), "%s/banners", DataDir); LoadBanners(temp);#endif /* * Load printers and classes... */ LoadAllPrinters();// LoadAllClasses(); CreateCommonData();#if 0 /* * Load devices and PPDs... */ snprintf(temp, sizeof(temp), "%s/backend", ServerBin); LoadDevices(temp); snprintf(temp, sizeof(temp), "%s/model", DataDir); LoadPPDs(temp); /* * Load queued jobs... */ LoadAllJobs(); LogMessage(L_INFO, "Full reload complete.");#endif } else { CreateCommonData(); LogMessage(L_INFO, "Partial reload complete."); }#if 0 /* * Reset the reload state... */ NeedReload = RELOAD_NONE; ClearString(&old_serverroot); ClearString(&old_requestroot);#endif /* * Startup the server and return... */ StartServer(); DEBUG_printf(("Function ReadConfiguration()\n\n")); return (1);}/* * 'read_configuration()' - Read a configuration file. */static int /* O - 1 on success, 0 on failure */read_configuration(cups_file_t *fp) /* I - File to read from */{ int i; /* Looping var */ int linenum; /* Current line number */ int len; /* Length of line */ char line[HTTP_MAX_BUFFER], /* Line from file */ name[256], /* Parameter name */ *nameptr, /* Pointer into name */ *value; /* Pointer to value */ var_t *var; /* Current variable */ cups_file_t *incfile; /* Include file */ char incname[1024]; /* Include filename */#if 0 int valuelen; /* Length of value */ unsigned address; /* Address value */ unsigned netmask; /* Netmask value */ int mask[4]; /* IP netmask components */ int ip[4], /* IP address components */ ipcount; /* Number of components provided */ dirsvc_relay_t *relay; /* Relay data */ dirsvc_poll_t *poll; /* Polling data */ struct sockaddr_in polladdr; /* Polling address */ location_t *location; /* Browse location */ static unsigned netmasks[4] = /* Standard netmasks... */ { 0xff000000, 0xffff0000, 0xffffff00, 0xffffffff };#endif DEBUG_printf(("Function read_configuration() start...\n")); /* * Loop through each line in the file... */ linenum = 0; while (cupsFileGets(fp, line, sizeof(line)) != NULL) { linenum ++; /* * Skip comment lines... */ if (line[0] == '#') continue; /* * Strip trailing whitespace, if any... */ len = strlen(line); while (len > 0 && isspace(line[len - 1])) { len --; line[len] = '\0'; } /* * Extract the name from the beginning of the line... */ for (value = line; isspace(*value); value ++); for (nameptr = name; *value != '\0' && !isspace(*value) && nameptr < (name + sizeof(name) - 1);) *nameptr++ = *value++; *nameptr = '\0'; while (isspace(*value)) value ++; if (name[0] == '\0') continue; /* * Decode the directive... */ if (strcasecmp(name, "Include") == 0) { /* * Include filename */ if (value[0] == '/') strlcpy(incname, value, sizeof(incname)); else snprintf(incname, sizeof(incname), "%s/%s", ServerRoot, value); if ((incfile = cupsFileOpen(incname, "rb")) == NULL) LogMessage(L_ERROR, "Unable to include config file \"%s\" - %s", incname, strerror(errno)); else { read_configuration(incfile); cupsFileClose(incfile); } }#if 0 else if (strcasecmp(name, "<Location") == 0) { /* * <Location path> */ if (line[len - 1] == '>') { line[len - 1] = '\0'; linenum = read_location(fp, value, linenum); if (linenum == 0) return (0); } else { LogMessage(L_ERROR, "Syntax error on line %d.", linenum); return (0); } }#endif else if (strcasecmp(name, "Port") == 0 || strcasecmp(name, "Listen") == 0) { /* * Add a listening address to the list... */ listener_t *temp; /* New listeners array */ if (NumListeners == 0) temp = malloc(sizeof(listener_t)); else temp = realloc(Listeners, (NumListeners + 1) * sizeof(listener_t)); if (!temp) { LogMessage(L_ERROR, "Unable to allocate %s at line %d - %s.", name, linenum, strerror(errno)); continue; } Listeners = temp; temp += NumListeners; memset(temp, 0, sizeof(listener_t)); if (get_address(value, INADDR_ANY, IPP_PORT, &(temp->address))) { LogMessage(L_INFO, "Listening to %x:%d", (unsigned)ntohl(temp->address.sin_addr.s_addr), ntohs(temp->address.sin_port)); NumListeners ++; } else LogMessage(L_ERROR, "Bad %s address %s at line %d.", name, value, linenum); }#if 0#ifdef HAVE_SSL else if (strcasecmp(name, "SSLPort") == 0 || strcasecmp(name, "SSLListen") == 0) { /* * Add a listening address to the list... */ listener_t *temp; /* New listeners array */ if (NumListeners == 0) temp = malloc(sizeof(listener_t)); else temp = realloc(Listeners, (NumListeners + 1) * sizeof(listener_t)); if (!temp) { LogMessage(L_ERROR, "Unable to allocate %s at line %d - %s.", name, linenum, strerror(errno)); continue; } Listeners = temp; temp += NumListeners; if (get_address(value, INADDR_ANY, IPP_PORT, &(temp->address))) { LogMessage(L_INFO, "Listening to %x:%d (SSL)", (unsigned)ntohl(temp->address.sin_addr.s_addr), ntohs(temp->address.sin_port)); temp->encryption = HTTP_ENCRYPT_ALWAYS; NumListeners ++; } else LogMessage(L_ERROR, "Bad %s address %s at line %d.", name, value, linenum); }#endif /* HAVE_SSL */ else if (strcasecmp(name, "BrowseAddress") == 0) { /* * Add a browse address to the list... */ dirsvc_addr_t *temp; /* New browse address array */ if (NumBrowsers == 0) temp = malloc(sizeof(dirsvc_addr_t)); else temp = realloc(Browsers, (NumBrowsers + 1) * sizeof(dirsvc_addr_t)); if (!temp) { LogMessage(L_ERROR, "Unable to allocate BrowseAddress at line %d - %s.", linenum, strerror(errno)); continue; } Browsers = temp; temp += NumBrowsers; memset(temp, 0, sizeof(dirsvc_addr_t)); if (strcasecmp(value, "@LOCAL") == 0) { /* * Send browse data to all local interfaces... */ strcpy(temp->iface, "*"); NumBrowsers ++; } else if (strncasecmp(value, "@IF(", 4) == 0) { /* * Send browse data to the named interface... */ strlcpy(temp->iface, value + 4, sizeof(Browsers[0].iface)); nameptr = temp->iface + strlen(temp->iface) - 1; if (*nameptr == ')') *nameptr = '\0'; NumBrowsers ++; } else if (get_address(value, INADDR_NONE, BrowsePort, &(temp->to))) { LogMessage(L_INFO, "Sending browsing info to %x:%d", (unsigned)ntohl(temp->to.sin_addr.s_addr), ntohs(temp->to.sin_port)); NumBrowsers ++; } else LogMessage(L_ERROR, "Bad BrowseAddress %s at line %d.", value, linenum); } else if (strcasecmp(name, "BrowseOrder") == 0) { /* * "BrowseOrder Deny,Allow" or "BrowseOrder Allow,Deny"... */ if ((location = FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL) location = AddLocation("CUPS_INTERNAL_BROWSE_ACL"); if (location == NULL) LogMessage(L_ERROR, "Unable to initialize browse access control list!"); else if (strncasecmp(value, "deny", 4) == 0) location->order_type = AUTH_ALLOW; else if (strncasecmp(value, "allow", 5) == 0) location->order_type = AUTH_DENY; else LogMessage(L_ERROR, "Unknown BrowseOrder value %s on line %d.", value, linenum); } else if (strcasecmp(name, "BrowseProtocols") == 0) { /* * "BrowseProtocol name [... name]" */ BrowseProtocols = 0; for (; *value;) { for (valuelen = 0; value[valuelen]; valuelen ++) if (isspace(value[valuelen]) || value[valuelen] == ',') break; if (value[valuelen]) { value[valuelen] = '\0'; valuelen ++; } if (strcasecmp(value, "cups") == 0) BrowseProtocols |= BROWSE_CUPS; else if (strcasecmp(value, "slp") == 0) BrowseProtocols |= BROWSE_SLP; else if (strcasecmp(value, "ldap") == 0) BrowseProtocols |= BROWSE_LDAP; else if (strcasecmp(value, "all") == 0) BrowseProtocols |= BROWSE_ALL; else { LogMessage(L_ERROR, "Unknown browse protocol \"%s\" on line %d.", value, linenum); break; } for (value += valuelen; *value; value ++) if (!isspace(*value) || *value != ',') break; } } else if (strcasecmp(name, "BrowseAllow") == 0 || strcasecmp(name, "BrowseDeny") == 0) { /* * BrowseAllow [From] host/ip... * BrowseDeny [From] host/ip... */ if ((location = FindLocation("CUPS_INTERNAL_BROWSE_ACL")) == NULL) location = AddLocation("CUPS_INTERNAL_BROWSE_ACL"); if (location == NULL) LogMessage(L_ERROR, "Unable to initialize browse access control list!"); else { if (strncasecmp(value, "from ", 5) == 0) { /* * Strip leading "from"... */ value += 5; while (isspace(*value)) value ++; } /* * Figure out what form the allow/deny address takes: * * All * None * *.domain.com * .domain.com * host.domain.com * nnn.* * nnn.nnn.* * nnn.nnn.nnn.* * nnn.nnn.nnn.nnn * nnn.nnn.nnn.nnn/mm * nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm */ if (strcasecmp(value, "all") == 0) { /* * All hosts... */ if (strcasecmp(name, "BrowseAllow") == 0) AllowIP(location, 0, 0); else DenyIP(location, 0, 0); } else if (strcasecmp(value, "none") == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -