/** @brief create a thread result must be unreferenced * * @note If the manager thread has not yet started this will start the manager thread. * @warning @ref THREAD_OPTION_RETURN flag controls the return of this function. * @warning Threads should periodically check the result of framework_threadok() and cleanup or use @ref THREAD_OPTION_CANCEL * @param func Function to run thread on. * @param cleanup Cleanup function to run. * @param sig_handler Thread signal handler. * @param data Data to pass to callbacks. * @param flags Options of @ref thread_option_flags passed * @returns a thread structure that must be un referencend OR NULL depending on flags.*/ extern struct thread_pvt *framework_mkthread(threadfunc func, threadcleanup cleanup, threadsighandler sig_handler, void *data, int flags) { struct thread_pvt *thread; struct threadcontainer *tc = NULL; /*Grab a reference for threads in this scope start up if we can*/ if (!(tc = (objref(threads)) ? threads : NULL)) { if (!thread_can_start) { return NULL; } else if (!startthreads()) { return NULL; } if (!(tc = (objref(threads)) ? threads : NULL)) { return NULL; } } objlock(tc); /* dont allow threads if no manager or it not started*/ if ((!tc->manager || !func) && (func != managethread)) { /*im shuting down*/ objunlock(tc); objunref(tc); return NULL; } else if (!(thread = objalloc(sizeof(*thread), free_thread))) { /* could not create*/ objunlock(tc); objunref(tc); return NULL; } thread->data = (objref(data)) ? data : NULL; thread->flags = flags << 16; thread->cleanup = cleanup; thread->sighandler = sig_handler; thread->func = func; objunlock(tc); /* start thread and check it*/ if (pthread_create(&thread->thr, NULL, threadwrap, thread) || pthread_kill(thread->thr, 0)) { objunref(thread); objunref(tc); return NULL; } /*Activate the thread it needs to be flaged to run or it will die*/ objlock(tc); addtobucket(tc->list, thread); setflag(thread, TL_THREAD_RUN); objunlock(tc); objunref(tc); if (testflag(thread, TL_THREAD_RETURN)) { return thread; } else { objunref(thread); return NULL; } }
DTSAPPToolBar::DTSAPPToolBar(struct dtsgui *dtsgui, wxWindow *parent, long style, wxWindowID id, wxString name, void *data) { int servid; if (dtsgui && objref(dtsgui)) { this->dtsgui = (struct dtsgui*)dtsgui; } else { this->dtsgui = NULL; } itemid = wxID_AUTO_LOWEST; Create(parent, id, wxDefaultPosition, wxDefaultSize, style, name); proto = new wxComboBox(this, itemid++, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxCB_READONLY); servid = itemid++; server = new DTSXMLComboBox(this, servid, "https://sip1.speakezi.co.za:666/auth/test.php", "/servers/Server", &DTSAPPToolBar::GetPostInfo, 3); server->SetSize(wxSize(300,-1)); wxStaticText *text2 = new wxStaticText(this, wxID_ANY, "://"); wxStaticText *text = new wxStaticText(this, wxID_ANY, "Server "); AddControl(text); proto->Append("http"); proto->Append("https"); proto->Append("https [:666]"); proto->SetSelection(2); AddControl(proto); AddControl(text2); AddControl(server); AddStretchableSpace(); Bind(wxEVT_TEXT_ENTER, &DTSAPPToolBar::HandleEvent, this, servid, servid, NULL); Bind(wxEVT_COMBOBOX, &DTSAPPToolBar::HandleEvent, this, servid, servid, NULL); Bind(wxEVT_COMBOBOX_DROPDOWN, &DTSAPPToolBar::HandleEvent, this, servid, servid, NULL); }
/** @brief Initialise the threadlist and start manager thread * * @note There is no need to call this as it will start when first thread starts. * @returns 1 On success 0 on failure.*/ extern int startthreads(void) { struct threadcontainer *tc; tc = (objref(threads)) ? threads : NULL; if (tc) { objunref(tc); return 1; } if (!(tc = objalloc(sizeof(*threads), close_threads))) { return 0; } if (!tc->list && !(tc->list = create_bucketlist(4, hash_thread))) { objunref(tc); return 0; } threads = tc; if (!(tc->manager = framework_mkthread(managethread, manage_clean, manager_sig, NULL, THREAD_OPTION_JOINABLE | THREAD_OPTION_RETURN))) { objunref(tc); return 0; } return 1; }
static void *threadwrap(void *data) { struct thread_pvt *thread = data; void *ret = NULL; int cnt; objref(thread); for(cnt = 0;!testflag(thread, TL_THREAD_RUN) && (cnt < 100); cnt++) { usleep(1000); } if (cnt == 100) { return NULL; } pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); if (!testflag(thread, TL_THREAD_CAN_CANCEL)) { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); } if (!testflag(thread, TL_THREAD_JOINABLE)) { pthread_detach(thread->thr); } pthread_cleanup_push(thread_cleanup, thread); ret = thread->func(thread->data); pthread_cleanup_pop(1); return (ret); }
/** @brief Bind to the connection with simple bind requireing a distingushed name and password. * @param ld LDAP connection to bind to. * @param dn Distinguished name to bind with. * @param passwd Password for dn. * @returns -1 on error.*/ extern int ldap_simplebind(struct ldap_conn *ld, const char *dn, const char *passwd) { struct ldap_simple *simple; struct berval *cred; int res, len = 0; if (!objref(ld)) { return LDAP_UNAVAILABLE; } if (passwd) { len = strlen(passwd); } simple = objalloc(sizeof(*simple), free_simple); cred = calloc(sizeof(*cred), 1); cred->bv_val = malloc(len); memcpy(cred->bv_val, passwd, len); cred->bv_len=len; simple->cred = cred; simple->dn = strdup(dn); objlock(ld); if (ld->simple) { objunref(ld->simple); } ld->simple = simple; res = ldap_sasl_bind_s(ld->ldap, simple->dn, LDAP_SASL_SIMPLE, simple->cred, ld->sctrlsp, NULL, NULL); objunlock(ld); objunref(ld); return res; }
ObjectTree::ObjectTree(QWidget *parent) : QVBox(parent) { copying = false; cutting = false; referencing = false; list = new ObjectListView(this); list->addColumn("Objects"); list->addColumn("Value"); list->addColumn("Def"); list->setRootIsDecorated(true); list->setItemMargin(3); list->setTreeStepSize(15); list->setAcceptDrops(true); menu = new QMenu(list); menu->addAction(QIcon(QPixmap("icons/add.png")), "Add", this, SLOT(addAttribute())); menu->addAction(QIcon(QPixmap("icons/remove.png")), "Delete", this, SLOT(deleteObject())); menu->addAction(QIcon(QPixmap("icons/object.png")), "View", this, SLOT(viewObject())); menu->addAction(QIcon(QPixmap("icons/filesaveobj.png")), "Save...", this, SLOT(saveObject())); menu->addSeparator(); menu->addAction(QIcon(QPixmap("icons/editcut.png")), "Cut", this, SLOT(objcut())); menu->addAction(QIcon(QPixmap("icons/editcopy.png")), "Copy", this, SLOT(objcopy())); menu->addAction(QIcon(QPixmap("icons/definition.png")), "Reference", this, SLOT(objref())); menu->addSeparator(); menu->addAction(QIcon(QPixmap("icons/trace.png")), "Trace", this, SLOT(traceObject())); menu->addAction(QIcon(QPixmap("icons/monitor.png")), "Monitor"); menu->addAction(QIcon(QPixmap("icons/edit.png")), "Edit", this, SLOT(editObject())); icon_array = new QPixmap[NUM_OBJTYPES]; for (int i=0; i<NUM_OBJTYPES; i++) { icon_array[i] = QPixmap(icon_files[i]); } icon_def = new QPixmap(icon_deffile); new ObjectItem(list, Null, Null, core::root, "root", false); //new ObjectItem(list, Null, Null, doste::Current, "current", false); //aname = new AttribNameDialog(); connect(list, SIGNAL(expanded(QTreeWidgetItem*)), this, SLOT(expanded(QTreeWidgetItem*))); connect(list, SIGNAL(collapsed(QTreeWidgetItem*)), this, SLOT(collapsed(QTreeWidgetItem*))); connect(list, SIGNAL(itemRenamed(QTreeWidgetItem *, int, const QString&)), this, SLOT(itemRenamed(QTreeWidgetItem*, int, const QString&))); connect(list, SIGNAL(rightButtonClicked(QTreeWidgetItem *, const QPoint&, int)), this, SLOT(rightButtonClicked(QTreeWidgetItem*, const QPoint&, int))); connect(list, SIGNAL(onItem(QTreeWidgetItem*)), this, SLOT(onItem(QTreeWidgetItem*))); connect(list, SIGNAL(clicked(QTreeWidgetItem*)), this, SLOT(itemClicked(QTreeWidgetItem*))); }
/** @brief Bind to the server with SASL * @param ld Reference to LDAP connection. * @param mech SASL mechanisim. * @param realm SASL realm. * @param authcid SASL auth id. * @param passwd Password for authid. * @param authzid Proxy authid. * @returns -1 on error.*/ extern int ldap_saslbind(struct ldap_conn *ld, const char *mech, const char *realm, const char *authcid, const char *passwd, const char *authzid ) { struct sasl_defaults *sasl; int res, sasl_flags = LDAP_SASL_AUTOMATIC | LDAP_SASL_QUIET; if (!objref(ld)) { return LDAP_UNAVAILABLE; } if (!(sasl = objalloc(sizeof(*sasl), free_sasl))) { return LDAP_NO_MEMORY; } ALLOC_CONST(sasl->passwd, passwd); if (mech) { ALLOC_CONST(sasl->mech, mech); } else { ldap_get_option(ld->ldap, LDAP_OPT_X_SASL_MECH, &sasl->mech); } if (realm) { ALLOC_CONST(sasl->realm, realm); } else { ldap_get_option(ld->ldap, LDAP_OPT_X_SASL_REALM, &sasl->realm ); } if (authcid) { ALLOC_CONST(sasl->authcid, authcid); } else { ldap_get_option(ld->ldap, LDAP_OPT_X_SASL_AUTHCID, &sasl->authcid ); } if (authzid) { ALLOC_CONST(sasl->authzid, authzid); } else { ldap_get_option(ld->ldap, LDAP_OPT_X_SASL_AUTHZID, &sasl->authzid ); } objlock(ld); if (ld->sasl) { objunref(ld->sasl); } ld->sasl = sasl; res = ldap_sasl_interactive_bind_s(ld->ldap, NULL, sasl->mech, ld->sctrlsp , NULL, sasl_flags, dts_sasl_interact, sasl); objunlock(ld); objunref(ld); return res; }
static struct thread_pvt *get_thread_from_id() { struct thread_pvt *thr; struct threadcontainer *tc; pthread_t me; if (!(tc = (objref(threads)) ? threads : NULL)) { return NULL; } me = pthread_self(); objlock(tc); thr = bucket_list_find_key(tc->list, &me); objunlock(tc); objunref(tc); return thr; }
/** @brief Join the manager thread. * * This will be done when you have issued stopthreads and are waiting or have completed the program and want to let the threads continue. * for threads to exit.*/ extern void jointhreads(void) { struct threadcontainer *tc; tc = (objref(threads)) ? threads : NULL; if (!tc) { return; } objlock(tc); if (tc->manager) { setflag(tc->manager, TL_THREAD_JOIN); objunlock(tc); pthread_join(tc->manager->thr, NULL); } else { objunlock(tc); } objunref(tc); }
static int ldap_rebind_proc(LDAP *ld, LDAP_CONST char *url, ber_tag_t request, ber_int_t msgid, void *params) { struct ldap_conn *ldap = params; int res = LDAP_UNAVAILABLE; if (!objref(ldap)) { return LDAP_UNAVAILABLE; } if (ldap->sasl) { int sasl_flags = LDAP_SASL_AUTOMATIC | LDAP_SASL_QUIET; struct sasl_defaults *sasl = ldap->sasl; res = ldap_sasl_interactive_bind_s(ld, NULL, sasl->mech, ldap->sctrlsp , NULL, sasl_flags, dts_sasl_interact, sasl); } else if (ldap->simple) { struct ldap_simple *simple = ldap->simple; res = ldap_sasl_bind_s(ld, simple->dn, LDAP_SASL_SIMPLE, simple->cred, ldap->sctrlsp, NULL, NULL); } objunref(ldap); return res; }
/** @brief Bind to LDAP connection using rebind. * * Bind to a connection with a lower privlidge distingushed name and password search for a user dn, * bind to the connection with the retrieved dn and user password. * @param ldap LDAP connection to bind too. * @param initialdn Initial dn to bind with. * @param initialpw Password for the initial dn. * @param base Search base to find user. * @param filter LDAP filter to apply to find user. * @param uidrdn Attribute containing user id. * @param uid To search and bind as. * @param passwd Password for the user id. * @returns -1 on error.*/ extern int ldap_simplerebind(struct ldap_conn *ldap, const char *initialdn, const char *initialpw, const char *base, const char *filter, const char *uidrdn, const char *uid, const char *passwd) { int res, flen; struct ldap_results *results; const char *sfilt; if (!objref(ldap)) { return LDAP_UNAVAILABLE; } if ((res = ldap_simplebind(ldap, initialdn, initialpw))) { objunref(ldap); return res; } flen=strlen(uidrdn) + strlen(filter) + strlen(uid) + 7; sfilt = malloc(flen); snprintf((char *)sfilt, flen, "(&(%s=%s)%s)", uidrdn, uid, filter); if (!(results = ldap_search_sub(ldap, base, sfilt, 0, &res, uidrdn, NULL))) { free((void *)sfilt); objunref(ldap); return res; } free((void *)sfilt); if (results->count != 1) { objunref(results); objunref(ldap); return LDAP_INAPPROPRIATE_AUTH; } res = ldap_simplebind(ldap, results->first_entry->dn, passwd); objunref(ldap); objunref(results); return res; }