(krb5_change_password): make timeout 1 + 2^{0,1,...}. also keep track
if we got an old packet back and then just wait without sending a new packet git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@8757 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -263,6 +263,7 @@ krb5_change_password (krb5_context context,
|
|||||||
int sock;
|
int sock;
|
||||||
int i;
|
int i;
|
||||||
struct addrinfo *ai, *a;
|
struct addrinfo *ai, *a;
|
||||||
|
int done = 0;
|
||||||
|
|
||||||
ret = krb5_auth_con_init (context, &auth_context);
|
ret = krb5_auth_con_init (context, &auth_context);
|
||||||
if (ret)
|
if (ret)
|
||||||
@@ -272,59 +273,65 @@ krb5_change_password (krb5_context context,
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
for (a = ai; a != NULL; a = a->ai_next) {
|
for (a = ai; !done && a != NULL; a = a->ai_next) {
|
||||||
|
int replied = 0;
|
||||||
|
|
||||||
sock = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
sock = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||||
if (sock < 0)
|
if (sock < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (i = 0; i < 5; ++i) {
|
for (i = 0; !done && i < 5; ++i) {
|
||||||
fd_set fdset;
|
fd_set fdset;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
ret = send_request (context,
|
if (!replied) {
|
||||||
&auth_context,
|
replied = 0;
|
||||||
creds,
|
ret = send_request (context,
|
||||||
sock,
|
&auth_context,
|
||||||
a->ai_addr,
|
creds,
|
||||||
a->ai_addrlen,
|
sock,
|
||||||
newpw);
|
a->ai_addr,
|
||||||
if (ret) {
|
a->ai_addrlen,
|
||||||
close(sock);
|
newpw);
|
||||||
goto out;
|
if (ret) {
|
||||||
|
close(sock);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FD_ZERO(&fdset);
|
FD_ZERO(&fdset);
|
||||||
FD_SET(sock, &fdset);
|
FD_SET(sock, &fdset);
|
||||||
tv.tv_usec = 0;
|
tv.tv_usec = 0;
|
||||||
tv.tv_sec = 1 << i;
|
tv.tv_sec = 1 + 1 << i;
|
||||||
|
|
||||||
ret = select (sock + 1, &fdset, NULL, NULL, &tv);
|
ret = select (sock + 1, &fdset, NULL, NULL, &tv);
|
||||||
if (ret < 0 && errno != EINTR) {
|
if (ret < 0 && errno != EINTR) {
|
||||||
close(sock);
|
close(sock);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (ret == 1)
|
if (ret == 1) {
|
||||||
break;
|
replied = 1;
|
||||||
}
|
|
||||||
if (i == 5) {
|
|
||||||
ret = KRB5_KDC_UNREACH;
|
|
||||||
close (sock);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = process_reply (context,
|
ret = process_reply (context,
|
||||||
auth_context,
|
auth_context,
|
||||||
sock,
|
sock,
|
||||||
result_code,
|
result_code,
|
||||||
result_code_string,
|
result_code_string,
|
||||||
result_string);
|
result_string);
|
||||||
|
if (ret == 0)
|
||||||
|
done = 1;
|
||||||
|
} else {
|
||||||
|
ret = KRB5_KDC_UNREACH;
|
||||||
|
}
|
||||||
|
}
|
||||||
close (sock);
|
close (sock);
|
||||||
if (ret == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
freeaddrinfo (ai);
|
freeaddrinfo (ai);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
krb5_auth_con_free (context, auth_context);
|
krb5_auth_con_free (context, auth_context);
|
||||||
return ret;
|
if (done)
|
||||||
|
return 0;
|
||||||
|
else
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user