BOOL sysv_cache_reload(void) { char **lines; int i; DEBUG(5, ("reloading sysv printcap cache\n")); if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL) return False; for (i = 0; lines[i]; i++) { char *name, *tmp; char *buf = lines[i]; /* eat "system/device for " */ if (((tmp = strchr_m(buf, ' ')) == NULL) || ((tmp = strchr_m(++tmp, ' ')) == NULL)) continue; /* * In case we're only at the "for ". */ if(!strncmp("for ", ++tmp, 4)) { tmp=strchr_m(tmp, ' '); tmp++; } /* Eat whitespace. */ while(*tmp == ' ') ++tmp; /* * On HPUX there is an extra line that can be ignored. * d.thibadeau 2001/08/09 */ if(!strncmp("remote to", tmp, 9)) continue; name = tmp; /* truncate the ": ..." */ if ((tmp = strchr_m(name, ':')) != NULL) *tmp = '\0'; /* add it to the cache */ if (!pcap_cache_add(name, NULL)) { file_lines_free(lines); return False; } } file_lines_free(lines); return True; }
static int iprint_cache_add_printer(http_t *http, int reqId, char* url) { ipp_t *request = NULL, /* IPP Request */ *response = NULL; /* IPP Response */ ipp_attribute_t *attr; /* Current attribute */ cups_lang_t *language = NULL; /* Default language */ char *name, /* printer-name attribute */ *info, /* printer-info attribute */ smb_enabled, /* smb-enabled attribute */ secure; /* security-enabled attrib. */ char *httpPath; /* path portion of the printer-uri */ static const char *pattrs[] = /* Requested printer attributes */ { "printer-name", "security-enabled", "printer-info", "smb-enabled" }; request = ippNew(); ippSetOperation(request, IPP_GET_PRINTER_ATTRIBUTES); ippSetRequestId(request, reqId); language = cupsLangDefault(); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, "utf-8"); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->language); ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, url); ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "requested-attributes", (sizeof(pattrs) / sizeof(pattrs[0])), NULL, pattrs); /* * Do the request and get back a response... */ if ((httpPath = strstr(url,"://")) == NULL || (httpPath = strchr(httpPath+3,'/')) == NULL) { ippDelete(request); request = NULL; goto out; } if ((response = cupsDoRequest(http, request, httpPath)) == NULL) { ipp_status_t lastErr = cupsLastError(); /* * Ignore printers that cannot be queried without credentials */ if (lastErr == IPP_FORBIDDEN || lastErr == IPP_NOT_AUTHENTICATED || lastErr == IPP_NOT_AUTHORIZED) goto out; DEBUG(0,("Unable to get printer list - %s\n", ippErrorString(lastErr))); goto out; } for (attr = ippFirstAttribute(response); attr != NULL;) { /* * Skip leading attributes until we hit a printer... */ while (attr != NULL && ippGetGroupTag(attr) != IPP_TAG_PRINTER) attr = ippNextAttribute(response); if (attr == NULL) break; /* * Pull the needed attributes from this printer... */ name = NULL; info = NULL; smb_enabled= 1; secure = 0; while (attr != NULL && ippGetGroupTag(attr) == IPP_TAG_PRINTER) { if (strcmp(ippGetName(attr), "printer-name") == 0 && ippGetValueTag(attr) == IPP_TAG_NAME) name = ippGetString(attr, 0, NULL); if (strcmp(ippGetName(attr), "printer-info") == 0 && (ippGetValueTag(attr) == IPP_TAG_TEXT || ippGetValueTag(attr) == IPP_TAG_TEXTLANG)) info = ippGetString(attr, 0, NULL); /* * If the smb-enabled attribute is present and the * value is set to 0, don't show the printer. * If the attribute is not present, assume that the * printer should show up */ if (!strcmp(ippGetName(attr), "smb-enabled") && ((ippGetValueTag(attr) == IPP_TAG_INTEGER && !ippGetInteger(attr, 0)) || (ippGetValueTag(attr) == IPP_TAG_BOOLEAN && !ippGetBoolean(attr, 0)))) smb_enabled = 0; /* * If the security-enabled attribute is present and the * value is set to 1, don't show the printer. * If the attribute is not present, assume that the * printer should show up */ if (!strcmp(ippGetName(attr), "security-enabled") && ((ippGetValueTag(attr) == IPP_TAG_INTEGER && ippGetInteger(attr, 0)) || (ippGetValueTag(attr) == IPP_TAG_BOOLEAN && ippGetBoolean(attr, 0)))) secure = 1; attr = ippNextAttribute(response); } /* * See if we have everything needed... * Make sure the printer is not a secure printer * and make sure smb printing hasn't been explicitly * disabled for the printer */ if (name != NULL && !secure && smb_enabled) pcap_cache_add(name, info, NULL); } out: if (response) ippDelete(response); return(0); }
bool aix_cache_reload(void) { int iEtat; XFILE *pfile; char *line = NULL, *p; char *name = NULL; TALLOC_CTX *ctx = talloc_init("aix_cache_reload"); if (!ctx) { return false; } DEBUG(5, ("reloading aix printcap cache\n")); if ((pfile = x_fopen(lp_printcapname(), O_RDONLY, 0)) == NULL) { DEBUG(0,( "Unable to open qconfig file %s for read!\n", lp_printcapname())); TALLOC_FREE(ctx); return false; } iEtat = 0; /* scan qconfig file for searching <printername>: */ for (;(line = fgets_slash(NULL, 1024, pfile)); free(line)) { if (*line == '*' || *line == 0) continue; switch (iEtat) { case 0: /* locate an entry */ if (*line == '\t' || *line == ' ') continue; if ((p = strchr_m(line, ':'))) { char *saveptr; *p = '\0'; p = strtok_r(line, ":", &saveptr); if (strcmp(p, "bsh") != 0) { name = talloc_strdup(ctx, p); if (!name) { SAFE_FREE(line); x_fclose(pfile); TALLOC_FREE(ctx); return false; } iEtat = 1; continue; } } break; case 1: /* scanning device stanza */ if (*line == '*' || *line == 0) continue; if (*line != '\t' && *line != ' ') { /* name is found without stanza device */ /* probably a good printer ??? */ iEtat = 0; if (!pcap_cache_add(name, NULL)) { SAFE_FREE(line); x_fclose(pfile); TALLOC_FREE(ctx); return false; } continue; } if (strstr_m(line, "backend")) { /* it's a device, not a virtual printer */ iEtat = 0; } else if (strstr_m(line, "device")) { /* it's a good virtual printer */ iEtat = 0; if (!pcap_cache_add(name, NULL)) { SAFE_FREE(line); x_fclose(pfile); TALLOC_FREE(ctx); return false; } continue; } break; } } x_fclose(pfile); TALLOC_FREE(ctx); return true; }
bool sysv_cache_reload(void) { char **lines; int i; #if defined(HPUX) DEBUG(5, ("reloading hpux printcap cache\n")); #else DEBUG(5, ("reloading sysv printcap cache\n")); #endif if ((lines = file_lines_pload("/usr/bin/lpstat -v", NULL)) == NULL) { #if defined(HPUX) /* * if "lpstat -v" is NULL then we check if schedular is running if it is * that means no printers are added on the HP-UX system, if schedular is not * running we display reload error. */ char **scheduler; scheduler = file_lines_pload("/usr/bin/lpstat -r", NULL); if(!strcmp(*scheduler,"scheduler is running")){ DEBUG(3,("No Printers found!!!\n")); TALLOC_FREE(scheduler); return True; } else{ DEBUG(3,("Scheduler is not running!!!\n")); TALLOC_FREE(scheduler); return False; } #else DEBUG(3,("No Printers found!!!\n")); return False; #endif } for (i = 0; lines[i]; i++) { char *name, *tmp; char *buf = lines[i]; /* eat "system/device for " */ if (((tmp = strchr_m(buf, ' ')) == NULL) || ((tmp = strchr_m(++tmp, ' ')) == NULL)) continue; /* * In case we're only at the "for ". */ if(!strncmp("for ", ++tmp, 4)) { tmp=strchr_m(tmp, ' '); tmp++; } /* Eat whitespace. */ while(*tmp == ' ') ++tmp; /* * On HPUX there is an extra line that can be ignored. * d.thibadeau 2001/08/09 */ if(!strncmp("remote to", tmp, 9)) continue; name = tmp; /* truncate the ": ..." */ if ((tmp = strchr_m(name, ':')) != NULL) *tmp = '\0'; /* add it to the cache */ if (!pcap_cache_add(name, NULL, NULL)) { TALLOC_FREE(lines); return False; } } TALLOC_FREE(lines); return True; }