- /* Rewind file and send it down the original fd. */
- lseek(dk_fd, 0, SEEK_SET);
+ #ifdef EXPERIMENTAL_DOMAINKEYS
+ if ( (dk_private_key != NULL) && (dk_selector != NULL) ) {
+ /* Rewind file and feed it to the goats^W DK lib */
+ lseek(dkim_fd, 0, SEEK_SET);
+ dk_signature = dk_exim_sign(dkim_fd,
+ dk_private_key,
+ dk_domain,
+ dk_selector,
+ dk_canon);
+ if (dk_signature == NULL) {
+ if (dk_strict != NULL) {
+ uschar *dk_strict_result = expand_string(dk_strict);
+ if (dk_strict_result != NULL) {
+ if ( (strcmpic(dk_strict,US"1") == 0) ||
+ (strcmpic(dk_strict,US"true") == 0) ) {
+ save_errno = errno;
+ rc = FALSE;
+ goto CLEANUP;
+ }
+ }
+ }
+ }
+ else {
+ int siglen = Ustrlen(dk_signature);
+ while(siglen > 0) {
+ #ifdef SUPPORT_TLS
+ if (tls_active == fd) wwritten = tls_write(dk_signature, siglen); else
+ #endif
+ wwritten = write(fd,dk_signature,siglen);
+ if (wwritten == -1) {
+ /* error, bail out */
+ save_errno = errno;
+ rc = FALSE;
+ goto CLEANUP;
+ }
+ siglen -= wwritten;
+ dk_signature += wwritten;
+ }
+ }
+ }
+ #endif
+
+ /* Fetch file positition (the size) */
+ size = lseek(dkim_fd,0,SEEK_CUR);