passwd_entry *find_passwd_entry(const char *username) { int u; for(u=0; u<passwd_list_size; u++) if(passwd_list[u].username && !usercmp(passwd_list[u].username,username)) return passwd_list+u; return NULL; }
/** * This is our callback for the receiving-im-msg signal. * * We return TRUE to block the IM, FALSE to accept the IM */ static gboolean receiving_im_msg_cb(GaimAccount * account, char **sender, char **buffer, int *flags, void *data) { gboolean retval = FALSE; /* assume the sender is allowed */ gboolean found = FALSE; gint pos = -1; char *botmsg = NULL; PendingMessage *pending = NULL; GSList *slist = NULL; GSList *search = NULL; GaimConnection *connection = NULL; /* expire any old entries in pending */ expire_pending_list(); connection = gaim_account_get_connection(account); /* not good, but don't do anything */ if (!connection || !sender) { return retval; } /* if there is already an open conversation, allowed it */ if (gaim_find_conversation_with_account(*sender, account)) { return retval; } /* don't make buddies use the challenge/response system */ if (gaim_find_buddy(account, *sender)) { return retval; } /* don't make permit list members use the challenge/response system */ for (slist = account->permit; slist != NULL; slist = slist->next) { if (!gaim_utf8_strcasecmp (*sender, gaim_normalize(account, (char *) slist->data))) { return retval; } } /* if there is no question or no answer, allow the sender */ const char *question = gaim_prefs_get_string("/plugins/core/bot/challenger/question"); const char *answer = gaim_prefs_get_string("/plugins/core/bot/challenger/answer"); if (!question || !answer) { return retval; } /* blank / null message ... can this even happen? */ if (!*buffer) { return retval; } /* search if this sender is already in pending */ for (search = pending_list; search; search = search->next) { pending = search->data; pos = g_slist_position(pending_list, search); if (protocmp(account, pending) && usercmp(account, pending) && sendercmp(*sender, pending)) { found = TRUE; break; } } if (!found) { /** * its the first time through, save the nick/msg to the * queue and ask the question */ GTimeVal *now = NULL; now = g_new0(GTimeVal, 1); g_get_current_time(now); PendingMessage *newpend = NULL; newpend = g_new0(PendingMessage, 1); newpend->tv_sec = now->tv_sec; newpend->protocol = g_strdup(account->protocol_id); newpend->username = g_strdup(account->username); newpend->sender = g_strdup(*sender); newpend->message = g_strdup(*buffer); pending_list = g_slist_append(pending_list, newpend); botmsg = g_strdup_printf(_ ("Bot Challenger engaged: you are now being ignored! Your message will be delivered if you can correctly answer the following question within %i minutes: %s"), BOT_MAX_MINUTES, question); send_auto_reply(account, *sender, botmsg); g_free(now); g_free(botmsg); retval = TRUE; } else { if (gaim_utf8_strcasecmp(*buffer, answer)) { /** * Sorry, thanks for playing, please try again */ retval = TRUE; } else { botmsg = _ ("Bot Challenger accepted your answer and delivered your original message. You may now speak freely."); send_auto_reply(account, *sender, botmsg); if (gaim_prefs_get_bool ("/plugins/core/bot/challenger/auto_add_permit")) { if (!gaim_privacy_permit_add(account, *sender, FALSE)) { gaim_debug_info("bot-challenger", "Unable to add %s/%s/%s to permit list\n", *sender, pending->username, pending->protocol); } } /** * Free what is currently in the buffer (the correct answer) * and replace it with the user's first message that was * queued, pending the correct answer. I think some other * process is supposed to free the buffer after its sent. */ g_free(*buffer); *buffer = pending->message; /* Clean up everything else except pending->message */ free_pending(search, FALSE); retval = FALSE; /* Don't block this message */ } } debug_pending_list(); return retval; /* returning TRUE will block the IM */ }
static void set_acl(CXmlNodePtr base) { CXmlNodePtr acl, acl_to_set = NULL; acl = fileattr_find(base,"acl"); while(acl) { const char *user = fileattr_getvalue(acl,"@user"); const char *branch = fileattr_getvalue(acl,"@branch"); const char *merge = fileattr_getvalue(acl,"@merge"); if(((!user && !parms.user) || (user && parms.user && !usercmp(user,parms.user))) && ((!branch && !parms.branch) || (branch && parms.branch && !strcmp(branch,parms.branch))) && ((!merge && !parms.merge) || (merge && parms.merge && !strcmp(merge,parms.merge)))) { acl_to_set = acl; break; } acl = fileattr_next(acl); } if(acl_to_set) fileattr_batch_delete(acl_to_set); if(!parms.del) { char *parm = xstrdup(parms.access); char *acc = parm?strtok(parm,","):NULL; base->NewNode("acl"); fileattr_modified(); if(parms.user) base->NewAttribute("user",parms.user); if(parms.branch) base->NewAttribute("branch",parms.branch); if(parms.merge) base->NewAttribute("merge",parms.merge); if(parms.priority && atoi(parms.priority)) base->NewAttribute("priority",parms.priority); if(parms.message) base->NewNode("message",parms.message,false); base->NewNode("modified_by",getcaller(),false); base->NewNode("modified_date",current_date,false); while(acc) { int deny=0; if(!strncmp(acc,"no",2) && strcmp(acc,"none")) { deny=1; acc+=2; } if(!strcmp(acc,"all")) set_attrs(base,"all",deny,parms.noinherit); else if(!strcmp(acc,"none")) set_attrs(base,"all",!deny,parms.noinherit); else if(!strcmp(acc,"read")) set_attrs(base,"read",deny,parms.noinherit); else if(!strcmp(acc,"write")) set_attrs(base,"write",deny,parms.noinherit); else if(!strcmp(acc,"create")) set_attrs(base,"create",deny,parms.noinherit); else if(!strcmp(acc,"tag")) set_attrs(base,"tag",deny,parms.noinherit); else if(!strcmp(acc,"control")) set_attrs(base,"control",deny,parms.noinherit); else error(1,0,"Invalid access control attribute '%s'",acc); acc = strtok(NULL,","); } base->GetParent(); fileattr_prune(base); xfree(parm); } else { if(acl_to_set) fileattr_prune(acl_to_set); } }