Added libcurl to download remote repos
Added the functions to download and add the contents to tmpfile Updated the Makefile and README.mdstable
parent
7de6403f27
commit
bba9693138
2
Makefile
2
Makefile
|
|
@ -3,7 +3,7 @@ dir:
|
|||
if [ ! -d /etc/rhosts ];then mkdir /etc/rhosts;else echo "/etc/rhosts already exists";fi
|
||||
if [ ! -d build ];then mkdir build;else echo "build already exists";fi
|
||||
build: dir
|
||||
gcc src/rhosts.c -o build/rhosts
|
||||
gcc src/rhosts.c -lcurl -o build/rhosts
|
||||
clean:
|
||||
- rm -rf build
|
||||
install: build
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ This reroutes sites to 0.0.0.0 in order to block them from being reached by addi
|
|||
|
||||
- make
|
||||
|
||||
- libcurl4-gnutls-dev
|
||||
|
||||
## Install
|
||||
|
||||
sudo make install
|
||||
|
|
|
|||
48
src/rhosts.c
48
src/rhosts.c
|
|
@ -166,7 +166,6 @@ int preserve_static_entries(){
|
|||
|
||||
// This will download entries from the config
|
||||
int download_entries(struct entry **entries){
|
||||
printf("Downloading of entries is currently unavailable\n");
|
||||
int i = (*entries)[0].entrytype;
|
||||
int rc = 0;
|
||||
FILE *tmpf;
|
||||
|
|
@ -188,6 +187,7 @@ int download_entries(struct entry **entries){
|
|||
printf("Download: %s\n",(*entries)[i].entry);
|
||||
rc = fprintf(tmpf, "# rhosts download - %s", \
|
||||
(*entries)[i].entry);
|
||||
fflush(tmpf);
|
||||
if (rc == EOF){
|
||||
printf("Failed to write to %s\n", \
|
||||
TMPDOWNLOADLOCATION);
|
||||
|
|
@ -195,7 +195,7 @@ int download_entries(struct entry **entries){
|
|||
fclose(tmpf);
|
||||
return 1;
|
||||
}
|
||||
// Here is where the download func should be called
|
||||
download_libcurl((*entries)[i].entry);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -239,3 +239,47 @@ int add_site_entries(struct entry **entries){
|
|||
fclose(tmpf);
|
||||
return 0;
|
||||
}
|
||||
// Uses libcurl to download and add file to tmpf
|
||||
int download_libcurl(char *e){
|
||||
CURL *curl;
|
||||
CURLcode res;
|
||||
|
||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
curl = curl_easy_init();
|
||||
if(curl){
|
||||
// Add the url
|
||||
curl_easy_setopt(curl, CURLOPT_URL, e);
|
||||
// Skip cert check
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
|
||||
// Ignore if cert has a different HostName
|
||||
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
|
||||
// Send what is recieved to function
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, parse_download);
|
||||
|
||||
// Download the file
|
||||
res = curl_easy_perform(curl);
|
||||
if(res != CURLE_OK){
|
||||
printf("Failed to download the file %d", res);
|
||||
return 1;
|
||||
}
|
||||
curl_easy_cleanup(curl);
|
||||
}
|
||||
curl_global_cleanup();
|
||||
|
||||
return 0;
|
||||
}
|
||||
// Parse what was downloaded
|
||||
int parse_download(char *buff, size_t size, size_t nmemb){
|
||||
FILE *tmpf;
|
||||
int i=0;
|
||||
int rc=0;
|
||||
tmpf = fopen(TMPLOCATION, "a");
|
||||
for(i=0;i<nmemb;i++){
|
||||
rc = fputc(buff[i], tmpf);
|
||||
if(rc == EOF)
|
||||
break;
|
||||
rc = i +1;
|
||||
}
|
||||
fclose(tmpf);
|
||||
return nmemb;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#ifdef _WIN64
|
||||
#define TMPLOCATION "/tmp/rhosts"
|
||||
#define TMPDOWNLOADLOCATION "/tmp/rhostsdownload"
|
||||
|
|
@ -41,4 +43,6 @@ short int determine_config_entry_value(char *buff);
|
|||
int preserve_static_entries();
|
||||
int download_entries(struct entry **entries);
|
||||
int add_site_entries(struct entry **entries);
|
||||
int download_libcurl(char *e);
|
||||
int parse_download(char *buff, size_t size, size_t nmemb);
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue