svn commit: samba r21263 - in branches: SAMBA_3_0/source/lib SAMBA_3_0_25/source/lib

derrell at samba.org derrell at samba.org
Fri Feb 9 21:08:14 GMT 2007


vlendec at samba.org writes:

> Author: vlendec
> Date: 2007-02-09 20:58:17 +0000 (Fri, 09 Feb 2007)
> New Revision: 21263
>
> WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=21263
>
> Log:
> getpeername() returning -1 is not a reliable indication if a TCP connection is
> dead. Might be my code, this rings a very distant bell...
>
> Attempt to fix bug # 4372.
>
> Volker
>
> Modified:
>    branches/SAMBA_3_0/source/lib/smbldap.c
>    branches/SAMBA_3_0_25/source/lib/smbldap.c

Volker, I don't see anything in this changeset that references getpeername().
I actually just put a getpeername() call into libsmbclient (see bug 4309) to
detect loss of connection when we can't use SMBkeepalive packets because
netbios isn't in use.  Looking at the man page, it looks like a return of -1
isn't quite adequate.  We should also be checking for errno==ENOTCONN (which
I'm not currently doing in the recent libsmbclient changes).  Does that seem
to you like a reasonably reliable indication of a TCP connection being dead?

Derrell

>
>
> Changeset:
> Modified: branches/SAMBA_3_0/source/lib/smbldap.c
> ===================================================================
> --- branches/SAMBA_3_0/source/lib/smbldap.c	2007-02-09 19:41:09 UTC (rev 21262)
> +++ branches/SAMBA_3_0/source/lib/smbldap.c	2007-02-09 20:58:17 UTC (rev 21263)
> @@ -1232,12 +1232,23 @@
>  				       sizelimit, res);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed search for base: %s, error: %s "
> -				  "(%s)\n", base, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed search for base: %s, error: %d (%s) "
> +				   "(%s)\n", base, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  
> @@ -1372,12 +1383,23 @@
>  		rc = ldap_modify_s(ldap_state->ldap_struct, utf8_dn, attrs);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to modify dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to modify dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  		
> @@ -1404,12 +1426,23 @@
>  		rc = ldap_add_s(ldap_state->ldap_struct, utf8_dn, attrs);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to add dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to add dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  	
> @@ -1436,12 +1469,23 @@
>  		rc = ldap_delete_s(ldap_state->ldap_struct, utf8_dn);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to delete dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to delete dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  	
> @@ -1467,12 +1511,23 @@
>  					       clientctrls, retoidp, retdatap);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Extended operation failed with error: %s "
> -				  "(%s)\n", ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Extended operation failed with error: "
> +				   "%d (%s) (%s)\n", ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  		
>
> Modified: branches/SAMBA_3_0_25/source/lib/smbldap.c
> ===================================================================
> --- branches/SAMBA_3_0_25/source/lib/smbldap.c	2007-02-09 19:41:09 UTC (rev 21262)
> +++ branches/SAMBA_3_0_25/source/lib/smbldap.c	2007-02-09 20:58:17 UTC (rev 21263)
> @@ -1232,12 +1232,23 @@
>  				       sizelimit, res);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed search for base: %s, error: %s "
> -				  "(%s)\n", base, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed search for base: %s, error: %d (%s) "
> +				   "(%s)\n", base, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  
> @@ -1372,12 +1383,23 @@
>  		rc = ldap_modify_s(ldap_state->ldap_struct, utf8_dn, attrs);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to modify dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to modify dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  		
> @@ -1404,12 +1426,23 @@
>  		rc = ldap_add_s(ldap_state->ldap_struct, utf8_dn, attrs);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to add dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to add dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  	
> @@ -1436,12 +1469,23 @@
>  		rc = ldap_delete_s(ldap_state->ldap_struct, utf8_dn);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Failed to delete dn: %s, error: %s "
> -				  "(%s)\n", dn, ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Failed to delete dn: %s, error: %d (%s) "
> +				   "(%s)\n", dn, ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  	
> @@ -1467,12 +1511,23 @@
>  					       clientctrls, retoidp, retdatap);
>  		if (rc != LDAP_SUCCESS) {
>  			char *ld_error = NULL;
> +			int ld_errno;
> +
>  			ldap_get_option(ldap_state->ldap_struct,
> +					LDAP_OPT_RESULT_CODE, &ld_errno);
> +
> +			ldap_get_option(ldap_state->ldap_struct,
>  					LDAP_OPT_ERROR_STRING, &ld_error);
> -			DEBUG(10,("Extended operation failed with error: %s "
> -				  "(%s)\n", ldap_err2string(rc),
> -				  ld_error ? ld_error : "unknown"));
> +			DEBUG(10, ("Extended operation failed with error: "
> +				   "%d (%s) (%s)\n", ld_errno,
> +				   ldap_err2string(rc),
> +				   ld_error ? ld_error : "unknown"));
>  			SAFE_FREE(ld_error);
> +
> +			if (ld_errno == LDAP_SERVER_DOWN) {
> +				ldap_unbind(ldap_state->ldap_struct);
> +				ldap_state->ldap_struct = NULL;
> +			}
>  		}
>  	}
>  		
>

-- 


More information about the samba-technical mailing list