static int expect(int master, char *issue, char *expected) { pstring buffer; int attempts, timeout, nread, len; BOOL match = False; for (attempts = 0; attempts < 2; attempts++) { if (!strequal(issue, ".")) { if (lp_passwd_chat_debug()) DEBUG(100, ("expect: sending [%s]\n", issue)); if ((len = write(master, issue, strlen(issue))) != strlen(issue)) { DEBUG(2,("expect: (short) write returned %d\n", len )); return False; } } if (strequal(expected, ".")) return True; /* Initial timeout. */ timeout = lp_passwd_chat_timeout() * 1000; nread = 0; buffer[nread] = 0; while ((len = read_socket_with_timeout(master, buffer + nread, 1, sizeof(buffer) - nread - 1, timeout)) > 0) { nread += len; buffer[nread] = 0; { /* Eat leading/trailing whitespace before match. */ pstring str; pstrcpy( str, buffer); trim_char( str, ' ', ' '); if ((match = (unix_wild_match(expected, str) == 0))) { /* Now data has started to return, lower timeout. */ timeout = lp_passwd_chat_timeout() * 100; } } } if (lp_passwd_chat_debug()) DEBUG(100, ("expect: expected [%s] received [%s] match %s\n", expected, buffer, match ? "yes" : "no" )); if (match) break; if (len < 0) { DEBUG(2, ("expect: %s\n", strerror(errno))); return False; } } DEBUG(10,("expect: returning %s\n", match ? "True" : "False" )); return match; }
/** * Check if needle is contained in haystack, * and ? patterns are resolved * @param haystack list of parameters separated by delimimiter character * @param needle string to be matched exectly to haystack including pattern matching * @return True if found **/ static bool matchparam(const char **haystack_list, const char *needle) { int i; if (haystack_list == NULL || haystack_list[0] == NULL || *haystack_list[0] == '\0' || needle == NULL || *needle == '\0') { return False; } for(i=0; haystack_list[i] ; i++) { if(unix_wild_match(haystack_list[i], needle)) { return True; } } return False; }
static bool matchdirparam(const char **dir_exclude_list, char *path) { char *startp = NULL, *endp = NULL; if (dir_exclude_list == NULL || dir_exclude_list[0] == NULL || *dir_exclude_list[0] == '\0' || path == NULL || *path == '\0') { return False; } /* * Walk the components of path, looking for matches with the * exclude list on each component. */ for (startp = path; startp; startp = endp) { int i; while (*startp == '/') { startp++; } endp = strchr(startp, '/'); if (endp) { *endp = '\0'; } for(i=0; dir_exclude_list[i] ; i++) { if(unix_wild_match(dir_exclude_list[i], startp)) { /* Repair path. */ if (endp) { *endp = '/'; } return True; } } /* Repair path. */ if (endp) { *endp = '/'; } } return False; }
/* string_match - match string s against token tok */ static bool string_match(const char *tok,const char *s) { size_t tok_len; size_t str_len; const char *cut; /* Return true if a token has the magic value "ALL". Return * true if the token is "FAIL". If the token starts with a "." * (domain name), return true if it matches the last fields of * the string. If the token has the magic value "LOCAL", * return true if the string does not contain a "." * character. If the token ends on a "." (network number), * return true if it matches the first fields of the * string. If the token begins with a "@" (netgroup name), * return true if the string is a (host) member of the * netgroup. Return true if the token fully matches the * string. If the token is a netnumber/netmask pair, return * true if the address is a member of the specified subnet. */ if (tok[0] == '.') { /* domain: match last fields */ if ((str_len = strlen(s)) > (tok_len = strlen(tok)) && strequal(tok, s + str_len - tok_len)) { return true; } } else if (tok[0] == '@') { /* netgroup: look it up */ #ifdef HAVE_NETGROUP DATA_BLOB tmp; char *mydomain = NULL; char *hostname = NULL; bool netgroup_ok = false; if (memcache_lookup( NULL, SINGLETON_CACHE, data_blob_string_const_null("yp_default_domain"), &tmp)) { SMB_ASSERT(tmp.length > 0); mydomain = (tmp.data[0] == '\0') ? NULL : (char *)tmp.data; } else { yp_get_default_domain(&mydomain); memcache_add( NULL, SINGLETON_CACHE, data_blob_string_const_null("yp_default_domain"), data_blob_string_const_null(mydomain?mydomain:"")); } if (!mydomain) { DEBUG(0,("Unable to get default yp domain. " "Try without it.\n")); } if (!(hostname = SMB_STRDUP(s))) { DEBUG(1,("out of memory for strdup!\n")); return false; } netgroup_ok = innetgr(tok + 1, hostname, (char *) 0, mydomain); DEBUG(5,("looking for %s of domain %s in netgroup %s gave %s\n", hostname, mydomain?mydomain:"(ANY)", tok+1, BOOLSTR(netgroup_ok))); SAFE_FREE(hostname); if (netgroup_ok) return true; #else DEBUG(0,("access: netgroup support is not configured\n")); return false; #endif } else if (strequal(tok, "ALL")) { /* all: match any */ return true; } else if (strequal(tok, "FAIL")) { /* fail: match any */ return true; } else if (strequal(tok, "LOCAL")) { /* local: no dots */ if (strchr_m(s, '.') == 0 && !strequal(s, "unknown")) { return true; } } else if (strequal(tok, s)) { /* match host name or address */ return true; } else if (tok[(tok_len = strlen(tok)) - 1] == '.') { /* network */ if (strncmp(tok, s, tok_len) == 0) { return true; } } else if ((cut = strchr_m(tok, '/')) != 0) { /* netnumber/netmask */ if ((isdigit(s[0]) && strchr_m(tok, '.') != NULL) || (tok[0] == '[' && cut > tok && cut[-1] == ']') || ((isxdigit(s[0]) || s[0] == ':') && strchr_m(tok, ':') != NULL)) { /* IPv4/netmask or * [IPv6:addr]/netmask or IPv6:addr/netmask */ return masked_match(tok, cut, s); } } else if (strchr_m(tok, '*') != 0 || strchr_m(tok, '?')) { return unix_wild_match(tok, s); } return false; }
static int expect(int master, char *issue, char *expected) { char buffer[1024]; int attempts, timeout, nread; size_t len; bool match = False; for (attempts = 0; attempts < 2; attempts++) { NTSTATUS status; if (!strequal(issue, ".")) { if (lp_passwd_chat_debug()) DEBUG(100, ("expect: sending [%s]\n", issue)); if ((len = sys_write(master, issue, strlen(issue))) != strlen(issue)) { DEBUG(2,("expect: (short) write returned %d\n", (int)len )); return False; } } if (strequal(expected, ".")) return True; /* Initial timeout. */ timeout = lp_passwd_chat_timeout() * 1000; nread = 0; buffer[nread] = 0; while (True) { status = read_fd_with_timeout( master, buffer + nread, 1, sizeof(buffer) - nread - 1, timeout, &len); if (!NT_STATUS_IS_OK(status)) { DEBUG(2, ("expect: read error %s\n", nt_errstr(status))); break; } nread += len; buffer[nread] = 0; { /* Eat leading/trailing whitespace before match. */ char *str = SMB_STRDUP(buffer); if (!str) { DEBUG(2,("expect: ENOMEM\n")); return False; } trim_char(str, ' ', ' '); if ((match = unix_wild_match(expected, str)) == True) { /* Now data has started to return, lower timeout. */ timeout = lp_passwd_chat_timeout() * 100; } SAFE_FREE(str); } } if (lp_passwd_chat_debug()) DEBUG(100, ("expect: expected [%s] received [%s] match %s\n", expected, buffer, match ? "yes" : "no" )); if (match) break; if (!NT_STATUS_IS_OK(status)) { DEBUG(2, ("expect: %s\n", nt_errstr(status))); return False; } } DEBUG(10,("expect: returning %s\n", match ? "True" : "False" )); return match; }