int getLotToIndex(char subname[],char HostName[], int dirty) { int LotNr; int sock; int i; if ((sock = cconnect(HostName, BLDPORT)) == 0) { perror(HostName); return 0; } //sender heder printf("sending heder\n"); sendpacked(sock,C_getLotToIndex,BLDPROTOCOLVERSION, 0, NULL,subname); //sender dirty printf("sending dirty (%i)\n",dirty); sendall(sock,&dirty, sizeof(dirty)); //leser inn lotnr if ((i=recv(sock, &LotNr, sizeof(LotNr),MSG_WAITALL)) == -1) { perror("getLotToIndex: Cant recv lot"); return 0; } close(sock); return LotNr; }
int boithoad_groupsForUser(const char username_in[],char **respons_list[],int *nrofresponses) { int socketha; char username[64]; //ToDo: strscpy strncpy(username,username_in,sizeof(username)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { printf("boithoad_groupsForUser: can't connect\n"); return 0; } sendpacked(socketha,bad_groupsForUser,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha,username, sizeof(username)); if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) { printf("boithoad_groupsForUser: can't getLdapResponsList for user \"%s\"\n",username); return 0; } close(socketha); #ifdef DEBUG int i_debug; printf("debug: have %i groups\n",*nrofresponses); for (i_debug=0;i_debug<*nrofresponses;i_debug++) { printf("debug: group name \"%s\", nr %i\n",(*respons_list)[i_debug],i_debug); } #endif return 1; }
int lotHasSufficientSpaceNetToHostname(int LotNr, int needSpace, char subname[], char server[]) { int response; int sock; int i; if ((sock = cconnect(server, BLDPORT)) == 0) { perror(server); return 0; } //sender heder sendpacked(sock,C_getlotHasSufficientSpace,BLDPROTOCOLVERSION, 0, NULL,subname); //sender needSpace og lotnr sendall(sock,&LotNr, sizeof(LotNr)); sendall(sock,&needSpace, sizeof(needSpace)); //leser inn svar if ((i=recv(sock, &response, sizeof(response),MSG_WAITALL)) == -1) { perror("lotHasSufficientSpaceNetToHostname: Cant recv response"); return 0; } close(sock); return response; }
int cmc_pathaccess(int socketha,char collection_in[], char uri_in[], char user_in[], char password_in[]) { char collection[64]; char uri[512]; char user[64]; char password[64]; int intrespons; int i; char all[64+512+64+64]; memset(collection,'\0',sizeof(collection)); //toDo bruk strSspy strncpy(all,collection_in,sizeof(collection)); strncpy(all+64,uri_in,sizeof(uri)); strncpy(all+512+64,user_in,sizeof(user)); strncpy(all+512+64+64,password_in,sizeof(password)); sendpacked(socketha,cm_pathaccess,BLDPROTOCOLVERSION, sizeof(all), all, collection); if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } #ifdef DEBUG printf("cmc_pathaccess: intrespons %i\n",intrespons); #endif return intrespons; }
struct cm_listusers_h cmc_listusersus(int sock, int usersystem, char ***users, char *extra_in) { struct cm_listusers_h users_h; int i, n_users; char user[MAX_LDAP_ATTR_LEN]; char extrabuf[512]; strncpy(extrabuf, extra_in, sizeof extrabuf); sendpacked(sock, cm_listusersus, BLDPROTOCOLVERSION, 0, NULL, ""); sendall(sock, &usersystem, sizeof(usersystem)); sendall(sock, &extrabuf, sizeof extrabuf); recv(sock, &users_h, sizeof(users_h), 0); n_users = users_h.num_users; if (n_users >= 0) { *users = malloc((n_users+1) * sizeof(char *)); // runarb 2 sept 2009: m� finne en m�te � sjekke om malloc fungerte her. //if (*users == NULL) { // perror("malloc"); // return 0; //} for (i = 0; i < n_users; i++) { recv(sock, user, sizeof(user), 0); (*users)[i] = strdup(user); } (*users)[n_users] = NULL; } return users_h; }
/* Delete an uri from the system */ int bbdn_deleteuri(int socketha, char subname[], char *uri) { int len, intrespons, i; debug("bbdn_deleteuri start"); sendpacked(socketha,bbc_deleteuri,BLDPROTOCOLVERSION, 0, NULL,""); len = strlen(subname) +1; if(sendall(socketha,&len, sizeof(int)) == -1) { perror("sendall"); exit(1); } if(sendall(socketha,subname, len) == -1) { perror("sendall"); exit(1); } len = strlen(uri) +1; if(sendall(socketha,&len, sizeof(int)) == -1) { perror("sendall"); exit(1); } if(sendall(socketha,uri, len) == -1) { perror("sendall"); exit(1); } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { bperror("Cant recv respons"); intrespons = 0; } debug("bbdn_deleteuri end"); return intrespons; }
int boithoad_listUsers(char **respons_list[],int *nrofresponses){ int socketha; //hvis nos skulle skje lendere nede så har vi 0 brukere. *nrofresponses = 0; if ((socketha = cconnect("localhost", BADPORT)) == 0) { #ifdef DEBUG printf("cant connect to boithobd at %s:%d\n",__FILE__,__LINE__); #endif return 0; } sendpacked(socketha,bad_listUsers,BADPROTOCOLVERSION, 0, NULL,""); if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) { return 0; } close(socketha); return 1; }
int cmc_groupsforuserfromusersystem(int socketha, char *_user, unsigned int us, char ***_groups, char *extra_in) { int n; char **groups; void *all, *p; #ifdef DEBUG_TIME struct timeval ts, te; #endif int allsize = 512 + 512 + sizeof(us); if ((all = malloc(allsize)) == NULL) { perror("cmc_groupsforuserfromusersystem; malloc all buf"); return 0; } p = all; // kopierer all dataen i en pakke strncpy(p, _user, 512); p += 512; memcpy(p, &us, sizeof(us)); p += sizeof(us); strncpy(p, extra_in, 512); p += 512; sendpacked(socketha, cm_groupsforuserfromusersystem, BLDPROTOCOLVERSION, allsize, all, ""); free(all); if (recv(socketha, &n, sizeof n, MSG_WAITALL) == -1) { perror("groupsbyuserforcoll recv"); return 0; } #ifdef DEBUG_TIME gettimeofday(&ts, NULL); #endif if (n > 0) { groups = calloc(n, MAX_LDAP_ATTR_LEN); if (recv(socketha, groups, n * MAX_LDAP_ATTR_LEN, MSG_WAITALL) == -1) { perror("groupsbyuserforcoll recv"); return 0; } *_groups = groups; } else { *_groups = NULL; } #ifdef DEBUG_TIME gettimeofday(&te, NULL); printf("grepme cmc_groupsforuserfromusersystem took: %f\n", getTimeDifference(&ts, &te)); #endif return n; }
int cmc_removeForeignUsers(int sock, char *collection) { int n; sendpacked(sock, cm_removeForeignUsers, BLDPROTOCOLVERSION, 0, NULL, collection); recv(sock, &n, sizeof(n), MSG_WAITALL); return n; }
int cmc_usersystemfromcollection(int sock, char *collection) { int n; sendpacked(sock, cm_usersystemfromcollection, BLDPROTOCOLVERSION, 0, NULL, collection); recv(sock, &n, sizeof(n), MSG_WAITALL); return n; }
void bbdn_opencollection(int sock, char *subname) { int len; sendpacked(sock, bbc_opencollection, BLDPROTOCOLVERSION, 0, NULL, ""); len = strlen(subname); if (sendall(sock, &len, sizeof(len)) == -1) err(1, "sendall(len)"); if (sendall(sock, subname, len) == -1) err(1, "sendall(subname)"); }
int cmc_killcrawl(int socketha, int port) { int resp; sendpacked(socketha, cm_killcrawl, BLDPROTOCOLVERSION, 0, NULL, ""); if (sendall(socketha, &port, sizeof port) == 0) { perror("killcrawl sendall"); exit(1); } if (recv(socketha, &resp, sizeof resp, MSG_WAITALL) == -1) { perror("killcrawl recv"); return 0; } return resp; }
//stenger ned å kjører etterpehandler på en koleksin. Dette er ikke det samme som å stenge ned socketen int bbdn_closecollection(int socketha, char subname[]) { int len; debug("bbdn_closecollection start"); sendpacked(socketha,bbc_closecollection,BLDPROTOCOLVERSION, 0, NULL,""); len = strlen(subname) +1; if(sendall(socketha,&len, sizeof(int)) == -1) { perror("sendall"); exit(1); } if(sendall(socketha,subname, len) == -1) { perror("sendall"); exit(1); } debug("bbdn_closecollection end"); return 1; }
int cmc_addForeignUsers(int sock, char *collection, char *inuser, char *ingroup) { int n; char group[512], user[512]; strlcpy(group, ingroup, sizeof(group)); strlcpy(user, inuser, sizeof(user)); sendpacked(sock, cm_removeForeignUsers, BLDPROTOCOLVERSION, 0, NULL, collection); sendall(sock, user, sizeof(user)); sendall(sock, group, sizeof(group)); recv(sock, &n, sizeof(n), MSG_WAITALL); return n; }
int cmc_collectionislocked(int socketha, char *collection_in) { char collection[64]; int r, i; strncpy(collection, collection_in, sizeof(collection)); sendpacked(socketha, cm_collectionislocked, BLDPROTOCOLVERSION, 0, NULL, ""); sendall(socketha, &collection, sizeof(collection)); if ((i=recv(socketha, &r, sizeof(r),MSG_WAITALL)) == -1) { return 1; } return r; }
int bbdn_addwhisper(int sock, char *subname, whisper_t whisper) { int len; debug("bbdn_addwhisper: start"); sendpacked(sock, bbc_addwhisper, BLDPROTOCOLVERSION, 0, NULL, ""); len = strlen(subname); if (sendall(sock, &len, sizeof(len)) == -1) err(1, "sendall(len)"); if (sendall(sock, subname, len) == -1) err(1, "sendall(subname)"); if (sendall(sock, &whisper, sizeof(whisper)) == -1) err(1, "sendall(whisper)"); debug("bbdn_addwhisper: end"); return 1; }
int cmc_rewrite_url(int socketha, char *collection_in, const char *url_in, enum platform_type ptype, enum browser_type btype, char *url_out, size_t url_out_len, char *uri_out, size_t uri_out_len, char *fulluri_out, size_t fulluri_out_len) { struct rewriteFormat rewrite; #ifdef DEBUG_TIME struct timeval start_time, end_time; printf("cmc_rewrite_url(collection_in=\"%s\", url_in=\"%s\")\n",collection_in,url_in); gettimeofday(&start_time, NULL); #endif memset(&rewrite, '\0', sizeof(rewrite)); strscpy(rewrite.collection, collection_in, sizeof(rewrite.collection)); strscpy(rewrite.url, url_in, sizeof(rewrite.url)); rewrite.ptype = ptype; rewrite.btype = btype; sendpacked(socketha, cm_rewriteurl, BLDPROTOCOLVERSION, sizeof(rewrite), &rewrite, ""); if (recvall(socketha, &rewrite, sizeof(rewrite)) == 0) { perror("recvall(url)"); return 0; } strscpy(url_out, rewrite.url, url_out_len); strscpy(uri_out, rewrite.uri, uri_out_len); strscpy(fulluri_out, rewrite.fulluri, fulluri_out_len); #ifdef DEBUG printf("~cmc_rewrite_url [uri_out=\"%s\", fulluri=\"%s\"]\n",uri_out,fulluri_out); #endif #ifdef DEBUG_TIME gettimeofday(&end_time, NULL); printf("~cmc_rewrite_url(2) time %f\n",getTimeDifference(&start_time,&end_time)); #endif return 1; }
int bbdn_conect(int *socketha, char tkey[], int PORT) { int intrespons; int i; if (((*socketha) = cconnect("127.0.0.1", PORT)) == 0) { bperror("Can't connect to back-end document manager"); return 0; } //sender heder sendpacked((*socketha),bbc_askToAuthenticate,BLDPROTOCOLVERSION, 0, NULL,""); if (!sendall((*socketha),tkey, 32)) { bperror("sendall"); goto bbdn_conect_err; } if ((i=recv((*socketha), &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { bperror("Cant recv respons"); goto bbdn_conect_err; } if (intrespons == bbc_authenticate_ok) { debug("bbc authenticate ok\n"); return 1; } else if (intrespons == bbc_authenticate_feiled) { berror("bbc authenticate feiled"); goto bbdn_conect_err; } else { berror("respons from server was nider bbc_authenticate_feiled or bbc_authenticate_ok!\n"); goto bbdn_conect_err; } bbdn_conect_err: close(*socketha); return 0; }
int boithoad_sidToGroup(char sid_in[], char username_in[]) { int socketha; int intresponse; char username[64]; char sid[512]; int forreturn = 0; //ToDo: strscpy strncpy(sid,sid_in,sizeof(sid)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { return 0; } sendpacked(socketha,bad_sidToGroup,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha, sid, sizeof(sid)); //read respons if (!recvall(socketha,&intresponse,sizeof(intresponse))) { return 0; } if (intresponse == 1) { if (!recvall(socketha,username,sizeof(username))) { return 0; } strcpy(username_in, username); forreturn = 1; } else { #ifdef DEBUG printf("didn't have a group at %s:%d\n",__FILE__,__LINE__); #endif strcpy(username_in,""); forreturn = 0; } close(socketha); return forreturn; }
int cmc_scan(int socketha,char **respons_list[],int *nrofresponses,char **errormsgp,char crawlertype_in[], char host_in[],char username_in[],char password_in[]) { char crawlertype[64]; char host[64]; char username[64]; char password[64]; int i,len; static char errormsg[512]; strscpy(crawlertype,crawlertype_in,sizeof(crawlertype)); strscpy(host,host_in,sizeof(host)); strscpy(username,username_in,sizeof(username)); strscpy(password,password_in,sizeof(password)); sendpacked(socketha,cm_scan,BLDPROTOCOLVERSION, 0, NULL,""); if(sendall(socketha,&crawlertype, sizeof(crawlertype)) == 0) { perror("sendall"); exit(1); } if(sendall(socketha,&host, sizeof(host)) == 0) { perror("sendall"); exit(1); } if(sendall(socketha,&username, sizeof(username)) == 0) { perror("sendall"); exit(1); } if(sendall(socketha,&password, sizeof(password)) == 0) { perror("sendall"); exit(1); } socketgetsaa(socketha,respons_list,nrofresponses); if ((*nrofresponses) == 0) { if ((i=recv(socketha, &len, sizeof(len),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } if ((i=recv(socketha, errormsg, len,MSG_WAITALL)) == -1) { perror("Cant read respons"); return 0; } (*errormsgp) = errormsg; return 0; } return 1; }
int boitho_authenticat(const char username_in[],char password_in[]) { int socketha; int response; char username[64]; char password[64]; strncpy(username,username_in,sizeof(username)); strncpy(password,password_in,sizeof(password)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { perror("localhost"); return 0; } #ifdef DEBUG printf("boitho_authenticat: dic cconnect\n"); #endif sendpacked(socketha,bad_askToAuthenticate,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha,username, sizeof(username)); sendall(socketha,password, sizeof(password)); recvall(socketha,&response,sizeof(response)); close(socketha); if (response == ad_userauthenticated_OK) { return 1; } else if (response == ad_userauthenticated_ERROR) { return 0; } else if (response == ad_userauthenticated_NOACCESS) { return 2; } else { fprintf(stderr,"dident get ad_userauthenticated_ERROR or ad_userauthenticated_OK\n"); return 0; } }
int boithoad_getPassword(const char username_in[], char password_in[]) { int socketha; int intresponse; char username[64]; char password[64]; int forreturn = 0; //ToDo: strscpy strncpy(username,username_in,sizeof(username)); if ((socketha = cconnect("localhost", BADPORT)) == 0) { return 0; } sendpacked(socketha,bad_getPassword,BADPROTOCOLVERSION, 0, NULL,""); sendall(socketha,username, sizeof(username)); //read respons if (!recvall(socketha,&intresponse,sizeof(intresponse))) { return 0; } if (intresponse == 1) { if (!recvall(socketha,password,sizeof(password))) { return 0; } //printf("got \"%s\"\n",password); strcpy(password_in,password); forreturn = 1; } else { printf("dident have a passord at %s:%d\n",__FILE__,__LINE__); strcpy(password_in,""); forreturn = 0; } close(socketha); return forreturn; }
/* Delete an uri from the system */ int bbdn_deleteuri(int socketha, char subname[], char *uri) { int len; debug("bbdn_deleteuri start"); sendpacked(socketha,bbc_deleteuri,BLDPROTOCOLVERSION, 0, NULL,""); len = strlen(subname) +1; if(sendall(socketha,&len, sizeof(int)) == -1) { perror("sendall"); exit(1); } if(sendall(socketha,subname, len) == -1) { perror("sendall"); exit(1); } len = strlen(uri) +1; if(sendall(socketha,&len, sizeof(int)) == -1) { perror("sendall"); exit(1); } if(sendall(socketha,uri, len) == -1) { perror("sendall"); exit(1); } debug("bbdn_deleteuri end"); return 1; }
int cmc_authuser(int sock, const char *_user, const char *_pass, unsigned int usersystem, char *extra_in) { char user[512], pass[512]; int n; char extrabuf[512]; strncpy(user, _user, sizeof(user)); strncpy(pass, _pass, sizeof(pass)); strncpy(extrabuf, extra_in, sizeof extrabuf); sendpacked(sock, cm_authenticateuser, BLDPROTOCOLVERSION, 0, NULL, ""); sendall(sock, &user, sizeof(user)); sendall(sock, &pass, sizeof(pass)); sendall(sock, &usersystem, sizeof(usersystem)); sendall(sock, &extrabuf, sizeof extrabuf); recv(sock, &n, sizeof(int), 0); return n; }
int cmc_crawlcanconect (int socketha, char vantcollection[], char statusbuff[],int statusbufflen) { int i; int intrespons; char *respons; char collection[64]; //extern int errno; sendpacked(socketha,cm_crawlcanconect,BLDPROTOCOLVERSION, 0, NULL,""); //sending coll strscpy(collection,vantcollection,sizeof(collection)); if(sendall(socketha,&collection, sizeof(collection)) == 0) { perror("sendall"); exit(1); } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { perror("Cant recv respons"); snprintf(statusbuff,statusbufflen,"recv: %s",strerror(errno)); return 0; } respons = malloc(intrespons +1); if ((i=recv(socketha, respons, intrespons,MSG_WAITALL)) == -1) { perror("Cant read respons"); snprintf(statusbuff,statusbufflen,"recv: %s",strerror(errno)); return 0; } if (strcmp(respons,"ok") != 0) { fprintf(stderr,"respons was not ok, but \"%s\"\n", respons); strscpy(statusbuff,respons,statusbufflen); return 0; } #ifdef DEBUG printf("~cmc_crawlcanconect=1\n"); #endif return 1; }
int cmc_collectionsforuser(int sock, char *_user, char **_collections) { char user[512]; int n; char *collections; strncpy(user, _user, sizeof(user)); sendpacked(sock, cm_collectionsforuser, BLDPROTOCOLVERSION, sizeof(user), user, ""); recv(sock, &n, sizeof(n), MSG_WAITALL); if (n == 0) { collections = strdup(""); } else { collections = calloc(n, maxSubnameLength+1); recv(sock, collections, (maxSubnameLength+1)*n, MSG_WAITALL); } *_collections = collections; return n; }
int boithoad_listGroups( char **respons_list[],int *nrofresponses){ int socketha; if ((socketha = cconnect("localhost", BADPORT)) == 0) { return 0; } sendpacked(socketha,bad_listGroups,BADPROTOCOLVERSION, 0, NULL,""); if (!boithoa_getLdapResponsList(socketha,respons_list,nrofresponses)) { return 0; } close(socketha); return 1; }
int cmc_crawl(int socketha,char collection_inn[], char *extra_in) { char collection[64]; char extrabuf[512]; int intrespons; int i; //toDo bruk strSspy strncpy(collection,collection_inn,sizeof(collection)); strncpy(extrabuf, extra_in, sizeof(extrabuf)); sendpacked(socketha,cm_crawlcollection,BLDPROTOCOLVERSION, 0, NULL,""); if(sendall(socketha,&collection, sizeof(collection)) == 0) { perror("sendall"); exit(1); } if(sendall(socketha,&extrabuf, sizeof(extrabuf)) == 0) { perror("sendall"); exit(1); } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } return 1; }
int cmc_deleteCollection(int socketha,char collection_in[], char **errormsgp) { char collection[64]; int intrespons; int i, len; static char errormsg[512]; //toDo bruk strSspy strncpy(collection,collection_in,sizeof(collection)); sendpacked(socketha,cm_deleteCollection,BLDPROTOCOLVERSION, 0, NULL,""); if(sendall(socketha,&collection, sizeof(collection)) == 0) { perror("sendall"); exit(1); } if ((i=recv(socketha, &intrespons, sizeof(intrespons),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } if (intrespons == 0) { if ((i=recv(socketha, &len, sizeof(len),MSG_WAITALL)) == -1) { perror("Cant recv respons"); return 0; } if ((i=recv(socketha, errormsg, len,MSG_WAITALL)) == -1) { perror("Cant read respons"); return 0; } (*errormsgp) = errormsg; return 0; } return 1; }
int rComand(char dest[], int LotNr,char subname[]) { int destLen; int socketha = conectTo(LotNr); //sender heder sendpacked(socketha,C_rComand,BLDPROTOCOLVERSION, 0, NULL,subname); //sender lotnr sendall(socketha,&LotNr, sizeof(LotNr)); destLen = strlen(dest) +1; // \0 //sender destinasjonsstring lengde sendall(socketha,&destLen, sizeof(destLen)); //sender destinasjon sendall(socketha,dest, destLen); return 1; }