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; }
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)); write(master, issue, strlen(issue)); } if (strequal(expected, ".")) return True; timeout = 2000; nread = 0; buffer[nread] = 0; while ((len = read_with_timeout(master, buffer + nread, 1, sizeof(buffer) - nread - 1, timeout)) > 0) { nread += len; buffer[nread] = 0; if ((match = unix_do_match(buffer, expected, False))) timeout = 200; } if (lp_passwd_chat_debug()) DEBUG(100, ("expect: expected [%s] received [%s]\n", expected, buffer)); if (match) break; if (len < 0) { DEBUG(2, ("expect: %s\n", strerror(errno))); return False; } } return match; }
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; }