struct sieve_binary *sieve_open_script (struct sieve_script *script, struct sieve_error_handler *ehandler, enum sieve_compile_flags flags, enum sieve_error *error_r) { struct sieve_instance *svinst = sieve_script_svinst(script); struct sieve_binary *sbin; T_BEGIN { /* Then try to open the matching binary */ sbin = sieve_script_binary_load(script, error_r); if (sbin != NULL) { /* Ok, it exists; now let's see if it is up to date */ if ( !sieve_binary_up_to_date(sbin, flags) ) { /* Not up to date */ if ( svinst->debug ) { sieve_sys_debug(svinst, "Script binary %s is not up-to-date", sieve_binary_path(sbin)); } sieve_binary_unref(&sbin); sbin = NULL; } } /* If the binary does not exist or is not up-to-date, we need * to (re-)compile. */ if ( sbin != NULL ) { if ( svinst->debug ) { sieve_sys_debug(svinst, "Script binary %s successfully loaded", sieve_binary_path(sbin)); } } else { sbin = sieve_compile_script(script, ehandler, flags, error_r); if ( sbin != NULL ) { if ( svinst->debug ) { sieve_sys_debug(svinst, "Script `%s' from %s successfully compiled", sieve_script_name(script), sieve_script_location(script)); } } } } T_END; return sbin; }
static bool ext_ihave_binary_open (const struct sieve_extension *ext, struct sieve_binary *sbin, void *context) { struct sieve_instance *svinst = ext->svinst; struct ext_ihave_binary_context *binctx = (struct ext_ihave_binary_context *) context; struct sieve_binary_block *sblock; unsigned int i, count, block_id; sieve_size_t offset; sblock = sieve_binary_extension_get_block(sbin, ext); if ( sblock != NULL ) { binctx->block = sblock; block_id = sieve_binary_block_get_id(sblock); offset = 0; /* Read number of missing extensions to read subsequently */ if ( !sieve_binary_read_unsigned(sblock, &offset, &count) ) { sieve_sys_error(svinst, "ihave: failed to read missing extension count " "from block %d of binary %s", block_id, sieve_binary_path(sbin)); return FALSE; } /* Read dependencies */ for ( i = 0; i < count; i++ ) { string_t *ext_name; const char *name; if ( !sieve_binary_read_string(sblock, &offset, &ext_name) ) { /* Binary is corrupt, recompile */ sieve_sys_error(svinst, "ihave: failed to read missing extension name " "from block %d of binary %s", block_id, sieve_binary_path(sbin)); return FALSE; } name = str_c(ext_name); array_append(&binctx->missing_extensions, &name, 1); } } return TRUE; }
void _sieve_runtime_trace_end(const struct sieve_runtime_env *renv) { const char *script_name = ( renv->script != NULL ? sieve_script_name(renv->script) : sieve_binary_path(renv->sbin) ); _sieve_runtime_trace_printf(renv, renv->pc, 0, "## Finished executing script '%s'", script_name); _trace_line_print_empty(renv); }
static int sieve_ldap_script_binary_read_metadata (struct sieve_script *script, struct sieve_binary_block *sblock, sieve_size_t *offset) { struct sieve_ldap_script *lscript = (struct sieve_ldap_script *)script; struct sieve_instance *svinst = script->storage->svinst; struct sieve_ldap_storage *lstorage = (struct sieve_ldap_storage *)script->storage; struct sieve_binary *sbin = sieve_binary_block_get_binary(sblock); time_t bmtime = sieve_binary_mtime(sbin); string_t *dn, *modattr; /* config file changed? */ if ( bmtime <= lstorage->set_mtime ) { if ( svinst->debug ) { sieve_script_sys_debug(script, "Sieve binary `%s' is not newer " "than the LDAP configuration `%s' (%s <= %s)", sieve_binary_path(sbin), lstorage->config_file, t_strflocaltime("%Y-%m-%d %H:%M:%S", bmtime), t_strflocaltime("%Y-%m-%d %H:%M:%S", lstorage->set_mtime)); } return 0; } /* open script if not open already */ if ( lscript->dn == NULL && sieve_script_open(script, NULL) < 0 ) return 0; /* if modattr not found, recompile always */ if ( lscript->modattr == NULL || *lscript->modattr == '\0' ) { sieve_script_sys_error(script, "LDAP entry for script `%s' " "has no modified attribute `%s'", sieve_script_location(script), lstorage->set.sieve_ldap_mod_attr); return 0; } /* compare DN in binary and from search result */ if ( !sieve_binary_read_string(sblock, offset, &dn) ) { sieve_script_sys_error(script, "Binary `%s' has invalid metadata for script `%s': " "Invalid DN", sieve_binary_path(sbin), sieve_script_location(script)); return -1; } i_assert( lscript->dn != NULL ); if ( strcmp(str_c(dn), lscript->dn) != 0 ) { sieve_script_sys_debug(script, "Binary `%s' reports different LDAP DN for script `%s' " "(`%s' rather than `%s')", sieve_binary_path(sbin), sieve_script_location(script), str_c(dn), lscript->dn); return 0; } /* compare modattr in binary and from search result */ if ( !sieve_binary_read_string(sblock, offset, &modattr) ) { sieve_script_sys_error(script, "Binary `%s' has invalid metadata for script `%s': " "Invalid modified attribute", sieve_binary_path(sbin), sieve_script_location(script)); return -1; } if ( strcmp(str_c(modattr), lscript->modattr) != 0 ) { sieve_script_sys_debug(script, "Binary `%s' reports different modified attribute content " "for script `%s' (`%s' rather than `%s')", sieve_binary_path(sbin), sieve_script_location(script), str_c(modattr), lscript->modattr); return 0; } return 1; }