#include "cf.defs.h"#include "cf.extern.h"Go to the source code of this file.
Functions | |
| int | OpenServerConnection (struct Image *ip) |
| void | CloseServerConnection () |
| int | cf_rstat (char *file, struct stat *buf, struct Image *ip, char *stattype) |
| CFDIR * | cf_ropendir (char *dirname, struct Image *ip) |
| void | FlushClientCache (struct Image *ip) |
| int | CompareMD5Net (char *file1, char *file2, struct Image *ip) |
| int | CopyRegNet (char *source, char *new, struct Image *ip, off_t size) |
| int | GetCachedStatData (char *file, struct stat *statbuf, struct Image *ip, char *stattype) |
| void | CacheData (struct cfstat *data, struct Image *ip) |
| void | FlushToEnd (int sd, int toget) |
| cfagent_connection * | NewAgentConn () |
| void | DeleteAgentConn (struct cfagent_connection *ap) |
|
||||||||||||
|
Definition at line 820 of file client.c. References bcopy, Image::cache, cferror, CfLog(), malloc(), cfstat::next, NULL, and sp. Referenced by cf_rstat(). 00825 { struct cfstat *sp; 00826 00827 if ((sp = (struct cfstat *) malloc(sizeof(struct cfstat))) == NULL) 00828 { 00829 CfLog(cferror,"Memory allocation faliure in CacheData()\n",""); 00830 return; 00831 } 00832 00833 bcopy(data,sp,sizeof(struct cfstat)); 00834 00835 sp->next = ip->cache; 00836 ip->cache = sp; 00837 }
|
|
||||||||||||
|
Definition at line 328 of file client.c. References AppendItem(), BadProtoReply(), bufsize, cfdir::cf_dirh, CF_DONE, cfdir::cf_list, cfdir::cf_listpos, CFD_TERMINATOR, cferror, cfinform, CfLog(), CONN, Debug, errno, FailedProtoReply(), malloc(), NULL, OUTPUT, ReceiveTransaction(), cfagent_connection::sd, SendTransaction(), Image::server, snprintf(), and sp. Referenced by cfopendir(). 00333 { char sendbuffer[bufsize]; 00334 char recvbuffer[bufsize]; 00335 int n, done=false; 00336 CFDIR *cfdirh; 00337 char *sp; 00338 00339 Debug("CfOpenDir(%s:%s)\n",ip->server,dirname); 00340 00341 if (strlen(dirname) > bufsize - 20) 00342 { 00343 CfLog(cferror,"Directory name too long",""); 00344 return NULL; 00345 } 00346 00347 if ((cfdirh = (CFDIR *)malloc(sizeof(CFDIR))) == NULL) 00348 { 00349 CfLog(cferror,"Couldn't allocate memory in cf_ropendir\n",""); 00350 exit(1); 00351 } 00352 00353 cfdirh->cf_list = NULL; 00354 cfdirh->cf_listpos = NULL; 00355 cfdirh->cf_dirh = NULL; 00356 00357 snprintf(sendbuffer,bufsize,"OPENDIR %s",dirname); 00358 00359 if (SendTransaction(CONN->sd,sendbuffer,0,CF_DONE) == -1) 00360 { 00361 return NULL; 00362 } 00363 00364 while (!done) 00365 { 00366 if ((n = ReceiveTransaction(CONN->sd,recvbuffer,NULL)) == -1) 00367 { 00368 if (errno == EINTR) 00369 { 00370 continue; 00371 } 00372 return false; 00373 } 00374 00375 if (n == 0) 00376 { 00377 break; 00378 } 00379 00380 if (FailedProtoReply(recvbuffer)) 00381 { 00382 snprintf(OUTPUT,bufsize*2,"Network access to %s:%s denied\n",ip->server,dirname); 00383 CfLog(cfinform,OUTPUT,""); 00384 return false; 00385 } 00386 00387 if (BadProtoReply(recvbuffer)) 00388 { 00389 snprintf(OUTPUT,bufsize*2,"%s\n",recvbuffer+4); 00390 CfLog(cfinform,OUTPUT,""); 00391 return false; 00392 } 00393 00394 for (sp = recvbuffer; *sp != '\0'; sp++) 00395 { 00396 if (strncmp(sp,CFD_TERMINATOR,strlen(CFD_TERMINATOR)) == 0) /* End transmission */ 00397 { 00398 cfdirh->cf_listpos = cfdirh->cf_list; 00399 return cfdirh; 00400 } 00401 00402 AppendItem(&(cfdirh->cf_list),sp,NULL); 00403 00404 while(*sp != '\0') 00405 { 00406 sp++; 00407 } 00408 } 00409 } 00410 00411 cfdirh->cf_listpos = cfdirh->cf_list; 00412 return cfdirh; 00413 }
|
|
||||||||||||||||||||
|
Definition at line 127 of file client.c. References BadProtoReply(), bcopy, bufsize, bzero, CacheData(), cfstat::cf_atime, cf_block, cf_char, cfstat::cf_ctime, cf_dir, CF_DONE, cfstat::cf_failed, cf_fifo, cfstat::cf_filename, cfstat::cf_gid, cfstat::cf_ino, cf_link, cfstat::cf_lmode, cfstat::cf_makeholes, cfstat::cf_mode, cfstat::cf_mtime, cfstat::cf_nlink, CF_PROTO_OFFSET, cfstat::cf_readlink, cf_reg, cfstat::cf_server, cfstat::cf_size, cf_sock, cfstat::cf_type, cfstat::cf_uid, cferror, cfinform, CfLog(), cfverbose, CONN, Debug, Image::encrypt, EncryptString(), errno, FatalError(), GetCachedStatData(), Image::makeholes, NULL, OKProtoReply(), OUTPUT, ReceiveTransaction(), S_IFBLK, S_IFCHR, S_IFDIR, S_IFIFO, S_IFLNK, S_IFREG, S_IFSOCK, cfagent_connection::sd, SendTransaction(), Image::server, cfagent_connection::session_key, snprintf(), strdup(), and strstr(). Referenced by cflstat(), and cfstat(). 00137 { char sendbuffer[bufsize]; 00138 char recvbuffer[bufsize]; 00139 char in[bufsize],out[bufsize]; 00140 struct cfstat cfst; 00141 int ret,tosend,cipherlen; 00142 time_t tloc; 00143 00144 Debug("cf_rstat(%s)\n",file); 00145 bzero(recvbuffer,bufsize); 00146 00147 if (strlen(file) > bufsize-30) 00148 { 00149 CfLog(cferror,"Filename too long",""); 00150 return -1; 00151 } 00152 00153 ret = GetCachedStatData(file,buf,ip,stattype); 00154 00155 if (ret != 0) 00156 { 00157 return ret; 00158 } 00159 00160 if ((tloc = time((time_t *)NULL)) == -1) 00161 { 00162 CfLog(cferror,"Couldn't read system clock\n",""); 00163 } 00164 00165 sendbuffer[0] = '\0'; 00166 00167 if (ip->encrypt == 'y') 00168 { 00169 if (CONN->session_key == NULL) 00170 { 00171 CfLog(cferror,"Cannot do encrypted copy without keys (use cfkey)",""); 00172 return -1; 00173 } 00174 00175 snprintf(in,bufsize-1,"SYNCH %d STAT %s",tloc,file); 00176 cipherlen = EncryptString(in,out,CONN->session_key,strlen(in)+1); 00177 snprintf(sendbuffer,bufsize-1,"SSYNCH %d",cipherlen); 00178 bcopy(out,sendbuffer+CF_PROTO_OFFSET,cipherlen); 00179 tosend = cipherlen+CF_PROTO_OFFSET; 00180 } 00181 else 00182 { 00183 snprintf(sendbuffer,bufsize,"SYNCH %d STAT %s",tloc,file); 00184 tosend = strlen(sendbuffer); 00185 } 00186 00187 if (SendTransaction(CONN->sd,sendbuffer,tosend,CF_DONE) == -1) 00188 { 00189 snprintf(OUTPUT,bufsize*2,"Transmission failed/refused talking to %.255s:%.255s in stat",ip->server,file); 00190 CfLog(cfinform,OUTPUT,"send"); 00191 return -1; 00192 } 00193 00194 if (ReceiveTransaction(CONN->sd,recvbuffer,NULL) == -1) 00195 { 00196 return -1; 00197 } 00198 00199 if (strstr(recvbuffer,"unsynchronized")) 00200 { 00201 CfLog(cferror,"Clocks differ too much to do copy by date (security)",""); 00202 CfLog(cferror,recvbuffer+4,""); 00203 return -1; 00204 } 00205 00206 if (BadProtoReply(recvbuffer)) 00207 { 00208 snprintf(OUTPUT,bufsize*2,"Server returned error: %s\n",recvbuffer+4); 00209 CfLog(cfverbose,OUTPUT,""); 00210 errno = EPERM; 00211 return -1; 00212 } 00213 00214 if (OKProtoReply(recvbuffer)) 00215 { 00216 long d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12=0; 00217 00218 sscanf(recvbuffer,"OK: %1ld %5ld %14ld %14ld %14ld %14ld %14ld %14ld %14ld %14ld %14ld %14ld", 00219 &d1,&d2,&d3,&d4,&d5,&d6,&d7,&d8,&d9,&d10,&d11,&d12); 00220 00221 cfst.cf_type = (enum cf_filetype) d1; 00222 cfst.cf_mode = (mode_t) d2; 00223 cfst.cf_lmode = (mode_t) d3; 00224 cfst.cf_uid = (uid_t) d4; 00225 cfst.cf_gid = (gid_t) d5; 00226 cfst.cf_size = (off_t) d6; 00227 cfst.cf_atime = (time_t) d7; 00228 cfst.cf_mtime = (time_t) d8; 00229 cfst.cf_ctime = (time_t) d9; 00230 cfst.cf_makeholes = (char) d10; 00231 ip->makeholes = (char) d10; 00232 cfst.cf_ino = d11; 00233 cfst.cf_nlink = d12; 00234 00235 /* Use %?d here to avoid memory overflow attacks */ 00236 00237 Debug("Mode = %d,%d\n",d2,d3); 00238 00239 Debug("OK: type=%d\n mode=%o\n lmode=%o\n uid=%d\n gid=%d\n size=%ld\n atime=%d\n mtime=%d ino=%d nlnk=%d\n", 00240 cfst.cf_type,cfst.cf_mode,cfst.cf_lmode,cfst.cf_uid,cfst.cf_gid,(long)cfst.cf_size, 00241 cfst.cf_atime,cfst.cf_mtime,cfst.cf_ino,cfst.cf_nlink); 00242 00243 bzero(recvbuffer,bufsize); 00244 00245 if (ReceiveTransaction(CONN->sd,recvbuffer,NULL) == -1) 00246 { 00247 return -1; 00248 } 00249 00250 Debug("Linkbuffer: %s\n",recvbuffer); 00251 00252 if (strlen(recvbuffer) > 3) 00253 { 00254 cfst.cf_readlink = strdup(recvbuffer+3); 00255 } 00256 else 00257 { 00258 cfst.cf_readlink = NULL; 00259 } 00260 00261 switch (cfst.cf_type) 00262 { 00263 case cf_reg: cfst.cf_mode |= (mode_t) S_IFREG; 00264 break; 00265 case cf_dir: cfst.cf_mode |= (mode_t) S_IFDIR; 00266 break; 00267 case cf_char: cfst.cf_mode |= (mode_t) S_IFCHR; 00268 break; 00269 case cf_fifo: cfst.cf_mode |= (mode_t) S_IFIFO; 00270 break; 00271 case cf_sock: cfst.cf_mode |= (mode_t) S_IFSOCK; 00272 break; 00273 case cf_block: cfst.cf_mode |= (mode_t) S_IFBLK; 00274 break; 00275 case cf_link: cfst.cf_mode |= (mode_t) S_IFLNK; 00276 break; 00277 } 00278 00279 00280 cfst.cf_filename = strdup(file); 00281 cfst.cf_server = strdup(ip->server); 00282 00283 if ((cfst.cf_filename == NULL) ||(cfst.cf_server) == NULL) 00284 { 00285 FatalError("Memory allocation in cf_rstat"); 00286 } 00287 00288 cfst.cf_failed = false; 00289 00290 if (cfst.cf_lmode != 0) 00291 { 00292 cfst.cf_lmode |= (mode_t) S_IFLNK; 00293 } 00294 00295 CacheData(&cfst,ip); 00296 00297 if ((cfst.cf_lmode != 0) && (strcmp(stattype,"link") == 0)) 00298 { 00299 buf->st_mode = cfst.cf_lmode; 00300 } 00301 else 00302 { 00303 buf->st_mode = cfst.cf_mode; 00304 } 00305 00306 buf->st_uid = cfst.cf_uid; 00307 buf->st_gid = cfst.cf_gid; 00308 buf->st_size = cfst.cf_size; 00309 buf->st_mtime = cfst.cf_mtime; 00310 buf->st_ctime = cfst.cf_ctime; 00311 buf->st_atime = cfst.cf_atime; 00312 buf->st_ino = cfst.cf_ino; 00313 buf->st_nlink = cfst.cf_nlink; 00314 00315 return 0; 00316 } 00317 00318 00319 snprintf(OUTPUT,bufsize*2,"Transmission refused or failed statting %s\nGot: %s\n",file,recvbuffer); 00320 CfLog(cferror,OUTPUT,""); 00321 errno = EPERM; 00322 00323 return -1; 00324 }
|
|
|
Definition at line 109 of file client.c. References cf_not_connected, CONN, Debug, NULL, cfagent_connection::sd, and cfagent_connection::session_key. Referenced by MakeImages(), and OpenServerConnection(). 00111 { 00112 Debug("Closing current connection\n"); 00113 00114 close(CONN->sd); 00115 00116 CONN->sd = cf_not_connected; 00117 00118 if (CONN->session_key != NULL) 00119 { 00120 free(CONN->session_key); 00121 CONN->session_key = NULL; 00122 } 00123 }
|
|
||||||||||||||||
|
Definition at line 431 of file client.c. References bcopy, bufsize, bzero, CF_DONE, CF_MD5_LEN, CF_PROTO_OFFSET, CF_SMALL_OFFSET, CFD_TRUE, cferror, CfLog(), ChecksumFile(), ChecksumPrint(), CONN, Debug, Image::encrypt, EncryptString(), i, NULL, ReceiveTransaction(), cfagent_connection::sd, SendTransaction(), cfagent_connection::session_key, snprintf(), sp, and Verbose. 00436 { static unsigned char d[CF_MD5_LEN]; 00437 char *sp,sendbuffer[bufsize],recvbuffer[bufsize],in[bufsize],out[bufsize]; 00438 int i,tosend,cipherlen; 00439 00440 00441 ChecksumFile(file2,d,'m'); /* send md5 to the server for comparison */ 00442 Debug("Send digest of %s to server, %s\n",file2,ChecksumPrint('m',d)); 00443 00444 bzero(recvbuffer,bufsize); 00445 00446 if (ip->encrypt == 'y') 00447 { 00448 snprintf(in,bufsize,"MD5 %s",file1); 00449 00450 sp = in + strlen(in) + CF_SMALL_OFFSET; 00451 00452 for (i = 0; i < CF_MD5_LEN; i++) 00453 { 00454 *sp++ = d[i]; 00455 } 00456 00457 cipherlen = EncryptString(in,out,CONN->session_key,strlen(in)+CF_SMALL_OFFSET+CF_MD5_LEN); 00458 snprintf(sendbuffer,bufsize,"SMD5 %d",cipherlen); 00459 bcopy(out,sendbuffer+CF_PROTO_OFFSET,cipherlen); 00460 tosend = cipherlen + CF_PROTO_OFFSET; 00461 } 00462 else 00463 { 00464 snprintf(sendbuffer,bufsize,"MD5 %s",file1); 00465 sp = sendbuffer + strlen(sendbuffer) + CF_SMALL_OFFSET; 00466 00467 for (i = 0; i < CF_MD5_LEN; i++) 00468 { 00469 *sp++ = d[i]; 00470 } 00471 00472 tosend = strlen(sendbuffer)+CF_SMALL_OFFSET+CF_MD5_LEN; 00473 } 00474 00475 if (SendTransaction(CONN->sd,sendbuffer,tosend,CF_DONE) == -1) 00476 { 00477 CfLog(cferror,"","send"); 00478 return false; 00479 } 00480 00481 if (ReceiveTransaction(CONN->sd,recvbuffer,NULL) == -1) 00482 { 00483 Verbose("No answer from host, assuming checksum ok to avoid remote copy for now...\n"); 00484 return false; 00485 } 00486 00487 if (strcmp(CFD_TRUE,recvbuffer) == 0) 00488 { 00489 Debug("MD5 mismatch: (reply - %s)\n",recvbuffer); 00490 return true; /* mismatch */ 00491 } 00492 else 00493 { 00494 Debug("MD5 matched ok: (reply - %s)\n",recvbuffer); 00495 return false; 00496 } 00497 00498 /* Not reached */ 00499 }
|
|
||||||||||||||||||||
|
Definition at line 503 of file client.c. References bcopy, bufsize, CF_DONE, cf_full_write(), CF_PROTO_OFFSET, CFCHANGEDSTR1, CFCHANGEDSTR2, cferror, CFFAILEDSTR, cfinform, CfLog(), Image::compat, CONN, Debug, EmbeddedWrite(), Image::encrypt, EncryptString(), errno, FlushToEnd(), malloc(), O_BINARY, OUTPUT, ReceiveTransaction(), RecvSocketStream(), cfagent_connection::sd, SendTransaction(), Image::server, cfagent_connection::session_key, snprintf(), and ST_BLKSIZE. Referenced by CopyReg(). 00509 { int dd, buf_size,n_read = 0,toget,towrite,plainlen,more = true; 00510 int last_write_made_hole = 0, done = false,tosend,cipherlen=0; 00511 char *buf,in[bufsize],out[bufsize],sendbuffer[bufsize],cfchangedstr[265]; 00512 unsigned char iv[] = {1,2,3,4,5,6,7,8}; 00513 long n_read_total = 0; 00514 EVP_CIPHER_CTX ctx; 00515 00516 snprintf(cfchangedstr,255,"%s%s",CFCHANGEDSTR1,CFCHANGEDSTR2); 00517 00518 EVP_CIPHER_CTX_init(&ctx); 00519 00520 if ((strlen(new) > bufsize-20)) 00521 { 00522 CfLog(cferror,"Filename too long",""); 00523 return false; 00524 } 00525 00526 unlink(new); /* To avoid link attacks */ 00527 00528 if ((dd = open(new,O_WRONLY|O_CREAT|O_TRUNC|O_EXCL|O_BINARY, 0600)) == -1) 00529 { 00530 snprintf(OUTPUT,bufsize*2,"Copy %s:%s security - failed attempt to exploit a race? (Not copied)\n",ip->server,new); 00531 CfLog(cferror,OUTPUT,"open"); 00532 unlink(new); 00533 return false; 00534 } 00535 00536 sendbuffer[0] = '\0'; 00537 00538 buf_size = ST_BLKSIZE(dstat); 00539 00540 if (buf_size < 2048) 00541 { 00542 buf_size = 2048; 00543 } 00544 00545 if (ip->encrypt == 'y') 00546 { 00547 if (size < 17) 00548 { 00549 snprintf(OUTPUT,bufsize,"Cannot encrypt files smaller than 17 bytes with OpenSSL/Blowfish (%s)",source); 00550 CfLog(cferror,OUTPUT,""); 00551 return false; 00552 } 00553 00554 snprintf(in,bufsize-CF_PROTO_OFFSET,"GET dummykey %s",source); 00555 cipherlen = EncryptString(in,out,CONN->session_key,strlen(in)+1); 00556 snprintf(sendbuffer,bufsize,"SGET %4d %4d",cipherlen,buf_size); 00557 bcopy(out,sendbuffer+CF_PROTO_OFFSET,cipherlen); 00558 tosend=cipherlen+CF_PROTO_OFFSET; 00559 EVP_DecryptInit(&ctx,EVP_bf_cbc(),CONN->session_key,iv); 00560 } 00561 else 00562 { 00563 snprintf(sendbuffer,bufsize,"GET %d %s",buf_size,source); 00564 tosend=strlen(sendbuffer); 00565 } 00566 00567 if (SendTransaction(CONN->sd,sendbuffer,tosend,CF_DONE) == -1) 00568 { 00569 CfLog(cferror,"Couldn't send","send"); 00570 close(dd); 00571 return false; 00572 } 00573 00574 buf = (char *) malloc(bufsize + sizeof(int)); /* Note bufsize not buf_size !! */ 00575 n_read_total = 0; 00576 00577 while (!done) 00578 { 00579 cipherlen = 0; 00580 00581 if ((size - n_read_total)/buf_size > 0) 00582 { 00583 toget = towrite = buf_size; 00584 } 00585 else if (size != 0) 00586 { 00587 towrite = (size - n_read_total); 00588 00589 if (ip->compat == 'y') 00590 { 00591 toget = buf_size; 00592 } 00593 else 00594 { 00595 toget = towrite; 00596 } 00597 } 00598 else 00599 { 00600 toget = towrite = 0; 00601 } 00602 00603 if (ip->encrypt == 'y') 00604 { 00605 if (more) 00606 { 00607 cipherlen = ReceiveTransaction(CONN->sd,buf,&more); 00608 } 00609 else 00610 { 00611 break; /* Already written last encrypted buffer */ 00612 } 00613 } 00614 else 00615 { 00616 if ((n_read = RecvSocketStream(CONN->sd,buf,toget,0)) == -1) 00617 { 00618 if (errno == EINTR) 00619 { 00620 continue; 00621 } 00622 00623 CfLog(cferror,"Error in socket stream","recv"); 00624 close(dd); 00625 free(buf); 00626 return false; 00627 } 00628 } 00629 00630 00631 /* If the first thing we get is an error message, break. */ 00632 00633 if (n_read_total == 0 && strncmp(buf,CFFAILEDSTR,strlen(CFFAILEDSTR)) == 0) 00634 { 00635 snprintf(OUTPUT,bufsize*2,"Network access to %s:%s denied\n",ip->server,source); 00636 if (ip->encrypt != 'y') 00637 { 00638 RecvSocketStream(CONN->sd,buf,buf_size-n_read,0); /* flush rest of transaction */ 00639 } 00640 00641 CfLog(cfinform,OUTPUT,""); 00642 close(dd); 00643 free(buf); 00644 return false; 00645 } 00646 00647 if (strncmp(buf,cfchangedstr,strlen(cfchangedstr)) == 0) 00648 { 00649 snprintf(OUTPUT,bufsize*2,"File %s:%s changed while copying\n",ip->server,source); 00650 RecvSocketStream(CONN->sd,buf,buf_size-n_read,0); /* flush rest of transaction */ 00651 CfLog(cfinform,OUTPUT,""); 00652 close(dd); 00653 free(buf); 00654 return false; 00655 } 00656 00657 if (ip->encrypt == 'y') 00658 { 00659 if (!EVP_DecryptUpdate(&ctx,sendbuffer,&plainlen,buf,cipherlen)) 00660 { 00661 Debug("Decryption failed\n"); 00662 return false; 00663 } 00664 00665 bcopy(sendbuffer,buf,plainlen); 00666 n_read = towrite = plainlen; 00667 } 00668 00669 if (n_read == 0) 00670 { 00671 break; 00672 } 00673 00674 if (n_read == size) 00675 { 00676 if (n_read_total == 0 && strncmp(buf,CFFAILEDSTR,size) == 0) 00677 { 00678 snprintf(OUTPUT,bufsize*2,"Network access to %s:%s denied\n",ip->server,source); 00679 CfLog(cfinform,OUTPUT,""); 00680 close(dd); 00681 free(buf); 00682 return false; 00683 } 00684 } 00685 00686 /* if (n_read < toget) 00687 { 00688 snprintf(OUTPUT,bufsize*2,"Network error getting %s:%s\n",ip->server,source); 00689 CfLog(cfinform,OUTPUT,""); 00690 close(dd); 00691 free(buf); 00692 return false; 00693 } 00694 */ 00695 n_read_total += towrite; /* n_read; */ 00696 00697 if (ip->encrypt == 'n') 00698 { 00699 if (n_read_total >= (long)size) /* Handle EOF without closing socket */ 00700 { 00701 done = true; 00702 } 00703 } 00704 00705 if (!EmbeddedWrite(new,dd,buf,ip,towrite,&last_write_made_hole,n_read)) 00706 { 00707 snprintf(OUTPUT,bufsize,"Local disk write failed copying %s:%s to %s\n",ip->server,source,new); 00708 CfLog(cferror,OUTPUT,""); 00709 free(buf); 00710 unlink(new); 00711 close(dd); 00712 FlushToEnd(CONN->sd,size - n_read_total); 00713 EVP_CIPHER_CTX_cleanup(&ctx); 00714 return false; 00715 } 00716 } 00717 00718 if (ip->encrypt == 'y') /* final crypto cleanup */ 00719 { 00720 if (!EVP_DecryptFinal(&ctx,buf,&plainlen)) 00721 { 00722 Debug("Final decrypt failed\n"); 00723 return false; 00724 } 00725 00726 if (!EmbeddedWrite(new,dd,buf,ip,plainlen,&last_write_made_hole,n_read)) 00727 { 00728 snprintf(OUTPUT,bufsize,"Local disk write failed copying %s:%s to %s\n",ip->server,source,new); 00729 CfLog(cferror,OUTPUT,""); 00730 free(buf); 00731 unlink(new); 00732 close(dd); 00733 FlushToEnd(CONN->sd,size - n_read_total); 00734 EVP_CIPHER_CTX_cleanup(&ctx); 00735 return false; 00736 } 00737 } 00738 00739 /* If the file ends with a `hole', something needs to be written at 00740 the end. Otherwise the kernel would truncate the file at the end 00741 of the last write operation. Write a null character and truncate 00742 it again. */ 00743 00744 if (last_write_made_hole) 00745 { 00746 if (cf_full_write (dd,"",1) < 0 || ftruncate (dd,n_read_total) < 0) 00747 { 00748 CfLog(cferror,"cfengine: full_write or ftruncate error in CopyReg\n",""); 00749 free(buf); 00750 unlink(new); 00751 close(dd); 00752 FlushToEnd(CONN->sd,size - n_read_total); 00753 EVP_CIPHER_CTX_cleanup(&ctx); 00754 return false; 00755 } 00756 } 00757 00758 Debug("End of CopyNetReg\n"); 00759 close(dd); 00760 free(buf); 00761 EVP_CIPHER_CTX_cleanup(&ctx); 00762 return true; 00763 }
|
|
|
Definition at line 881 of file client.c. References NULL. 00885 { 00886 if (ap->session_key != NULL) 00887 { 00888 free(ap->session_key); 00889 } 00890 00891 free(ap); 00892 ap = NULL; 00893 }
|
|
|
Definition at line 417 of file client.c. References NULL. Referenced by CheckImage().
|
|
||||||||||||
|
Definition at line 841 of file client.c. References bufsize, cfinform, CfLog(), i, OUTPUT, and snprintf(). Referenced by CopyRegNet(). 00845 { int i; 00846 char buffer[2]; 00847 00848 snprintf(OUTPUT,bufsize*2,"Flushing rest of file...%d bytes\n",toget); 00849 CfLog(cfinform,OUTPUT,""); 00850 00851 for (i = 0; i < toget; i++) 00852 { 00853 recv(sd,buffer,1,0); /* flush to end of current file */ 00854 } 00855 }
|
|
||||||||||||||||||||
|
Definition at line 769 of file client.c. References Image::cache, cfstat::cf_atime, cfstat::cf_ctime, cfstat::cf_failed, cfstat::cf_filename, cfstat::cf_gid, cfstat::cf_ino, cfstat::cf_lmode, cfstat::cf_mode, cfstat::cf_mtime, cfstat::cf_nlink, cfstat::cf_server, cfstat::cf_size, cfstat::cf_uid, Debug, errno, cfstat::next, NULL, Image::server, and sp. Referenced by cf_rstat(). 00776 { struct cfstat *sp; 00777 00778 Debug("GetCachedStatData(%s)\n",file); 00779 00780 for (sp = ip->cache; sp != NULL; sp=sp->next) 00781 { 00782 if ((strcmp(ip->server,sp->cf_server) == 0) && (strcmp(file,sp->cf_filename) == 0)) 00783 { 00784 if (sp->cf_failed) /* cached failure from cfopendir */ 00785 { 00786 errno = EPERM; 00787 Debug("Cached failure to stat\n"); 00788 return -1; 00789 } 00790 00791 if ((strcmp(stattype,"link") == 0) && (sp->cf_lmode != 0)) 00792 { 00793 statbuf->st_mode = sp->cf_lmode; 00794 } 00795 else 00796 { 00797 statbuf->st_mode = sp->cf_mode; 00798 } 00799 00800 statbuf->st_uid = sp->cf_uid; 00801 statbuf->st_gid = sp->cf_gid; 00802 statbuf->st_size = sp->cf_size; 00803 statbuf->st_atime = sp->cf_atime; 00804 statbuf->st_mtime = sp->cf_mtime; 00805 statbuf->st_ctime = sp->cf_ctime; 00806 statbuf->st_ino = sp->cf_ino; 00807 statbuf->st_nlink = sp->cf_nlink; 00808 00809 Debug("Found in cache\n"); 00810 return true; 00811 } 00812 } 00813 00814 Debug("Did not find in cache\n"); 00815 return false; 00816 }
|
|
|
Definition at line 859 of file client.c. References cf_not_connected, Debug, cfagent_connection::error, cfagent_connection::family, cfagent_connection::localip, malloc(), NULL, cfagent_connection::remoteip, cfagent_connection::sd, cfagent_connection::session_key, and cfagent_connection::trust. 00861 { struct cfagent_connection *ap; 00862 00863 if ((ap = (struct cfagent_connection *)malloc(sizeof(struct cfagent_connection))) == NULL) 00864 { 00865 return NULL; 00866 } 00867 00868 Debug("New server connection...\n"); 00869 ap->sd = cf_not_connected; 00870 ap->family = AF_INET; 00871 ap->trust = false; 00872 ap->localip[0] = '\0'; 00873 ap->remoteip[0] = '\0'; 00874 ap->session_key = NULL; 00875 ap->error = false; 00876 return ap; 00877 };
|
|
|
Definition at line 41 of file client.c. References AUTHENTICATED, bufsize, cf_not_connected, cferror, cfinform, CfLog(), CloseServerConnection(), CONN, Debug, errno, cfagent_connection::family, IdentifyForVerification(), KeyAuthentication(), cfagent_connection::localip, OUTPUT, RemoteConnect(), cfagent_connection::sd, snprintf(), and VFQNAME. Referenced by MakeImages(). 00045 { 00046 if (strcmp(ip->server,"localhost") == 0) 00047 { 00048 AUTHENTICATED = true; 00049 return true; 00050 } 00051 00052 AUTHENTICATED = false; 00053 00054 if (CONN->sd == cf_not_connected) 00055 { 00056 Debug("Opening server connnection to %s\n",ip->server); 00057 00058 if (!RemoteConnect(ip->server,ip->forceipv4)) 00059 { 00060 CfLog(cfinform,"Couldn't open a socket","socket"); 00061 if (CONN->sd != cf_not_connected) 00062 { 00063 CloseServerConnection(); 00064 } 00065 AUTHENTICATED = false; 00066 return false; 00067 } 00068 00069 if (!IdentifyForVerification(CONN->sd,CONN->localip,CONN->family)) 00070 { 00071 snprintf(OUTPUT,bufsize,"Id-authentication for %s failed\n",VFQNAME); 00072 CfLog(cferror,OUTPUT,""); 00073 errno = EPERM; 00074 CloseServerConnection(); 00075 AUTHENTICATED = false; 00076 return false; 00077 } 00078 00079 if (ip->compat == 'y') 00080 { 00081 CfLog(cfinform,"WARNING: the connection to %s is not offering key authentication\n",""); 00082 CfLog(cfinform,"WARNING: oldserver=true is a TEMPORARY measure only\n",""); 00083 } 00084 00085 else if (!KeyAuthentication(ip)) 00086 { 00087 snprintf(OUTPUT,bufsize,"Authentication dialogue with %s failed\n",ip->server); 00088 CfLog(cferror,OUTPUT,""); 00089 errno = EPERM; 00090 CloseServerConnection(); 00091 AUTHENTICATED = false; 00092 return false; 00093 } 00094 00095 AUTHENTICATED = true; 00096 return true; 00097 } 00098 else 00099 { 00100 Debug("Server connection to %s already open on %d\n",ip->server,CONN->sd); 00101 } 00102 00103 AUTHENTICATED = true; 00104 return true; 00105 }
|