hostname = PORT_Strdup(hn); if ( hostname == NULL ) { return(SECFailure); } sec_lower_string(hostname);
CERT_VerifyCertName(CERTCertificate *cert, const char *hn){    char *    cn;    char *    domain;    char *    hndomain;    char *    hostname;    int       regvalid;    int       match;    SECStatus rv;    CERTOKDomainName *domainOK;    if (!hn || !strlen(hn)) {    	PORT_SetError(SEC_ERROR_INVALID_ARGS);	return SECFailure;    }    hostname = PORT_Strdup(hn);    if ( hostname == NULL ) {	return(SECFailure);    }    sec_lower_string(hostname);    /* if the name is one that the user has already approved, it's OK. */    for (domainOK = cert->domainOK; domainOK; domainOK = domainOK->next) {	if (0 == PORT_Strcmp(hostname, domainOK->name)) {	    PORT_Free(hostname);	    return SECSuccess;    	}    }    /* try the cert extension first, then the common name */    cn = CERT_FindNSStringExtension(cert, SEC_OID_NS_CERT_EXT_SSL_SERVER_NAME);    if ( cn == NULL ) {	cn = CERT_GetCommonName(&cert->subject);    }        sec_lower_string(cn);    if ( cn ) {	if ( ( hndomain = PORT_Strchr(hostname, '.') ) == NULL ) {	    /* No domain in server name */	    if ( ( domain = PORT_Strchr(cn, '.') ) != NULL ) {		/* there is a domain in the cn string, so chop it off */		*domain = '\0';	    }	}	regvalid = PORT_RegExpValid(cn);		if ( regvalid == NON_SXP ) {	    /* compare entire hostname with cert name */	    if ( PORT_Strcmp(hostname, cn) == 0 ) {		rv = SECSuccess;		goto done;	    }	    	    if ( hndomain ) {		/* compare just domain name with cert name */		if ( PORT_Strcmp(hndomain+1, cn) == 0 ) {		    rv = SECSuccess;		    goto done;		}	    }	    PORT_SetError(SSL_ERROR_BAD_CERT_DOMAIN);	    rv = SECFailure;	    goto done;	    	} else {	    /* try to match the shexp */	    match = PORT_RegExpCaseSearch(hostname, cn);	    if ( match == 0 ) {		rv = SECSuccess;	    } else {		PORT_SetError(SSL_ERROR_BAD_CERT_DOMAIN);		rv = SECFailure;	    }	    goto done;	}    }    PORT_SetError(SEC_ERROR_NO_MEMORY);    rv = SECFailure;done:    /* free the common name */    if ( cn ) {	PORT_Free(cn);    }        if ( hostname ) {	PORT_Free(hostname);    }        return(rv);}