/* * modify an existing node */ void display_edit_node(void) { WCTemplputParams SubTP; HashList *NodeConfig; const StrBuf *Index; void *vNode; const StrBuf *Tmpl; Index = sbstr("index"); if (Index == NULL) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; } StackContext(NULL, &SubTP, vNode, CTX_NODECONF, 0, NULL); { begin_burst(); Tmpl = sbstr("template"); output_headers(1, 0, 0, 0, 1, 0); DoTemplate(SKEY(Tmpl), NULL, &SubTP); end_burst(); } UnStackContext(&SubTP); DeleteHash(&NodeConfig); }
void ServerShutdownModule_CONTEXT (void) { DeleteHash(&HttpReqTypes); DeleteHash(&HttpHeaderHandler); }
void pop3_cleanup(void) { /* citthread_mutex_destroy(&POP3QueueMutex); TODO */ while (doing_pop3client != 0) ; DeleteHash(&POP3FetchUrls); DeleteHash(&POP3QueueRooms); }
/* * actually delete the node */ void delete_node(void) { HashList *NodeConfig; const StrBuf *Index; NodeConf *Node; void *vNode; Index = sbstr("index"); if (Index == NULL) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); if (!GetHash(NodeConfig, ChrPtr(Index), StrLength(Index), &vNode) || (vNode == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); DeleteHash(&NodeConfig); return; } Node = (NodeConf *) vNode; Node->DeleteMe = 1; save_net_conf(NodeConfig); DeleteHash(&NodeConfig); url_do_template(); }
void smtp_evq_cleanup(void) { pthread_mutex_lock(&ActiveQItemsLock); DeleteHash(&QItemHandlers); DeleteHash(&ActiveQItems); pthread_mutex_unlock(&ActiveQItemsLock); pthread_setspecific(MyConKey, (void *)&smtp_queue_CC); /* citthread_mutex_destroy(&ActiveQItemsLock); TODO */ }
void ServerShutdownModule_WEBCIT (void) { FreeStrBuf(&csslocal); DeleteHash(&HandlerHash); }
void HttpDetachModule_CONTEXT (ParsedHttpHdrs *httpreq) { FlushStrBuf(httpreq->PlainArgs); FlushStrBuf(httpreq->HostHeader); FlushStrBuf(httpreq->this_page); FlushStrBuf(httpreq->PlainArgs); DeleteHash(&httpreq->HTTPHeaders); memset(&httpreq->HR, 0, sizeof(HdrRefs)); }
void Free_ctdl_openid(ctdl_openid **FreeMe) { if (*FreeMe == NULL) { return; } FreeStrBuf(&(*FreeMe)->op_url); FreeStrBuf(&(*FreeMe)->claimed_id); DeleteHash(&(*FreeMe)->sreg_keys); free(*FreeMe); *FreeMe = NULL; }
/* * this thread operates the select() etc. via libev. */ void *client_event_thread(void *arg) { struct CitContext libev_client_CC; CtdlFillSystemContext(&libev_client_CC, "LibEv Thread"); pthread_setspecific(evConKey, IOLog); EVQM_syslog(LOG_DEBUG, "client_event_thread() initializing\n"); event_base = ev_default_loop (EVFLAG_AUTO); ev_async_init(&AddJob, QueueEventAddCallback); ev_async_start(event_base, &AddJob); ev_async_init(&ExitEventLoop, EventExitCallback); ev_async_start(event_base, &ExitEventLoop); ev_async_init(&WakeupCurl, WakeupCurlCallback); ev_async_start(event_base, &WakeupCurl); curl_init_connectionpool(); ev_run (event_base, 0); EVQM_syslog(LOG_DEBUG, "client_event_thread() exiting\n"); ///what todo here? CtdlClearSystemContext(); pthread_mutex_lock(&EventExitQueueMutex); ev_loop_destroy (EV_DEFAULT_UC); event_base = NULL; DeleteHash(&QueueEvents); InboundEventQueue = NULL; DeleteHash(&InboundEventQueues[0]); DeleteHash(&InboundEventQueues[1]); /* citthread_mutex_destroy(&EventQueueMutex); TODO */ evcurl_shutdown(); CtdlDestroyEVCleanupHooks(); pthread_mutex_unlock(&EventExitQueueMutex); EVQShutDown = 1; return(NULL); }
void HttpDestroyModule_CONTEXT (ParsedHttpHdrs *httpreq) { FreeStrBuf(&httpreq->this_page); FreeStrBuf(&httpreq->PlainArgs); FreeStrBuf(&httpreq->this_page); FreeStrBuf(&httpreq->PlainArgs); FreeStrBuf(&httpreq->HostHeader); DeleteHash(&httpreq->HTTPHeaders); }
/* * this thread operates writing to the message database via libev. */ void *db_event_thread(void *arg) { ev_loop *tmp; struct CitContext libev_msg_CC; pthread_setspecific(evConKey, DBLog); CtdlFillSystemContext(&libev_msg_CC, "LibEv DB IO Thread"); EVQM_syslog(LOG_DEBUG, "dbevent_thread() initializing\n"); tmp = event_db = ev_loop_new (EVFLAG_AUTO); ev_async_init(&DBAddJob, DBQueueEventAddCallback); ev_async_start(event_db, &DBAddJob); ev_async_init(&DBExitEventLoop, DBEventExitCallback); ev_async_start(event_db, &DBExitEventLoop); ev_run (event_db, 0); pthread_mutex_lock(&DBEventExitQueueMutex); event_db = NULL; EVQM_syslog(LOG_INFO, "dbevent_thread() exiting\n"); DeleteHash(&DBQueueEvents); DBInboundEventQueue = NULL; DeleteHash(&DBInboundEventQueues[0]); DeleteHash(&DBInboundEventQueues[1]); /* citthread_mutex_destroy(&DBEventQueueMutex); TODO */ ev_loop_destroy (tmp); pthread_mutex_unlock(&DBEventExitQueueMutex); return(NULL); }
void FreeQueItem(OneQueItem **Item) { /* SMTPC_syslog(LOG_DEBUG, "---------------%s--------------", __FUNCTION__); cit_backtrace(); */ DeleteHash(&(*Item)->MailQEntries); FreeStrBuf(&(*Item)->EnvelopeFrom); FreeStrBuf(&(*Item)->BounceTo); FreeStrBuf(&(*Item)->SenderRoom); FreeURL(&(*Item)->URL); memset(*Item, 0, sizeof(OneQueItem)); free(*Item); Item = NULL; }
/* * Purge OpenID assocations for missing users (theoretically this will never delete anything) */ int PurgeStaleOpenIDassociations(void) { struct cdbdata *cdboi; struct ctdluser usbuf; HashList *keys = NULL; HashPos *HashPos; char *deleteme = NULL; long len; void *Value; const char *Key; int num_deleted = 0; long usernum = 0L; keys = NewHash(1, NULL); if (!keys) return(0); cdb_rewind(CDB_OPENID); while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) { if (cdboi->len > sizeof(long)) { memcpy(&usernum, cdboi->ptr, sizeof(long)); if (CtdlGetUserByNumber(&usbuf, usernum) != 0) { deleteme = strdup(cdboi->ptr + sizeof(long)), Put(keys, deleteme, strlen(deleteme), deleteme, NULL); } } cdb_free(cdboi); } /* Go through the hash list, deleting keys we stored in it */ HashPos = GetNewHashPos(keys, 0); while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0) { syslog(LOG_DEBUG, "Deleting associated OpenID <%s>", (char*)Value); cdb_delete(CDB_OPENID, Value, strlen(Value)); /* note: don't free(Value) -- deleting the hash list will handle this for us */ ++num_deleted; } DeleteHashPos(&HashPos); DeleteHash(&keys); return num_deleted; }
boolean DeleteCurrList(List l) { ListElem *ElemToFree=l->C; if(l->nobject==0) { Error("DeleteCurrList, Trying to delete in a empty list\n",NO_EXIT); return FALSE; /* Empty list */ } if(l->C==NULL) { Error("DeleteCurrList, Trying to delete a NULL current of List\n",NO_EXIT); return FALSE; /* Unsetted Current element l->C */ } if(l->nobject==1) /* One element List, the list beco-*/ { /* me empty and all pointers NULL */ l->T=NULL; l->H=NULL; } if(l->hash) if(!DeleteHash(l->C->obj, l)) { Error("DeleteCurrList, L->C was not in hash\n",NO_EXIT); return FALSE; } if(l->H==l->C) l->H=l->C->prev; if(l->T==l->C) l->T=l->C->next; if(l->C->next) l->C->next->prev=l->C->prev; if(l->C->prev) l->C->prev->next=l->C->next; if(l->type == CIRCULAR && (l->nobject > 1)) l->C=l->C->next; else l->C=NULL; free(ElemToFree); l->nobject--; return TRUE; }
int DuplicateAtK(HNode* hash,int* Array,int n,int k){ int i; int flag=0; for(i=0;i<n;i++){ flag=Search(hash,Array[i]); if(flag){ break; } Insert(hash,Array[i]); if(i>=k){ DeleteHash(hash,Array[i-k]); } } return flag; }
/* * edit a network node */ void edit_node(void) { HashList *NodeConfig; const StrBuf *Index; NodeConf *NewNode; if (havebstr("ok_button")) { Index = sbstr("index"); NewNode = HttpGetNewNode(); if ((NewNode == NULL) || (Index == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf); save_net_conf(NodeConfig); DeleteHash(&NodeConfig); } url_do_template(); }
void DeletePOP3Aggregator(void *vptr) { pop3aggr *ptr = vptr; DeleteHashPos(&ptr->Pos); DeleteHash(&ptr->MsgNumbers); // FreeStrBuf(&ptr->rooms); FreeStrBuf(&ptr->pop3user); FreeStrBuf(&ptr->pop3pass); FreeStrBuf(&ptr->Host); FreeStrBuf(&ptr->RoomName); FreeURL(&ptr->IO.ConnectMe); FreeStrBuf(&ptr->Url); FreeStrBuf(&ptr->IO.IOBuf); FreeStrBuf(&ptr->IO.SendBuf.Buf); FreeStrBuf(&ptr->IO.RecvBuf.Buf); DeleteAsyncMsg(&ptr->IO.ReadMsg); if (((struct CitContext*)ptr->IO.CitContext)) { ((struct CitContext*)ptr->IO.CitContext)->state = CON_IDLE; ((struct CitContext*)ptr->IO.CitContext)->kill_me = 1; } FreeAsyncIOContents(&ptr->IO); free(ptr); }
void SessionDetachModule_WEBCIT (wcsession *sess) { DeleteHash(&sess->Directory); FreeStrBuf(&sess->upload); sess->upload_length = 0; FreeStrBuf(&sess->trailing_javascript); if (StrLength(sess->WBuf) > SIZ * 30) /* Bigger than 120K? release. */ { FreeStrBuf(&sess->WBuf); sess->WBuf = NewStrBuf(); } else FlushStrBuf(sess->WBuf); FlushStrBuf(sess->HBuf); if (StrLength(sess->ImportantMsg) > 0) { FlushStrBuf(sess->ImportantMsg); } }
/* * Stupidly, XMPP does not specify a way to tell the client to flush its client-side roster * and prepare to receive a new one. So instead we remember every buddy we've ever told the * client about, and push delete operations out at the beginning of a session. * * We omit any users who happen to be online right now, but we still keep them in the mortuary, * which needs to be maintained as a list of every buddy the user has ever seen. We don't know * when they're connecting from the same client and when they're connecting from a different client, * so we have no guarantee of what is in the client side roster at connect time. */ void xmpp_delete_old_buddies_who_no_longer_exist_from_the_client_roster(void) { long len; void *Value; const char *Key; struct CitContext *cptr; int nContexts, i; int online_now = 0; HashList *mortuary = xmpp_fetch_mortuary(); HashPos *HashPos = GetNewHashPos(mortuary, 0); /* we need to omit anyone who is currently online */ cptr = CtdlGetContextArray(&nContexts); /* go through the list of users in the mortuary... */ while (GetNextHashPos(mortuary, HashPos, &len, &Key, &Value) != 0) { online_now = 0; if (cptr) for (i=0; i<nContexts; i++) { if (xmpp_is_visible(&cptr[i], CC)) { if (!strcasecmp(cptr[i].cs_inet_email, (char *)Value)) { online_now = 1; } } } if (!online_now) { xmpp_destroy_buddy((char *)Value, 1); /* aggressive presence update */ } } DeleteHashPos(&HashPos); DeleteHash(&mortuary); free(cptr); }
/* * Upon logout we make an attempt to delete the whole roster, in order to * try to keep "ghost" buddies from remaining in the client-side roster. * * Since the client is probably not still alive, also remember the current * roster for next time so we can delete dead buddies then. */ void xmpp_massacre_roster(void) { struct CitContext *cptr; int nContexts, i; HashList *mortuary = xmpp_fetch_mortuary(); cptr = CtdlGetContextArray(&nContexts); if (cptr) { for (i=0; i<nContexts; i++) { if (xmpp_is_visible(&cptr[i], CC)) { if (mortuary) { char *buddy = strdup(cptr[i].cs_inet_email); Put(mortuary, buddy, strlen(buddy), buddy, NULL); } } } free (cptr); } if (mortuary) { xmpp_store_mortuary(mortuary); DeleteHash(&mortuary); } }
void cleanup_nttlist(void) { begin_critical_section(S_NTTLIST); DeleteHash(&nttlist); end_critical_section(S_NTTLIST); }
int FileHashChanged(EvalContext *ctx, const char *filename, unsigned char digest[EVP_MAX_MD_SIZE + 1], HashMethod type, Attributes attr, const Promise *pp, PromiseResult *result) { int size; unsigned char dbdigest[EVP_MAX_MD_SIZE + 1]; CF_DB *dbp; char buffer[EVP_MAX_MD_SIZE * 4]; size = HashSizeFromId(type); if (!OpenDB(&dbp, dbid_checksums)) { cfPS(ctx, LOG_LEVEL_ERR, PROMISE_RESULT_FAIL, pp, attr, "Unable to open the hash database!"); *result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL); return false; } if (ReadHash(dbp, type, filename, dbdigest)) { if (memcmp(digest, dbdigest, size) != 0) { Log(LOG_LEVEL_NOTICE, "Hash '%s' for '%s' changed!", HashNameFromId(type), filename); if (pp->comment) { Log(LOG_LEVEL_NOTICE, "Preceding promise '%s'", pp->comment); } if (attr.change.update) { cfPS(ctx, LOG_LEVEL_NOTICE, PROMISE_RESULT_CHANGE, pp, attr, "Updating hash for '%s' to '%s'", filename, HashPrintSafe(type, true, digest, buffer)); *result = PromiseResultUpdate(*result, PROMISE_RESULT_CHANGE); DeleteHash(dbp, type, filename); WriteHash(dbp, type, filename, digest); } else { cfPS(ctx, LOG_LEVEL_NOTICE, PROMISE_RESULT_FAIL, pp, attr, "Hash for file '%s' changed", filename); *result = PromiseResultUpdate(*result, PROMISE_RESULT_FAIL); } CloseDB(dbp); return true; } cfPS(ctx, LOG_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, pp, attr, "File hash for %s is correct", filename); *result = PromiseResultUpdate(*result, PROMISE_RESULT_NOOP); CloseDB(dbp); return false; } else { /* Key was not found, so install it */ cfPS(ctx, LOG_LEVEL_NOTICE, PROMISE_RESULT_CHANGE, pp, attr, "File '%s' was not in '%s' database - new file found", filename, HashNameFromId(type)); *result = PromiseResultUpdate(*result, PROMISE_RESULT_CHANGE); Log(LOG_LEVEL_DEBUG, "Storing checksum for '%s' in database '%s'", filename, HashPrintSafe(type, true, digest, buffer)); WriteHash(dbp, type, filename, digest); LogHashChange(filename, FILE_STATE_NEW, "New file found", pp); CloseDB(dbp); return false; } }
void ServerShutdownModule_ICAL (void) { DeleteHash(&IcalComponentMap); }
int FileHashChanged(char *filename, unsigned char digest[EVP_MAX_MD_SIZE + 1], int warnlevel, enum cfhashes type, Attributes attr, Promise *pp) /* Returns false if filename never seen before, and adds a checksum to the database. Returns true if hashes do not match and also potentially updates database to the new value */ { int i, size = 21; unsigned char dbdigest[EVP_MAX_MD_SIZE + 1]; CF_DB *dbp; CfDebug("HashChanged: key %s (type=%d) with data %s\n", filename, type, HashPrint(type, digest)); size = FileHashSize(type); if (!OpenDB(&dbp, dbid_checksums)) { cfPS(OUTPUT_LEVEL_ERROR, CF_FAIL, "", pp, attr, "Unable to open the hash database!"); return false; } if (ReadHash(dbp, type, filename, dbdigest)) { for (i = 0; i < size; i++) { if (digest[i] != dbdigest[i]) { CfDebug("Found cryptohash for %s in database but it didn't match\n", filename); CfOut(warnlevel, "", "ALERT: Hash (%s) for %s changed!", FileHashName(type), filename); if (pp->ref) { CfOut(warnlevel, "", "Preceding promise: %s", pp->ref); } if (attr.change.update) { cfPS(warnlevel, CF_CHG, "", pp, attr, " -> Updating hash for %s to %s", filename, HashPrint(type, digest)); DeleteHash(dbp, type, filename); WriteHash(dbp, type, filename, digest); } else { cfPS(warnlevel, CF_FAIL, "", pp, attr, "!! Hash for file \"%s\" changed", filename); } CloseDB(dbp); return true; } } cfPS(OUTPUT_LEVEL_VERBOSE, CF_NOP, "", pp, attr, " -> File hash for %s is correct", filename); CloseDB(dbp); return false; } else { /* Key was not found, so install it */ cfPS(warnlevel, CF_CHG, "", pp, attr, " !! File %s was not in %s database - new file found", filename, FileHashName(type)); CfDebug("Storing checksum for %s in database %s\n", filename, HashPrint(type, digest)); WriteHash(dbp, type, filename, digest); LogHashChange(filename, cf_file_new, "New file found", pp); CloseDB(dbp); return false; } }
void control_cleanup(void) { DeleteHash(&CfgNameHash); }
void cmd_gvdn(char *argbuf) { const ConfType *pCfg; char *confptr; long min = atol(argbuf); const char *Pos = NULL; const char *PPos = NULL; const char *HKey; long HKLen; StrBuf *Line; StrBuf *Config; StrBuf *Cfg; StrBuf *CfgToken; HashList *List; HashPos *It; void *vptr; List = NewHash(1, NULL); Cfg = NewStrBufPlain(config.c_fqdn, -1); Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; confptr = CtdlGetSysConfig(INTERNETCFG); Config = NewStrBufPlain(confptr, -1); free(confptr); Line = NewStrBufPlain(NULL, StrLength(Config)); CfgToken = NewStrBufPlain(NULL, StrLength(Config)); while (StrBufSipLine(Line, Config, &Pos)) { if (Cfg == NULL) Cfg = NewStrBufPlain(NULL, StrLength(Line)); PPos = NULL; StrBufExtract_NextToken(Cfg, Line, &PPos, '|'); StrBufExtract_NextToken(CfgToken, Line, &PPos, '|'); if (GetHash(CfgNameHash, SKEY(CfgToken), &vptr) && (vptr != NULL)) { pCfg = (ConfType *) vptr; if (pCfg->Type <= min) { Put(List, SKEY(Cfg), Cfg, HFreeStrBuf); Cfg = NULL; } } } cprintf("%d Valid Domains\n", LISTING_FOLLOWS); It = GetNewHashPos(List, 1); while (GetNextHashPos(List, It, &HKLen, &HKey, &vptr)) { cputbuf(vptr); cprintf("\n"); } cprintf("000\n"); DeleteHashPos(&It); DeleteHash(&List); FreeStrBuf(&Cfg); FreeStrBuf(&Line); FreeStrBuf(&CfgToken); FreeStrBuf(&Config); }
void ShutDownLibCitadelMime(void) { DeleteHash(&IconHash); }
boolean ExtractList(pointer Object, List l) { pointer *object=(pointer *)Object; ListElem *elemtofree; if(l->nobject==0) return FALSE; /* Empty list */ switch(l->type) { case FIFO: *object=l->H->obj; /* object to give back */ elemtofree=l->H; l->H = l->H->prev; if(l->H) l->H->next = NULL; /* Was not last obj */ else l->T=NULL; /* Was the last obj */ break; case CIRCULAR: if(l->C==NULL) /* l->C==NULL and Not Empty List */ ErrorFALSE("ExtractList, NULL CurrList in a CIRCULAR list.\n") *object=l->C->obj; /* object to give back */ elemtofree=l->C; if(l->nobject==1) { l->C=NULL; l->T=NULL; l->H=NULL; } else { l->C->prev->next=l->C->next; l->C->next->prev=l->C->prev; if(l->C==l->H) l->H=l->H->prev; if(l->C==l->T) l->T=l->T->next; l->C=l->C->next; } break; case ORDERED: case LIFO: default: *object=l->T->obj; /* object to give back */ elemtofree=l->T; l->T = l->T->next; if(l->T) l->T->prev = NULL; /* Was not last obj */ else l->H = NULL; /* Was the last obj */ } l->nobject--; if(l->hash) if(!DeleteHash(*object, l)) { Error("ExtractList, extracted object was not in hash!\n",NO_EXIT); return FALSE; } /* the following line was modified on 10 Nov 1993; previously I freed elemtofree before the DeleteHash; was wrong but worked on every machine /* free(elemtofree); /* free the memory of old list element */ return TRUE; }
/* * Finalize an OpenID authentication */ void cmd_oidf(char *argbuf) { long len; char buf[2048]; char thiskey[1024]; char thisdata[1024]; HashList *keys = NULL; const char *Key; void *Value; ctdl_openid *oiddata = (ctdl_openid *) CC->openid_data; if (CtdlGetConfigInt("c_disable_newu")) { cprintf("%d this system does not support openid.\n", ERROR + CMD_NOT_SUPPORTED); return; } if (oiddata == NULL) { cprintf("%d run OIDS first.\n", ERROR + INTERNAL_ERROR); return; } if (StrLength(oiddata->op_url) == 0){ cprintf("%d No OpenID Endpoint URL has been obtained.\n", ERROR + ILLEGAL_VALUE); return; } keys = NewHash(1, NULL); if (!keys) { cprintf("%d NewHash() failed\n", ERROR + INTERNAL_ERROR); return; } cprintf("%d Transmit OpenID data now\n", START_CHAT_MODE); while (client_getln(buf, sizeof buf), strcmp(buf, "000")) { len = extract_token(thiskey, buf, 0, '|', sizeof thiskey); if (len < 0) { len = sizeof(thiskey) - 1; } extract_token(thisdata, buf, 1, '|', sizeof thisdata); Put(keys, thiskey, len, strdup(thisdata), NULL); } /* Check to see if this is a correct response. * Start with verified=1 but then set it to 0 if anything looks wrong. */ oiddata->verified = 1; char *openid_ns = NULL; if ( (!GetHash(keys, "ns", 2, (void *) &openid_ns)) || (strcasecmp(openid_ns, "http://specs.openid.net/auth/2.0")) ) { syslog(LOG_DEBUG, "This is not an an OpenID assertion"); oiddata->verified = 0; } char *openid_mode = NULL; if ( (!GetHash(keys, "mode", 4, (void *) &openid_mode)) || (strcasecmp(openid_mode, "id_res")) ) { oiddata->verified = 0; } char *openid_claimed_id = NULL; if (GetHash(keys, "claimed_id", 10, (void *) &openid_claimed_id)) { FreeStrBuf(&oiddata->claimed_id); oiddata->claimed_id = NewStrBufPlain(openid_claimed_id, -1); syslog(LOG_DEBUG, "Provider is asserting the Claimed ID '%s'", ChrPtr(oiddata->claimed_id)); } /* Validate the assertion against the server */ syslog(LOG_DEBUG, "Validating..."); CURL *curl; CURLcode res; struct curl_httppost *formpost = NULL; struct curl_httppost *lastptr = NULL; char errmsg[1024] = ""; StrBuf *ReplyBuf = NewStrBuf(); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, "openid.mode", CURLFORM_COPYCONTENTS, "check_authentication", CURLFORM_END ); HashPos *HashPos = GetNewHashPos(keys, 0); while (GetNextHashPos(keys, HashPos, &len, &Key, &Value) != 0) { if (strcasecmp(Key, "mode")) { char k_o_keyname[1024]; snprintf(k_o_keyname, sizeof k_o_keyname, "openid.%s", (const char *)Key); curl_formadd(&formpost, &lastptr, CURLFORM_COPYNAME, k_o_keyname, CURLFORM_COPYCONTENTS, (char *)Value, CURLFORM_END ); } } DeleteHashPos(&HashPos); curl = ctdl_openid_curl_easy_init(errmsg); curl_easy_setopt(curl, CURLOPT_URL, ChrPtr(oiddata->op_url)); curl_easy_setopt(curl, CURLOPT_WRITEDATA, ReplyBuf); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlFillStrBuf_callback); curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); res = curl_easy_perform(curl); if (res) { syslog(LOG_DEBUG, "cmd_oidf() libcurl error %d: %s", res, errmsg); oiddata->verified = 0; } curl_easy_cleanup(curl); curl_formfree(formpost); /* syslog(LOG_DEBUG, "Validation reply: \n%s", ChrPtr(ReplyBuf)); */ if (cbmstrcasestr(ChrPtr(ReplyBuf), "is_valid:true") == NULL) { oiddata->verified = 0; } FreeStrBuf(&ReplyBuf); syslog(LOG_DEBUG, "OpenID authentication %s", (oiddata->verified ? "succeeded" : "failed") ); /* Respond to the client */ if (oiddata->verified) { /* If we were already logged in, attach the OpenID to the user's account */ if (CC->logged_in) { if (attach_openid(&CC->user, oiddata->claimed_id) == 0) { cprintf("attach\n"); syslog(LOG_DEBUG, "OpenID attach succeeded"); } else { cprintf("fail\n"); syslog(LOG_DEBUG, "OpenID attach failed"); } } /* Otherwise, a user is attempting to log in using the verified OpenID */ else { /* * Existing user who has claimed this OpenID? * * Note: if you think that sending the password back over the wire is insecure, * check your assumptions. If someone has successfully asserted an OpenID that * is associated with the account, they already have password equivalency and can * login, so they could just as easily change the password, etc. */ if (login_via_openid(oiddata->claimed_id) == 0) { cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password); logged_in_response(); syslog(LOG_DEBUG, "Logged in using previously claimed OpenID"); } /* * If this system does not allow self-service new user registration, the * remaining modes do not apply, so fail here and now. */ else if (CtdlGetConfigInt("c_disable_newu")) { cprintf("fail\n"); syslog(LOG_DEBUG, "Creating user failed due to local policy"); } /* * New user whose OpenID is verified and Attribute Exchange gave us a name? */ else if (openid_create_user_via_ax(oiddata->claimed_id, keys) == 0) { cprintf("authenticate\n%s\n%s\n", CC->user.fullname, CC->user.password); logged_in_response(); syslog(LOG_DEBUG, "Successfully auto-created new user"); } /* * OpenID is verified, but the desired username either was not specified or * conflicts with an existing user. Manual account creation is required. */ else { char *desired_name = NULL; cprintf("verify_only\n"); cprintf("%s\n", ChrPtr(oiddata->claimed_id)); if (GetHash(keys, "sreg.nickname", 13, (void *) &desired_name)) { cprintf("%s\n", desired_name); } else { cprintf("\n"); } syslog(LOG_DEBUG, "The desired display name is already taken."); } } } else { cprintf("fail\n"); } cprintf("000\n"); if (oiddata->sreg_keys != NULL) { DeleteHash(&oiddata->sreg_keys); oiddata->sreg_keys = NULL; } oiddata->sreg_keys = keys; }
int FileHashChanged(EvalContext *ctx, char *filename, unsigned char digest[EVP_MAX_MD_SIZE + 1], HashMethod type, Attributes attr, Promise *pp) { int i, size = 21; unsigned char dbdigest[EVP_MAX_MD_SIZE + 1]; CF_DB *dbp; char buffer[EVP_MAX_MD_SIZE * 4]; CfDebug("HashChanged: key %s (type=%d) with data %s\n", filename, type, HashPrintSafe(type, digest, buffer)); size = FileHashSize(type); if (!OpenDB(&dbp, dbid_checksums)) { cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, attr, "Unable to open the hash database!"); return false; } if (ReadHash(dbp, type, filename, dbdigest)) { for (i = 0; i < size; i++) { if (digest[i] != dbdigest[i]) { CfDebug("Found cryptohash for %s in database but it didn't match\n", filename); CfOut(OUTPUT_LEVEL_ERROR, "", "ALERT: Hash (%s) for %s changed!", FileHashName(type), filename); if (pp->comment) { CfOut(OUTPUT_LEVEL_ERROR, "", "Preceding promise: %s", pp->comment); } if (attr.change.update) { cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_CHANGE, "", pp, attr, " -> Updating hash for %s to %s", filename, HashPrintSafe(type, digest, buffer)); DeleteHash(dbp, type, filename); WriteHash(dbp, type, filename, digest); } else { cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_FAIL, "", pp, attr, "!! Hash for file \"%s\" changed", filename); } CloseDB(dbp); return true; } } cfPS(ctx, OUTPUT_LEVEL_VERBOSE, PROMISE_RESULT_NOOP, "", pp, attr, " -> File hash for %s is correct", filename); CloseDB(dbp); return false; } else { /* Key was not found, so install it */ cfPS(ctx, OUTPUT_LEVEL_ERROR, PROMISE_RESULT_CHANGE, "", pp, attr, " !! File %s was not in %s database - new file found", filename, FileHashName(type)); CfDebug("Storing checksum for %s in database %s\n", filename, HashPrintSafe(type, digest, buffer)); WriteHash(dbp, type, filename, digest); LogHashChange(filename, FILE_STATE_NEW, "New file found", pp); CloseDB(dbp); return false; } }