@@ -267,7 +267,7 @@ static int str_to_attachments(fr_mail_ctx_t *uctx, curl_mime *mime, char const *
267267 /* Check to see if the file attachment is valid, skip it if not */
268268 RDEBUG2 ("Trying to set attachment: %s" , str );
269269
270- if (strncmp ( str , "/" , 1 ) == 0 ) {
270+ if (* str == '/' ) {
271271 RDEBUG2 ("File attachments cannot be an absolute path" );
272272 return 0 ;
273273 }
@@ -514,7 +514,6 @@ static int body_init(fr_mail_ctx_t *uctx, curl_mime *mime)
514514 */
515515static int attachments_source (fr_mail_ctx_t * uctx , curl_mime * mime , rlm_smtp_t const * inst , rlm_smtp_env_t const * call_env )
516516{
517- request_t * request = uctx -> request ;
518517 int attachments_set = 0 ;
519518 fr_sbuff_uctx_talloc_t sbuff_ctx ;
520519 fr_sbuff_t path_buffer ;
@@ -534,8 +533,7 @@ static int attachments_source(fr_mail_ctx_t *uctx, curl_mime *mime, rlm_smtp_t c
534533 fr_sbuff_in_bstrcpy_buffer (& path_buffer , inst -> template_dir );
535534
536535 /* Make sure the template_directory path ends in a "/" */
537- if (inst -> template_dir [talloc_array_length (inst -> template_dir )- 2 ] != '/' ){
538- RDEBUG2 ("Adding / to end of template_dir" );
536+ if (inst -> template_dir [talloc_array_length (inst -> template_dir ) - 2 ] != '/' ){
539537 (void ) fr_sbuff_in_char (& path_buffer , '/' );
540538 }
541539
@@ -591,6 +589,7 @@ static unlang_action_t smtp_io_module_resume(rlm_rcode_t *p_result, module_ctx_t
591589 long curl_out_valid ;
592590
593591 curl_out_valid = curl_easy_getinfo (randle -> candle , CURLINFO_SSL_VERIFYRESULT , & curl_out );
592+
594593 if (curl_out_valid == CURLE_OK ){
595594 RDEBUG2 ("server certificate %s verified" , curl_out ? "was" : "not" );
596595 } else {
@@ -600,10 +599,12 @@ static unlang_action_t smtp_io_module_resume(rlm_rcode_t *p_result, module_ctx_t
600599 if (randle -> result != CURLE_OK ) {
601600 CURLcode result = randle -> result ;
602601 smtp_slab_release (randle );
602+
603603 switch (result ) {
604604 case CURLE_PEER_FAILED_VERIFICATION :
605605 case CURLE_LOGIN_DENIED :
606606 RETURN_MODULE_REJECT ;
607+
607608 default :
608609 RETURN_MODULE_FAIL ;
609610 }
@@ -751,25 +752,39 @@ static unlang_action_t CC_HINT(nonnull(1,2)) mod_authenticate(rlm_rcode_t *p_res
751752 rlm_smtp_auth_env_t * env_data = talloc_get_type_abort (mctx -> env_data , rlm_smtp_auth_env_t );
752753 fr_curl_io_request_t * randle ;
753754
754- randle = smtp_slab_reserve (t -> slab_onetime );
755- if (!randle ) RETURN_MODULE_FAIL ;
755+ if (!env_data -> username_tmpl ) {
756+ RDEBUG ("No 'username' was set for authentication - failing the request" );
757+ RETURN_MODULE_INVALID ;
758+ }
759+
760+ if (!env_data -> password_tmpl ) {
761+ RDEBUG ("No 'username' was set for authentication - failing the request" );
762+ RETURN_MODULE_INVALID ;
763+ }
756764
757765 if (env_data -> username .type != FR_TYPE_STRING || (env_data -> username .vb_length == 0 )) {
758766 RWARN ("\"%s\" is required for authentication" , env_data -> username_tmpl -> name );
759- error :
760- smtp_slab_release (randle );
761767 RETURN_MODULE_INVALID ;
762768 }
763769
764770 if (env_data -> password .type != FR_TYPE_STRING || (env_data -> password .vb_length == 0 )) {
765771 RWARN ("\"%s\" is required for authentication" , env_data -> password_tmpl -> name );
766- goto error ;
772+ RETURN_MODULE_INVALID ;
773+ }
774+
775+ randle = smtp_slab_reserve (t -> slab_onetime );
776+ if (!randle ) {
777+ RETURN_MODULE_FAIL ;
767778 }
768779
769780 FR_CURL_REQUEST_SET_OPTION (CURLOPT_USERNAME , env_data -> username .vb_strvalue );
770781 FR_CURL_REQUEST_SET_OPTION (CURLOPT_PASSWORD , env_data -> password .vb_strvalue );
771782
772- if (fr_curl_io_request_enqueue (t -> mhandle , request , randle )) RETURN_MODULE_INVALID ;
783+ if (fr_curl_io_request_enqueue (t -> mhandle , request , randle ) < 0 ) {
784+ error :
785+ smtp_slab_release (randle );
786+ RETURN_MODULE_FAIL ;
787+ }
773788
774789 return unlang_module_yield (request , smtp_io_module_resume , smtp_io_module_signal , ~FR_SIGNAL_CANCEL , randle );
775790}
0 commit comments