static int imap_hibernate_client_parse_input(const char *const *args, pool_t pool, struct imap_client_state *state_r, const char **error_r) { const char *key, *value; unsigned int peer_dev_major = 0, peer_dev_minor = 0; memset(state_r, 0, sizeof(*state_r)); if (args[0] == NULL) { *error_r = "Missing username in input"; return -1; } state_r->username = args[0]; args++; if (args[0] == NULL) { *error_r = "Missing mail_log_prefix in input"; return -1; } state_r->mail_log_prefix = args[0]; args++; for (; *args != NULL; args++) { value = strchr(*args, '='); if (value != NULL) key = t_strdup_until(*args, value++); else { key = *args; value = ""; } if (strcmp(key, "lip") == 0) { if (net_addr2ip(value, &state_r->local_ip) < 0) { *error_r = t_strdup_printf( "Invalid lip value: %s", value); return -1; } } else if (strcmp(key, "rip") == 0) { if (net_addr2ip(value, &state_r->remote_ip) < 0) { *error_r = t_strdup_printf( "Invalid rip value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { if (str_to_uint(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { if (str_to_uint(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; } } else if (strcmp(key, "peer_ino") == 0) { if (str_to_ino(value, &state_r->peer_ino) < 0) { *error_r = t_strdup_printf( "Invalid peer_ino value: %s", value); return -1; } } else if (strcmp(key, "uid") == 0) { if (str_to_uid(value, &state_r->uid) < 0) { *error_r = t_strdup_printf( "Invalid uid value: %s", value); return -1; } } else if (strcmp(key, "gid") == 0) { if (str_to_gid(value, &state_r->gid) < 0) { *error_r = t_strdup_printf( "Invalid gid value: %s", value); return -1; } } else if (strcmp(key, "stats") == 0) { state_r->stats = value; } else if (strcmp(key, "idle-cmd") == 0) { state_r->idle_cmd = TRUE; } else if (strcmp(key, "session") == 0) { state_r->session_id = value; } else if (strcmp(key, "userdb_fields") == 0) { state_r->userdb_fields = value; } else if (strcmp(key, "notify_fd") == 0) { state_r->have_notify_fd = TRUE; } else if (strcmp(key, "idle_notify_interval") == 0) { if (str_to_uint(value, &state_r->imap_idle_notify_interval) < 0) { *error_r = t_strdup_printf( "Invalid idle_notify_interval value: %s", value); return -1; } } else if (strcmp(key, "state") == 0) { buffer_t *state_buf; state_buf = buffer_create_dynamic(pool, 1024); if (base64_decode(value, strlen(value), NULL, state_buf) < 0) { *error_r = t_strdup_printf( "Invalid state base64 value: %s", value); return -1; } state_r->state = state_buf->data; state_r->state_size = state_buf->used; } } if (peer_dev_major != 0 || peer_dev_minor != 0) state_r->peer_dev = makedev(peer_dev_major, peer_dev_minor); return 0; }
static int imap_master_client_parse_input(const char *const *args, pool_t pool, struct mail_storage_service_input *input_r, struct imap_master_input *master_input_r, const char **error_r) { const char *key, *value; unsigned int peer_dev_major = 0, peer_dev_minor = 0; i_zero(input_r); i_zero(master_input_r); master_input_r->client_input = buffer_create_dynamic(pool, 64); master_input_r->client_output = buffer_create_dynamic(pool, 16); master_input_r->state = buffer_create_dynamic(pool, 512); input_r->module = input_r->service = "imap"; /* we never want to do userdb lookup again when restoring the client. we have the userdb_fields cached already. */ input_r->flags_override_remove = MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP; if (args[0] == NULL) { *error_r = "Missing username in input"; return -1; } input_r->username = args[0]; for (args++; *args != NULL; args++) { value = strchr(*args, '='); if (value != NULL) key = t_strdup_until(*args, value++); else { key = *args; value = ""; } if (strcmp(key, "lip") == 0) { if (net_addr2ip(value, &input_r->local_ip) < 0) { *error_r = t_strdup_printf( "Invalid lip value: %s", value); return -1; } } else if (strcmp(key, "rip") == 0) { if (net_addr2ip(value, &input_r->remote_ip) < 0) { *error_r = t_strdup_printf( "Invalid rip value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_major") == 0) { if (str_to_uint(value, &peer_dev_major) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_major value: %s", value); return -1; } } else if (strcmp(key, "peer_dev_minor") == 0) { if (str_to_uint(value, &peer_dev_minor) < 0) { *error_r = t_strdup_printf( "Invalid peer_dev_minor value: %s", value); return -1; } } else if (strcmp(key, "peer_ino") == 0) { if (str_to_ino(value, &master_input_r->peer_ino) < 0) { *error_r = t_strdup_printf( "Invalid peer_ino value: %s", value); return -1; } } else if (strcmp(key, "session") == 0) { input_r->session_id = value; } else if (strcmp(key, "session_created") == 0) { if (str_to_time(value, &input_r->session_create_time) < 0) { *error_r = t_strdup_printf( "Invalid session_created value: %s", value); return -1; } } else if (strcmp(key, "userdb_fields") == 0) { input_r->userdb_fields = t_strsplit_tabescaped(value); } else if (strcmp(key, "client_input") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->client_input) < 0) { *error_r = t_strdup_printf( "Invalid client_input base64 value: %s", value); return -1; } } else if (strcmp(key, "client_output") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->client_output) < 0) { *error_r = t_strdup_printf( "Invalid client_output base64 value: %s", value); return -1; } } else if (strcmp(key, "state") == 0) { if (base64_decode(value, strlen(value), NULL, master_input_r->state) < 0) { *error_r = t_strdup_printf( "Invalid state base64 value: %s", value); return -1; } } else if (strcmp(key, "tag") == 0) { master_input_r->tag = t_strdup(value); } else if (strcmp(key, "bad-done") == 0) { master_input_r->state_import_bad_idle_done = TRUE; } else if (strcmp(key, "idle-continue") == 0) { master_input_r->state_import_idle_continue = TRUE; } } if (peer_dev_major != 0 || peer_dev_minor != 0) { master_input_r->peer_dev = makedev(peer_dev_major, peer_dev_minor); } return 0; }