static int conf_set_from_global(struct conf **globalc, struct conf **cc) { int i=0; for(i=0; i<OPT_MAX; i++) { if(!(cc[i]->flags & CONF_FLAG_CC_OVERRIDE)) continue; switch(cc[i]->conf_type) { case CT_STRING: set_string(cc[i], get_string(globalc[i])); break; case CT_UINT: set_int(cc[i], get_int(globalc[i])); break; case CT_FLOAT: set_float(cc[i], get_float(globalc[i])); break; case CT_MODE_T: set_mode_t(cc[i], get_mode_t(globalc[i])); break; case CT_SSIZE_T: set_uint64_t(cc[i], get_uint64_t(globalc[i])); break; case CT_E_BURP_MODE: set_e_burp_mode(cc[i], get_e_burp_mode(globalc[i])); break; case CT_E_PROTOCOL: set_e_protocol(cc[i], get_e_protocol(globalc[i])); break; case CT_E_RECOVERY_METHOD: set_e_recovery_method(cc[i], get_e_recovery_method(globalc[i])); break; case CT_E_RSHASH: set_e_rshash(cc[i], get_e_rshash(globalc[i])); break; case CT_STRLIST: // Done later. break; case CT_CNTR: break; // No default so that there are warnings if anything // was missed. } } // If ssl_peer_cn is not set, default it to the client name. if(!get_string(globalc[OPT_SSL_PEER_CN]) && set_string(cc[OPT_SSL_PEER_CN], get_string(cc[OPT_CNAME]))) return -1; return 0; }
rs_result rs_sig_gzfile(struct asfd *asfd, struct fzp *old_file, struct fzp *sig_file, size_t new_block_len, size_t strong_len, rs_stats_t *stats, struct conf **confs) { rs_job_t *job; rs_result r; job= rs_sig_begin(new_block_len, strong_len #ifndef RS_DEFAULT_STRONG_LEN , rshash_to_magic_number( get_e_rshash(confs[OPT_RSHASH])) #endif ); r=rs_whole_gzrun(asfd, job, old_file, sig_file, get_cntr(confs[OPT_CNTR])); rs_job_free(job); return r; }
static void check_default(struct conf **c, enum conf_opt o) { switch(o) { case OPT_BURP_MODE: fail_unless(get_e_burp_mode(c[o])==BURP_MODE_UNSET); break; case OPT_LOCKFILE: case OPT_PIDFILE: case OPT_ADDRESS: case OPT_PORT: case OPT_STATUS_ADDRESS: case OPT_STATUS_PORT: case OPT_SSL_CERT_CA: case OPT_SSL_CERT: case OPT_SSL_KEY: case OPT_SSL_KEY_PASSWORD: case OPT_SSL_PEER_CN: case OPT_SSL_CIPHERS: case OPT_SSL_DHFILE: case OPT_CA_CONF: case OPT_CA_NAME: case OPT_CA_SERVER_NAME: case OPT_CA_BURP_CA: case OPT_CA_CSR_DIR: case OPT_CA_CRL: case OPT_PEER_VERSION: case OPT_CLIENT_LOCKDIR: case OPT_MONITOR_LOGFILE: case OPT_CNAME: case OPT_PASSWORD: case OPT_PASSWD: case OPT_SERVER: case OPT_ENCRYPTION_PASSWORD: case OPT_AUTOUPGRADE_OS: case OPT_AUTOUPGRADE_DIR: case OPT_BACKUP: case OPT_BACKUP2: case OPT_RESTOREPREFIX: case OPT_RESTORE_SPOOL: case OPT_BROWSEFILE: case OPT_BROWSEDIR: case OPT_B_SCRIPT_PRE: case OPT_B_SCRIPT_POST: case OPT_R_SCRIPT_PRE: case OPT_R_SCRIPT_POST: case OPT_B_SCRIPT: case OPT_R_SCRIPT: case OPT_RESTORE_PATH: case OPT_ORIG_CLIENT: case OPT_CONFFILE: case OPT_USER: case OPT_GROUP: case OPT_DIRECTORY: case OPT_TIMESTAMP_FORMAT: case OPT_CLIENTCONFDIR: case OPT_S_SCRIPT_PRE: case OPT_S_SCRIPT_POST: case OPT_MANUAL_DELETE: case OPT_S_SCRIPT: case OPT_TIMER_SCRIPT: case OPT_N_SUCCESS_SCRIPT: case OPT_N_FAILURE_SCRIPT: case OPT_DEDUP_GROUP: case OPT_VSS_DRIVES: case OPT_REGEX: case OPT_RESTORE_CLIENT: fail_unless(get_string(c[o])==NULL); break; case OPT_RATELIMIT: fail_unless(get_float(c[o])==0); break; case OPT_CLIENT_IS_WINDOWS: case OPT_RANDOMISE: case OPT_B_SCRIPT_POST_RUN_ON_FAIL: case OPT_R_SCRIPT_POST_RUN_ON_FAIL: case OPT_SEND_CLIENT_CNTR: case OPT_BREAKPOINT: case OPT_SYSLOG: case OPT_PROGRESS_COUNTER: case OPT_MONITOR_BROWSE_CACHE: case OPT_S_SCRIPT_PRE_NOTIFY: case OPT_S_SCRIPT_POST_RUN_ON_FAIL: case OPT_S_SCRIPT_POST_NOTIFY: case OPT_S_SCRIPT_NOTIFY: case OPT_HARDLINKED_ARCHIVE: case OPT_N_SUCCESS_WARNINGS_ONLY: case OPT_N_SUCCESS_CHANGES_ONLY: case OPT_CROSS_ALL_FILESYSTEMS: case OPT_READ_ALL_FIFOS: case OPT_READ_ALL_BLOCKDEVS: case OPT_SPLIT_VSS: case OPT_STRIP_VSS: case OPT_ATIME: case OPT_SCAN_PROBLEM_RAISES_ERROR: case OPT_OVERWRITE: case OPT_STRIP: case OPT_MESSAGE: case OPT_CA_CRL_CHECK: fail_unless(get_int(c[o])==0); break; case OPT_DAEMON: case OPT_STDOUT: case OPT_FORK: case OPT_ENABLED: case OPT_DIRECTORY_TREE: case OPT_PASSWORD_CHECK: case OPT_LIBRSYNC: case OPT_VERSION_WARN: case OPT_PATH_LENGTH_WARN: case OPT_CLIENT_CAN_DELETE: case OPT_CLIENT_CAN_DIFF: case OPT_CLIENT_CAN_FORCE_BACKUP: case OPT_CLIENT_CAN_LIST: case OPT_CLIENT_CAN_RESTORE: case OPT_CLIENT_CAN_VERIFY: case OPT_SERVER_CAN_RESTORE: case OPT_SERVER_CAN_OVERRIDE_INCLUDES: case OPT_B_SCRIPT_RESERVED_ARGS: case OPT_R_SCRIPT_RESERVED_ARGS: case OPT_GLOB_AFTER_SCRIPT_PRE: case OPT_ACL: case OPT_XATTR: fail_unless(get_int(c[o])==1); break; case OPT_NETWORK_TIMEOUT: fail_unless(get_int(c[o])==60*60*2); break; case OPT_SSL_COMPRESSION: case OPT_MAX_CHILDREN: case OPT_MAX_STATUS_CHILDREN: fail_unless(get_int(c[o])==5); break; case OPT_COMPRESSION: fail_unless(get_int(c[o])==9); break; case OPT_MAX_STORAGE_SUBDIRS: fail_unless(get_int(c[o])==30000); break; case OPT_MAX_HARDLINKS: fail_unless(get_int(c[o])==10000); break; case OPT_UMASK: fail_unless(get_mode_t(c[o])==0022); break; case OPT_STARTDIR: case OPT_B_SCRIPT_PRE_ARG: case OPT_B_SCRIPT_POST_ARG: case OPT_R_SCRIPT_PRE_ARG: case OPT_R_SCRIPT_POST_ARG: case OPT_B_SCRIPT_ARG: case OPT_R_SCRIPT_ARG: case OPT_S_SCRIPT_PRE_ARG: case OPT_S_SCRIPT_POST_ARG: case OPT_S_SCRIPT_ARG: case OPT_TIMER_ARG: case OPT_N_SUCCESS_ARG: case OPT_N_FAILURE_ARG: case OPT_RESTORE_CLIENTS: case OPT_KEEP: case OPT_INCEXCDIR: case OPT_INCLUDE: case OPT_EXCLUDE: case OPT_FSCHGDIR: case OPT_NOBACKUP: case OPT_INCEXT: case OPT_EXCEXT: case OPT_INCREG: case OPT_EXCREG: case OPT_EXCFS: case OPT_EXCOM: case OPT_INCGLOB: case OPT_FIFOS: case OPT_BLOCKDEVS: case OPT_LABEL: fail_unless(get_strlist(c[o])==NULL); break; case OPT_PROTOCOL: fail_unless(get_e_protocol(c[o])==PROTO_AUTO); break; case OPT_HARD_QUOTA: case OPT_SOFT_QUOTA: case OPT_MIN_FILE_SIZE: case OPT_MAX_FILE_SIZE: fail_unless(get_uint64_t(c[o])==0); break; case OPT_WORKING_DIR_RECOVERY_METHOD: fail_unless(get_e_recovery_method(c[o])== RECOVERY_METHOD_DELETE); break; case OPT_RSHASH: fail_unless(get_e_rshash(c[o])==RSHASH_UNSET); break; case OPT_CNTR: fail_unless(get_cntr(c)==NULL); break; case OPT_MAX: break; // No default, so we get compiler warnings if something was // missed. } }
static void log_rshash(struct conf **confs) { if(get_protocol(confs)!=PROTO_1) return; logp("Using librsync hash %s\n", rshash_to_str(get_e_rshash(confs[OPT_RSHASH]))); }
int extra_comms(struct async *as, char **incexc, int *srestore, struct conf **confs, struct conf **cconfs) { struct vers vers; struct asfd *asfd; asfd=as->asfd; //char *restorepath=NULL; const char *peer_version=NULL; if(vers_init(&vers, cconfs)) goto error; if(vers.cli<vers.directory_tree) { set_int(confs[OPT_DIRECTORY_TREE], 0); set_int(cconfs[OPT_DIRECTORY_TREE], 0); } // Clients before 1.2.7 did not know how to do extra comms, so skip // this section for them. if(vers.cli<vers.min) return 0; if(asfd_read_expect(asfd, CMD_GEN, "extra_comms_begin")) { logp("problem reading in extra_comms\n"); goto error; } // Want to tell the clients the extra comms features that are // supported, so that new clients are more likely to work with old // servers. if(vers.cli==vers.feat_list) { // 1.3.0 did not support the feature list. if(asfd->write_str(asfd, CMD_GEN, "extra_comms_begin ok")) { logp("problem writing in extra_comms\n"); goto error; } } else { if(send_features(asfd, cconfs)) goto error; } if(extra_comms_read(as, &vers, srestore, incexc, confs, cconfs)) goto error; peer_version=get_string(cconfs[OPT_PEER_VERSION]); // This needs to come after extra_comms_read, as the client might // have set PROTO_1 or PROTO_2. switch(get_protocol(cconfs)) { case PROTO_AUTO: // The protocol has not been specified. Make a choice. if(vers.cli<vers.burp2) { // Client is burp-1.x.x, use protocol1. set_protocol(confs, PROTO_1); set_protocol(cconfs, PROTO_1); logp("Client is burp-%s - using protocol=%d\n", peer_version, PROTO_1); } else { // Client is burp-2.x.x, use protocol2. // This will probably never be reached because // the negotiation will take care of it. set_protocol(confs, PROTO_2); set_protocol(cconfs, PROTO_2); logp("Client is burp-%s - using protocol=%d\n", peer_version, PROTO_2); } break; case PROTO_1: // It is OK for the client to be burp1 and for the // server to be forced to protocol1. break; case PROTO_2: if(vers.cli>=vers.burp2) break; logp("protocol=%d is set server side, " "but client is burp version %s\n", peer_version); goto error; } if(get_protocol(cconfs)==PROTO_1) { if(get_e_rshash(cconfs[OPT_RSHASH])==RSHASH_UNSET) { set_e_rshash(confs[OPT_RSHASH], RSHASH_MD4); set_e_rshash(cconfs[OPT_RSHASH], RSHASH_MD4); } } return 0; error: return -1; }
// Return 0 for OK, -1 for error. int do_backup_client(struct asfd *asfd, struct conf **confs, enum action action, int resume) { int ret=-1; int breaking=get_int(confs[OPT_BREAKPOINT]); if(action==ACTION_ESTIMATE) logp("do estimate client\n"); else { logp("do backup client\n"); if(get_protocol(confs)==PROTO_1) logp("Using librsync hash %s\n", rshash_to_str(get_e_rshash(confs[OPT_RSHASH]))); } #ifdef HAVE_WIN32 win32_enable_backup_privileges(); #ifdef WIN32_VSS if(win32_start_vss(confs)) return ret; #endif if(action==ACTION_BACKUP_TIMED) set_low_priority(); #endif // Scan the file system and send the results to the server. // Skip phase1 if the server wanted to resume. if(!resume) { if(breaking==1) { breakpoint(breaking, __func__); goto end; } if(backup_phase1_client(asfd, confs, action==ACTION_ESTIMATE)) goto end; } switch(action) { case ACTION_DIFF: case ACTION_DIFF_LONG: ret=1; goto end; case ACTION_ESTIMATE: cntr_print(get_cntr(confs), ACTION_ESTIMATE); break; default: // Now, the server will be telling us what data we need // to send. if(breaking==2) { breakpoint(breaking, __func__); goto end; } if(get_protocol(confs)==PROTO_1) ret=backup_phase2_client_protocol1(asfd, confs, resume); else ret=backup_phase2_client_protocol2(asfd, confs, resume); if(ret) goto end; break; } ret=0; end: #if defined(HAVE_WIN32) if(action==ACTION_BACKUP_TIMED) unset_low_priority(); #if defined(WIN32_VSS) win32_stop_vss(); #endif #endif return ret; }
static int process_changed_file(struct asfd *asfd, struct sdirs *sdirs, struct conf **cconfs, struct sbuf *cb, struct sbuf *p1b, const char *adir) { size_t blocklen=0; char *curpath=NULL; //logp("need to process changed file: %s (%s)\n", // cb->path, cb->datapth); // Move datapth onto p1b. iobuf_move(&p1b->protocol1->datapth, &cb->protocol1->datapth); if(!(curpath=prepend_s(adir, p1b->protocol1->datapth.buf))) { log_out_of_memory(__func__); return -1; } if(dpth_protocol1_is_compressed(cb->compression, curpath)) p1b->protocol1->sigfzp=fzp_gzopen(curpath, "rb"); else p1b->protocol1->sigfzp=fzp_open(curpath, "rb"); if(!p1b->protocol1->sigfzp) { logp("could not open %s: %s\n", curpath, strerror(errno)); free(curpath); return -1; } free(curpath); blocklen=get_librsync_block_len(cb->protocol1->endfile.buf); if(!(p1b->protocol1->sigjob= #ifdef RS_DEFAULT_STRONG_LEN rs_sig_begin(blocklen, RS_DEFAULT_STRONG_LEN) #else // This is for librsync-1.0.0. RS_DEFAULT_STRONG_LEN was 8 in // librsync-0.9.7. rs_sig_begin(blocklen, 8, rshash_to_magic_number(get_e_rshash(cconfs[OPT_RSHASH]))) #endif )) { logp("could not start signature job.\n"); return -1; } //logp("sig begin: %s\n", p1b->protocol1->datapth.buf); if(!(p1b->protocol1->infb=rs_filebuf_new(asfd, NULL, p1b->protocol1->sigfzp, -1, blocklen, -1, get_cntr(cconfs[OPT_CNTR])))) { logp("could not rs_filebuf_new for infb.\n"); return -1; } if(!(p1b->protocol1->outfb=rs_filebuf_new(asfd, NULL, NULL, asfd->fd, ASYNC_BUF_LEN, -1, get_cntr(cconfs[OPT_CNTR])))) { logp("could not rs_filebuf_new for in_outfb.\n"); return -1; } // Flag the things that need to be sent (to the client) p1b->flags |= SBUFL_SEND_DATAPTH; p1b->flags |= SBUFL_SEND_STAT; p1b->flags |= SBUFL_SEND_PATH; //logp("sending sig for %s\n", p1b->path); //logp("(%s)\n", p1b->datapth); return 0; }