Ejemplo n.º 1
0
Archivo: plt.c Proyecto: dwks/asyncsafe
static void reset_plt_entries(elf_t *elf) {
    Elf64_Rela *data = elf->map + elf->rela_plt->sh_offset;
    for(size_t i = 0; i < plt_count; i ++) {
        Elf64_Rela *r = &data[i];
        unsigned long address   = base_address + r->r_offset;
        unsigned long type      = ELF64_R_TYPE(r->r_info);
        unsigned long symbol    = ELF64_R_SYM(r->r_info);

        // every relocation in .rela.plt should have this type, but double-check
        if(type != R_X86_64_JUMP_SLOT) continue;

        Elf64_Sym *symtab = (Elf64_Sym *)(elf->map + elf->dynsym->sh_offset);
        Elf64_Sym *sym = symtab + symbol;
        const char *name = elf->dynstr + sym->st_name;

        int good = is_allowed(name);

        printf("%s plt entry at %lx (index %lu) for [%s]\n",
            good ? "allow" : "BLOCK", address, symbol, name);

        plt_symbol[i] = sym;
        plt_allowed[i] = good;
        if(!good) {
            plt_orig_address[i] = *(unsigned long *)address;
            *(unsigned long *)address = elf->plt + 16*(i+1) + 6;
        }
    }
}
Ejemplo n.º 2
0
bool js_leave_test(Room *room, Character *actor, int dir, JSBindable *self=0)
{
	std::shared_ptr< std::vector<JSTrigger*> > js_scripts;
	if( self ) {
		if (!self->js_scripts || self->js_scripts->size() == 0)
			return true;
		js_scripts = self->js_scripts;
	}
	else
		js_scripts = globalJS_Scripts;
	for (int i = 0; i < js_scripts->size(); ++i)
	{
		// this looks for scripts that _might_ match
		if (js_scripts->at(i)->isFlagged(JS::LEAVE))
		{
			JSTrigger* trig = js_scripts->at(i);

			if ( (!self || is_allowed(self, actor, trig)) && randomly_triggered(trig->narg))
			{
				int ret_val = JSManager::get()->execute(trig, self, actor, "", make_extra("direction", dir), room);
				if (!ret_val) // ret_val == 0 means we block them.
					return false;
			}
		}
	}
	return true;
}
Ejemplo n.º 3
0
int main() {
    int t;
    int i = 0;
    scanf ("%d", &t);
    int n;
    int time ;
    int student [t][1000] ;
    int k[t] ;
    int j;
    for (i = 0; i < t ;i++){
        scanf ("%d", &n);
        scanf ("%d", &k[i]);
        for (j = 0; j< n; j++)
            scanf ("%d", &student [i][j]);
    }
    for (i = 0; i < t ;i++){
        if (is_allowed (student [i], k[i], n)){
            printf ("%s\n", "YES");
        } else {
            printf ("%s\n", "NO");
        }
    }


    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    return 0;
}
Ejemplo n.º 4
0
static void
received_chat_msg_cb(PurpleAccount *account, char *sender, char *buffer,
					 PurpleConversation *chat, PurpleMessageFlags flags, void *data)
{
	gboolean on_focus;
	char *message, *notification;
	int len;
	
	DEBUG_MSG("received_chat_msg_cb\n");
		
	g_return_if_fail( is_allowed(account) );
		
	on_focus = purple_prefs_get_bool("/plugins/core/pidgin-gntp/on_focus");
	if(chat != NULL && !on_focus && chat->ui_ops->has_focus(chat))
		return;
		
	// copy string to temporary variable)
	message = malloc(s_strlen(buffer)+1);
	strcpy(message, buffer);
	special_entries(message);
	strip_tags(message);
	
	len = s_strlen(sender) + s_strlen(message) + 3;
	// message
	notification = malloc( len );
	g_snprintf(notification, len, "%s: %s", sender, message);
	
	gntp_notify("chat-msg-received", NULL, "Chat Message", notification, NULL);
	
	free(message);
	free(notification);
}
Ejemplo n.º 5
0
static void
buddy_signed_off_cb(PurpleBuddy *buddy, void *data)
{
	int len;
	char* buddy_nick, *buddy_name, *icon_path, *growl_msg;
	PurpleBuddyIcon* icon;

	DEBUG_MSG("buddy_signed_off_cb\n");
	
	g_return_if_fail( buddy != NULL );	
	g_return_if_fail( is_allowed(purple_buddy_get_account(buddy)) );
		
	buddy_nick = (char*)purple_buddy_get_alias(buddy);
	buddy_name = (char*)purple_buddy_get_name(buddy);
	icon = purple_buddy_get_icon(buddy);
	icon_path = (char*)purple_buddy_icon_get_full_path(icon);
		
	len = s_strlen(buddy_nick) + s_strlen(buddy_name) + 2;
	
	growl_msg = malloc( len );
	
	g_snprintf(growl_msg, len, "%s\n%s", buddy_nick, buddy_name );
	gntp_notify("buddy-sign-out", icon_path, "Signed Off", growl_msg, NULL);
	
	free(growl_msg);
}
Ejemplo n.º 6
0
int
main(int argc, char **argv)
{
    struct passwd *pass = NULL;
    char *cur_user = NULL;

    rootuid = get_user_uid_safe(ROOTNAME);
    rootgid = get_group_gid_safe(ROOTGROUP);

    if (strrchr(argv[0], '/') == NULL)
        prog_name = argv[0];
    else
        prog_name = strrchr(argv[0], '/') + 1;

    fcrontab_uid = get_user_uid_safe(USERNAME);

#ifdef USE_SETE_ID
    /* get user's permissions */
    if (seteuid(fcrontab_uid) != 0)
        die_e("Could not change euid to " USERNAME "[%d]", uid);
#endif                          /* USE_SETE_ID */

    if (argc == 2)
        fcronconf = argv[1];
    else if (argc > 2)
        usage();

    /* read fcron.conf and update global parameters */
    /* We deactivate output to console, because otherwise it may be used
     * by a malicious user to read some data it is not allow to read
     * (fcronsighup is suid root) */
    foreground = 0;
    read_conf();
    foreground = 1;

    uid = getuid();

    /* check if user is allowed to use this program */
    if (!(pass = getpwuid(uid)))
        die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
    cur_user = strdup2(pass->pw_name);

    if (is_allowed(cur_user)) {
        /* check if daemon is running */
        if ((daemon_pid = read_pid()) != 0)
            sig_daemon();
        else
            fprintf(stderr, "fcron is not running :\n  modifications will"
                    " be taken into account at its next execution.\n");
    }
    else
        die("User \"%s\" is not allowed to use %s. Aborting.", cur_user,
            prog_name);

    if (cur_user)
        free(cur_user);
    return EXIT_OK;

}
MODRET lmd_deny_blacklist_post_pass(cmd_rec *cmd) {
    /*
      mod_authを通過するまでは session.userは空の様子
      const char *account  = session.user;
    */
    const char *account   = NULL;
    const char *remote_ip = NULL;

    /* return IP unless found hostname */
    account = get_param_ptr(cmd->server->conf, "UserName", FALSE);
    remote_ip = pr_netaddr_get_ipstr(pr_netaddr_get_sess_remote_addr());

    if(false == is_set_server) {
        pr_log_auth(PR_LOG_WARNING, "%s: memcached_server not set", MODULE_NAME);
        lmd_cleanup();
        return PR_DECLINED(cmd);
    }

    if(is_allowed_user(cmd, account) == true) {
        pr_log_auth(PR_LOG_NOTICE,
           "%s: '%s' is allowed to login. skip last process", MODULE_NAME, account);
        lmd_cleanup();
        return PR_DECLINED(cmd);
    }

    /* allow explicily */
    if(is_allowed(cmd, session.c->remote_addr) == true) {
        return PR_DECLINED(cmd);
    }

    /* check whether account is registerd in blacklist or not */
    if(is_cache_exits(memcached_deny_blacklist_mmc, account) == true) {
        pr_log_auth(PR_LOG_NOTICE,
            "%s: denied '%s@%s'. Account found in blacklist(memcached)",
                 MODULE_NAME, account, remote_ip);
        pr_response_send(R_530, _("Login denied temporary (Account found in blacklist)"));
        end_login(0);
    }

    /* check whether remote IP is registerd in blacklist or not */
    if(is_cache_exits(memcached_deny_blacklist_mmc, remote_ip) == true) {
        pr_log_auth(PR_LOG_NOTICE,
            "%s: denied '%s@%s'. IP found in blacklist(memcached)",
                 MODULE_NAME, account, remote_ip);
        pr_response_send(R_530, _("Login denied temporary (IP found in blacklist)"));
        end_login(0);
    }

    pr_log_debug(DEBUG2,
            "%s: not found in blaclist. '%s@%s' is allowed to Login",
                 MODULE_NAME, account, remote_ip);

    lmd_cleanup();
    return PR_DECLINED(cmd);
}
Ejemplo n.º 8
0
void dumb_fill(cell_t **battlefield, size_t board_len){
    srand(time(NULL));
    int max_iter= 1000000;
    while(obeys_limits(battlefield, board_len) && max_iter > 0){
        int x = rand() % board_len;
        int y = rand() % board_len;
        if (is_allowed(y, x, battlefield, board_len) &&try_obeys(y,x, battlefield, board_len)){
            start_replace(y, x, battlefield, board_len);
        }
        max_iter-=1;
    }
}
Ejemplo n.º 9
0
struct hostent *gethostbyname2(const char *name, int af)
{
	init();
	static void * (*func)();
	if (!func)
		func = (void *(*)()) dlsym(RTLD_NEXT, "gethostbyname2");

	if (!is_allowed(name))
		return &invalid_host;

	return func(name, af);
}
Ejemplo n.º 10
0
static void
buddy_icon_changed_cb(PurpleBuddy *buddy)
{	
	PurpleBuddyIcon* icon;
	int len;
	char *icon_path, *buddy_nick, *buddy_name, *growl_msg;
	
	DEBUG_MSG("buddy_icon_changed_cb\n");
	
	g_return_if_fail( buddy != NULL );

	buddy_nick = (char*)purple_buddy_get_alias(buddy);
	buddy_name = (char*)purple_buddy_get_name(buddy);
	icon = purple_buddy_get_icon(buddy);
	icon_path = (char*)purple_buddy_icon_get_full_path(icon);
	
	if(buddy_nick == NULL)
		DEBUG_MSG("buddy_nick is NULL\n");
	if(buddy_name == NULL)
		DEBUG_MSG("buddy_name is NULL\n");	
	if(icon == NULL)
		DEBUG_MSG("icon is NULL\n");	
	if(icon_path == NULL)
		DEBUG_MSG("icon_path is NULL\n");	
	
	if(icon_path != NULL)
	{
		if(g_list_find_custom(img_list, icon_path, (GCompareFunc)strcmp))
		{
			DEBUG_MSG("icon_path found in list - leaving function\n");
			return;
		}
		img_list = g_list_prepend(img_list, icon_path);
		
		if(g_list_find_custom(img_list, icon_path, (GCompareFunc)strcmp))
			DEBUG_MSG("icon_path added to list of known icons\n");
	}
		
	// is allowed?
	g_return_if_fail( is_allowed(purple_buddy_get_account(buddy)) );	
	//hack to hide spam when signing on to account
	g_return_if_fail( GetTickCount() - start_tick_image > 500 );
	
	len = s_strlen(buddy_nick) + s_strlen(buddy_name) + 2;
	growl_msg = malloc( len ); 
	g_snprintf(growl_msg, len, "%s\n%s", buddy_nick, buddy_name );
	
	gntp_notify("buddy-change-image", icon_path, "Changed Image", growl_msg, NULL);
	free(growl_msg);
}
Ejemplo n.º 11
0
void place(int y, int x, int y_offset, int x_offset, board_t* board){
    coords_t coords = translate_coords(y,x, y_offset, x_offset, board);
    if (coords.fits){
        cell_t **battlefield;
        if (coords.player_a){
            battlefield = board->player_a;
        } else{
            battlefield = board->player_b;
        }
        if (is_allowed(coords.y, coords.x, battlefield, board->length) && try_obeys(coords.y, coords.x,battlefield, board->length)){
            start_replace(coords.y, coords.x, battlefield, board->length);
        }
    }
}
Ejemplo n.º 12
0
int inet_pton(int af, const char *src, void *dst)
{
	init();
	static int (*func)();
	if (!func)
		func = (int (*)()) dlsym(RTLD_NEXT, "inet_pton");

	if (!is_allowed(src)) {
		dst = NULL;
		return 0;
	}

	return func(af, src, dst);
}
Ejemplo n.º 13
0
int getaddrinfo(const char *node, const char *service,
		const struct addrinfo *hints,
		struct addrinfo **res)
{
	init();
	static int (*func)();
	if (!func)
		func = (int (*)()) dlsym(RTLD_NEXT, "getaddrinfo");

	if (!is_allowed(node)) {
		res = NULL;
		return -EAI_FAIL;
	}
	return func(node, service, hints, res);
}
Ejemplo n.º 14
0
VectorXf PBSeqWeightEstimator::calc_residue_weight(const vector<string>& msa, const int& idx) const {
    VectorXf s = VectorXf::Zero(dim);  // number of times a particular residue appears
    char c;
    for (vector<string>::const_iterator pos = msa.begin(); pos != msa.end(); ++pos) {
        c = (*pos)[idx];
        if (is_allowed(c)) s(abc_idx(c)) += 1;
    }
    double r = (double) (s.array() > 0).count();    // number of different residues
    VectorXf wt(dim);
    for (int k = 0; k < dim; ++k) {
        if (s(k) > 0) wt(k) = 1. / (r * s(k));
        else wt(k) = 0;
    }
    return wt;
}
Ejemplo n.º 15
0
static void
received_im_msg_cb(PurpleAccount *account, char *sender, char *buffer,
				   PurpleConversation *conv, PurpleMessageFlags flags, void *data)
{	
	gboolean on_focus;
	char *message, *notification, *buddy_nick, *iconpath;
	PurpleBuddy* buddy;
	PurpleBuddyIcon* icon;
	int len;
	
	DEBUG_MSG("received_im_msg_cb\n");
		
	g_return_if_fail( is_allowed(account) );
		
	on_focus = purple_prefs_get_bool("/plugins/core/pidgin-gntp/on_focus");
	if(conv != NULL && !on_focus && conv->ui_ops->has_focus(conv))
		return;
	
	
	// copy string to temporary variable)
	message = malloc(s_strlen(buffer)+1);
	strcpy(message, buffer);
	special_entries(message);
	strip_tags(message);

	
	// nickname
	buddy = purple_find_buddy(account, sender);
	if(buddy == NULL)
		buddy_nick = sender;
	else
		buddy_nick = (char*)purple_buddy_get_alias( buddy );
	
	len = s_strlen(buddy_nick) + s_strlen(message) + 3;

	// message
	notification = malloc( len );
	g_snprintf(notification, len, "%s: %s", buddy_nick, message);
	
	// icon
	icon = purple_buddy_get_icon( buddy );
	iconpath = purple_buddy_icon_get_full_path( icon );
	
	gntp_notify("im-msg-received", iconpath, "IM Message", notification, NULL);
	
	free(message);
	free(notification);
}
Ejemplo n.º 16
0
int gethostent_r(
		struct hostent *ret, char *buf, size_t buflen,
		struct hostent **result, int *h_errnop)
{
	init();
	static int (*func)();
	if (!func)
		func = (int (*)()) dlsym(RTLD_NEXT, "gethostent_r");

	if (!is_allowed(buf)) {
		result = NULL;
		return -23;
	}

	return func(ret, buf, buflen, result, h_errnop);
}
Ejemplo n.º 17
0
void js_speech_test(Character *actor, const char *str, JSBindable *self=0 )
{
	std::shared_ptr<std::vector<JSTrigger*> > js_scripts;
	std::shared_ptr<std::vector<JSTrigger*> > js_scripts2;
	js_scripts=globalJS_Scripts;
	js_scripts2 = js_scripts;
	if( self ) {
		if (!self->js_scripts || self->js_scripts->size() == 0)
			return;
		js_scripts = self->js_scripts;
	}
	else
		js_scripts = globalJS_Scripts;
	for (int i = 0; i < js_scripts->size(); ++i)
	{
		// this looks for scripts that _might_ match
		if (js_scripts->at(i)->isFlagged(JS::SPEECH) && (!self || is_allowed(self, actor, js_scripts->at(i))))
		{
			// this looks for scripts that _do_ match
			JSTrigger* trig = js_scripts->at(i);
			int rval=0;
			switch (trig->narg)
			{
				case 2:  // exact match
					if (trig->args == str)
						rval = JSManager::get()->execute(trig, self, actor, str);
					break;
				case 1: // substring match
					if (word_check(str, trig->args.c_str()))
						rval = JSManager::get()->execute(trig, self, actor, str);
					break;
				case 0: // substring match
//					cout << str << ":::" << trig->args << endl;
//					cout << word_check(str, trig->args.c_str()) << endl;
					if (word_check(str, trig->args.c_str()))
					{
						rval = JSManager::get()->execute(trig, (Character*)self, actor, str);
					}
					break;
				default:
					MudLog(NRM, LVL_BUILDER, TRUE, "Error in script %d : Narg %d is not 0, 1, or 2", trig->vnum, trig->narg);
					break;
			}
			//if( rval == 0 ) return;
		}
	}
}
Ejemplo n.º 18
0
static void
chat_buddy_left_cb(PurpleConversation *conv, const char *user,
				   const char *reason, void *data)
{
	char *notification;
	int len = s_strlen((char*)conv->title)+s_strlen((char*)user) + 7;
	
	DEBUG_MSG("chat_buddy_left_cb\n");
	
	g_return_if_fail( is_allowed(purple_conversation_get_account(conv)) );
		
	notification = malloc( len );
	g_snprintf(notification, len, "%s left %s", user, conv->title);
	
	gntp_notify("chat-buddy-sign-out", NULL, "Chat Leave", notification, NULL);
	free(notification);
}
Ejemplo n.º 19
0
void js_enter_game_test(Character *actor, Character *self, std::shared_ptr< std::vector<JSTrigger*> > js_scripts)
{
	if (!js_scripts || js_scripts->size() == 0)
		return;
	if( (self && self->IsPurged()) || actor->IsPurged() )
		return;
	for (int i = 0; i < js_scripts->size(); ++i)
	{
		if (js_scripts->at(i)->isFlagged(JS::CHARACTER_LOGIN))
		{
			JSTrigger* trig = js_scripts->at(i);
			if( (!self || is_allowed( self, actor, trig )) ) {
				JSManager::get()->execute(trig, self, actor);
			}
		}
	}
}
Ejemplo n.º 20
0
static void
chat_buddy_joined_cb(PurpleConversation *conv, const char *user,
					 PurpleConvChatBuddyFlags flags, gboolean new_arrival, void *data)
{	
	char *notification;
	int len = s_strlen((char*)conv->title)+s_strlen((char*)user) + 9;
	
	DEBUG_MSG("chat_buddy_joined_cb\n");
	
	g_return_if_fail( is_allowed(purple_conversation_get_account(conv)) );
		
	//hack to hide spam when join channel
	if( GetTickCount() - start_tick_chat < 10000) return;

	notification = malloc( len );
	g_snprintf(notification, len, "%s joined %s", user, conv->title);
	
	gntp_notify("chat-buddy-sign-in", NULL, "Chat Join", notification, NULL);
	free(notification);
}
Ejemplo n.º 21
0
void js_bribe_trigger(Character *self, Character *actor, const int amt)
{
    if (!self->js_scripts || self->js_scripts->size() == 0)
        return;
	if( self->IsPurged() || actor->IsPurged() )
		return;
	if( !IS_NPC(self) )
		return;
    for (int i = 0; i < self->js_scripts->size(); ++i)
    {
        if (self->js_scripts->at(i)->isFlagged(JS::MOB_BRIBE))
        {
            JSTrigger* trig = self->js_scripts->at(i);
        
            if (is_allowed(self, actor, trig) )
            {
                JSManager::get()->execute(trig, self, actor, "", make_extra("amount", amt));
            }
        }
    }
}
Ejemplo n.º 22
0
bool js_command_test(Character * actor, const char* cmd, const char* args, bool aliasOverride, JSBindable *self=0)
{
	std::shared_ptr<std::vector<JSTrigger*> > js_scripts;
	if( self ) {
		if (!self->js_scripts || self->js_scripts->size() == 0)
			return false;
		js_scripts = self->js_scripts;
	}
	else
		js_scripts = globalJS_Scripts;
	std::list< std::string > lArgList;

	if (!js_scripts || js_scripts->empty())
		return false;
	for (int i = 0; i < js_scripts->size(); ++i)
	{
		// this looks for scripts that _might_ match
		if (js_scripts->at(i)->isFlagged(JS::COMMAND) && js_scripts->at(i)->optionFlagged(JS::OPTION_ALIAS_OVERRIDE) == aliasOverride)
		{
			// this looks for scripts that _do_ match
			JSTrigger* trig = js_scripts->at(i);

			//...Split the commands into a list, and check to see if the actor's command matches any of them.
			lArgList = StringUtil::splitToContainer< std::list<std::string> >(trig->args, ' ');
			for(std::list<std::string>::iterator sIter = lArgList.begin();sIter != lArgList.end();++sIter)
			{
				if( !str_cmp( (*sIter), cmd ) || (*sIter) == "*" )
				{
					if (!self || is_allowed(self, actor, trig))
					{
						int ret_val = JSManager::get()->execute(trig, self, actor, args);
						if (ret_val == 0)
							return true;
					}
				}
			}
		}
	}
	return false;
}
Ejemplo n.º 23
0
static void
buddy_signed_on_cb(PurpleBuddy *buddy, void *data)
{
	int hack_ms;
	char* buddy_nick, *buddy_name, *icon_path, *growl_msg;
	PurpleBuddyIcon* icon;
	int len = 2;

	DEBUG_MSG("buddy_signed_on_cb\n");
	
	g_return_if_fail( buddy != NULL );	
	g_return_if_fail( is_allowed(purple_buddy_get_account(buddy)) );
		
	start_tick_image = GetTickCount();
	//hack to hide spam when signing on to account
	hack_ms = purple_prefs_get_int("/plugins/core/pidgin-gntp/hack_ms");
	if( GetTickCount() - start_tick_im < hack_ms) return;
	
	
	buddy_nick = (char*)purple_buddy_get_alias(buddy);
	buddy_name = (char*)purple_buddy_get_name(buddy);
	
	purple_blist_update_buddy_icon(buddy);	
	
	icon = purple_buddy_get_icon(buddy);
	icon_path = (char*)purple_buddy_icon_get_full_path(icon);

	if(buddy_nick != NULL)
		len = strlen(buddy_nick) + 1;
	if(buddy_name  != NULL )
		 len += strlen(buddy_name);
		
	growl_msg = malloc( len );
	
	g_snprintf(growl_msg, len, "%s\n%s", buddy_nick, buddy_name );
	gntp_notify("buddy-sign-in", icon_path, "Signed In", growl_msg, NULL);
	
	free(growl_msg);
}
Ejemplo n.º 24
0
VectorXf PBSeqWeightEstimator::estimate(const vector<string>& msa) const {
    int rows = msa.size();
    int cols = msa[0].size();
    VectorXf seq_wt = VectorXf::Zero(rows); // sequence weights
    VectorXf alen = VectorXf::Zero(rows);   // number of residues for normalization
    char c;
    for (int j = 0; j < cols; ++j) {
        VectorXf res_wt(dim);  // residue weight
        res_wt = calc_residue_weight(msa, j);
        for (int i = 0; i < rows; ++i) {
            c = msa[i][j];
            if (is_allowed(c)) {
                seq_wt(i) += res_wt(abc_idx(c));
                alen(i) += 1;
            }
        }
    }
    for (int i = 0; i < rows; ++i)
        if (alen(i) > 0) seq_wt(i) /= alen(i);     // normalized by length
    if (seq_wt.sum() == 0) seq_wt.setOnes();
    return seq_wt / seq_wt.sum();
}
Ejemplo n.º 25
0
static gint
chat_invited_cb(PurpleAccount *account, const char *inviter,
				const char *room_name, const char *message,
				const GHashTable *components, void *data)
{
	char *notification;
	int len = 	s_strlen((char*)inviter)+
				s_strlen((char*)room_name)+
				s_strlen((char*)message) + 23;
	
	DEBUG_MSG("chat_invited_cb\n");
	
	if( !is_allowed(account) )
		return 0;
		
	notification = malloc( len );
	g_snprintf(notification, len, "%s has invited you to %s\n%s", inviter, room_name, message);
	
	gntp_notify("chat-invited", NULL, "Chat Invite", notification, NULL);
	free(notification);
	
	return 0;
}
Ejemplo n.º 26
0
static void
chat_topic_changed_cb(PurpleConversation *conv, const char *who,
					  const char *topic, void *data)
{
	char *notification;
	int len = 	s_strlen((char*)who)+
				s_strlen((char*)conv->title)+
				s_strlen((char*)topic) + 40;
							
	DEBUG_MSG("chat_topic_changed_cb\n");
	
	if(conv == NULL || topic == NULL || who == NULL)
		return;
	
	g_return_if_fail( is_allowed(purple_conversation_get_account(conv)) );
		
	notification = malloc( len );
					
	g_snprintf(notification, len, "%s topic: %s\nby %s", conv->title, topic, who);				
	
	gntp_notify("chat-topic-change", NULL, "Chat Topic Changed", notification, NULL);
	
	free(notification);
}
Ejemplo n.º 27
0
void
parseopt(int argc, char *argv[])
  /* set options */
{

    int c;
    extern char *optarg;
    extern int optind, opterr, optopt;
    struct passwd *pass;
#ifdef SYSFCRONTAB
    char is_sysfcrontab = 0;
#endif

    /* constants and variables defined by command line */

    while(1) {
	c = getopt(argc, argv, "u:lrezdnhVc:");
	if (c == EOF) break;
	switch (c) {

	case 'V':
	    info(); break;

	case 'h':
	    usage(); break;

	case 'u':
	    if (uid != ROOTUID) {
		fprintf(stderr, "must be privileged to use -u\n");
		xexit(EXIT_ERR);
	    }
	    user = strdup2(optarg) ; 
	    break;

	case 'd':
	    debug_opt = 1; break;

	case 'l':
	    if (rm_opt || edit_opt || reinstall_opt) {
		fprintf(stderr, "Only one of the options -l, -r, -e and -z"
			"may be used simultaneously.\n");
		xexit(EXIT_ERR);
	    }
	    list_opt = 1;
	    rm_opt = edit_opt = reinstall_opt = 0;
	    break;

	case 'r':
	    if (list_opt || edit_opt || reinstall_opt) {
		fprintf(stderr, "Only one of the options -l, -r, -e and -z"
			"may be used simultaneously.\n");
		xexit(EXIT_ERR);
	    }
	    rm_opt = 1;
	    list_opt = edit_opt = reinstall_opt = 0;
	    break;

	case 'e':
	    if (list_opt || rm_opt || reinstall_opt) {
		fprintf(stderr, "Only one of the options -l, -r, -e and -z"
			"may be used simultaneously.\n");
		xexit(EXIT_ERR);
	    }
	    edit_opt = 1;
	    list_opt = rm_opt = reinstall_opt = 0;
	    break;

	case 'z':
	    if (list_opt || rm_opt || edit_opt) {
		fprintf(stderr, "Only one of the options -l, -r, -e and -z"
			"may be used simultaneously.\n");
		xexit(EXIT_ERR);
	    }
	    reinstall_opt = ignore_prev = 1;
	    list_opt = rm_opt = edit_opt = 0;
	    break;

	case 'n':
	    ignore_prev = 1;
	    break;
	    
	case 'c':
	    if ( optarg[0] == '/' ) {
		Set(fcronconf, optarg);
	    }
	    else {
		char buf[PATH_LEN];
		snprintf(buf, sizeof(buf), "%s/%s", orig_dir, optarg);
		Set(fcronconf, buf);
	    }
	    break;

	case ':':
	    fprintf(stderr, "(setopt) Missing parameter.\n");
	    usage();

	case '?':
	    usage();

	default:
	    fprintf(stderr, "(setopt) Warning: getopt returned %c.\n", c);
	}
    }

    /* read fcron.conf and update global parameters */
    read_conf();
    
    /* read the file name and/or user and check validity of the arguments */
    if (argc - optind > 2)
	usage();
    else if (argc - optind == 2 ) {
	if ( list_opt + rm_opt + edit_opt + reinstall_opt == 0 )
	    file_opt = optind++;
	else
	    usage();

	if (uid != ROOTUID) {
	    fprintf(stderr, "must be privileged to use -u\n");
	    xexit(EXIT_ERR);
	}
	Set(user, argv[optind]); 
    }
    else if (argc - optind == 1) {
	if ( list_opt + rm_opt + edit_opt + reinstall_opt == 0 )
	    file_opt = optind;
	else {
	    if (uid != ROOTUID) {
		fprintf(stderr, "must be privileged to use [user|-u user]\n");
		xexit(EXIT_ERR);
	    }
	    Set(user, argv[optind]); 	    
	}
    }
    else if (list_opt + rm_opt + edit_opt + reinstall_opt != 1)
	usage();

    if ( user == NULL ) {
	/* get user's name using getpwuid() */
	if ( ! (pass = getpwuid(uid)) )
	    die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
	/* we need to strdup2 the value given by getpwuid() because we free
	 * file->cf_user in delete_file */
	user = strdup2(pass->pw_name);
	asuid = pass->pw_uid;
	asgid = pass->pw_gid;
    }
    else {
#ifdef SYSFCRONTAB
  	if ( strcmp(user, SYSFCRONTAB) == 0 ) {
	    is_sysfcrontab = 1;
	    asuid = ROOTUID;
	    asgid = ROOTGID;
	}
	else
#endif /* def SYSFCRONTAB */ 
	    if ( (pass = getpwnam(user)) ) {
		asuid = pass->pw_uid;
		asgid = pass->pw_gid;
	    }
	    else
		die("user \"%s\" is not in passwd file. Aborting.", user);
    }

    if ( 
#ifdef SYSFCRONTAB
	! is_sysfcrontab &&
#endif
	! is_allowed(user) ) {
	die("User \"%s\" is not allowed to use %s. Aborting.",
	    user, prog_name);	    
    }

#ifdef SYSFCRONTAB
    if ( is_sysfcrontab )
	runas = ROOTNAME;
    else
#endif
	runas = user;

}
static void
ide_ctags_completion_provider_populate (GtkSourceCompletionProvider *provider,
                                        GtkSourceCompletionContext  *context)
{
  IdeCtagsCompletionProvider *self = (IdeCtagsCompletionProvider *)provider;
  g_autofree gchar *word = NULL;
  const IdeCtagsIndexEntry *entries;
  const gchar * const *allowed;
  g_autoptr(GPtrArray) ar = NULL;
  IdeCtagsIndexEntry *last = NULL;
  GtkSourceBuffer *buffer;
  gsize n_entries;
  GtkTextIter iter;
  GList *list = NULL;
  gsize i;
  gsize j;

  IDE_ENTRY;

  g_assert (IDE_IS_CTAGS_COMPLETION_PROVIDER (self));
  g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));

  if (self->indexes->len == 0)
    IDE_GOTO (failure);

  if (!g_settings_get_boolean (self->settings, "ctags-autocompletion"))
    IDE_GOTO (failure);

  if (!gtk_source_completion_context_get_iter (context, &iter))
    IDE_GOTO (failure);

  buffer = GTK_SOURCE_BUFFER (gtk_text_iter_get_buffer (&iter));
  allowed = get_allowed_suffixes (buffer);

  word = get_word_to_cursor (&iter);
  if (ide_str_empty0 (word) || strlen (word) < self->minimum_word_size)
    IDE_GOTO (failure);

  if (strlen (word) < 3)
    IDE_GOTO (failure);

  ar = g_ptr_array_new ();

  IDE_TRACE_MSG ("Searching for %s", word);

  for (j = 0; j < self->indexes->len; j++)
    {
      IdeCtagsIndex *index = g_ptr_array_index (self->indexes, j);

      entries = ide_ctags_index_lookup_prefix (index, word, &n_entries);
      if ((entries == NULL) || (n_entries == 0))
        continue;

      for (i = 0; i < n_entries; i++)
        {
          const IdeCtagsIndexEntry *entry = &entries [i];

          if (is_allowed (entry, allowed))
            g_ptr_array_add (ar, (gpointer)entry);
        }
    }

  g_ptr_array_sort (ar, sort_wrapper);

  for (i = ar->len; i > 0; i--)
    {
      GtkSourceCompletionProposal *item;
      IdeCtagsIndexEntry *entry = g_ptr_array_index (ar, i - 1);

      /*
       * NOTE:
       *
       * We walk backwards in this ptrarray so that we can use g_list_prepend() for O(1) access.
       * I think everyone agrees that using GList for passing completion data around was not
       * a great choice, but it is what we have to work with.
       */

      /*
       * Ignore this item if the previous one looks really similar.
       * We take the first item instead of the last since the first item (when walking backwards)
       * tends to be more likely to be the one we care about (based on lexicographical
       * ordering. For example, something in "gtk-2.0" is less useful than "gtk-3.0".
       *
       * This is done here instead of during our initial object creation so that
       * we can merge items between different indexes. It often happens that the
       * same headers are included in multiple tags files.
       */
      if ((last != NULL) && too_similar (entry, last))
        continue;

      /*
       * NOTE:
       *
       * Autocompletion is very performance sensitive code. The smallest amount of
       * extra work has a very negative impact on interactivity. We are trying to
       * avoid a couple things here based on how completion works.
       *
       * 1) Avoiding referencing or copying things.
       *    Since the provider will always outlive the completion item, we use
       *    borrowed references for as much as we can.
       * 2) We delay the work of looking up icons until they are requested.
       *    No sense in doing that work before hand.
       */
      item = ide_ctags_completion_item_new (entry, self, context);
      list = g_list_prepend (list, item);

      last = entry;
    }

failure:
  gtk_source_completion_context_add_proposals (context, provider, list, TRUE);
  g_list_free_full (list, g_object_unref);

  IDE_EXIT;
}
Ejemplo n.º 29
0
int
main(int argc, char **argv)
{
    int return_code = 0;
    int fd = (-1);              /* fd == -1 means connection to fcron is not currently open */
    struct passwd *pass = NULL;

    rootuid = get_user_uid_safe(ROOTNAME);
    rootgid = get_group_gid_safe(ROOTGROUP);

    if (strrchr(argv[0], '/') == NULL)
        prog_name = argv[0];
    else
        prog_name = strrchr(argv[0], '/') + 1;

    user_uid = getuid();
    user_gid = getgid();
    if ((pass = getpwuid(user_uid)) == NULL)
        die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
    user_str = strdup2(pass->pw_name);

    /* drop suid rights that we don't need, but keep the sgid rights
     * for now as we will need them for read_conf() and is_allowed() */
#ifdef USE_SETE_ID
    seteuid_safe(user_uid);
#endif
    if (setuid(user_uid) < 0)
        die_e("could not setuid() to %d", user_uid);

    /* interpret command line options */
    parseopt(argc, argv);

    /* read fcron.conf and update global parameters */
    read_conf();

    if (!is_allowed(user_str)) {
        die("User \"%s\" is not allowed to use %s. Aborting.", user_str,
            prog_name);
    }

    /* we don't need anymore special rights : drop remaining ones */
#ifdef USE_SETE_ID
    setegid_safe(user_gid);
#endif
    if (setgid(user_gid) < 0)
        die_e("could not setgid() to %d", user_gid);

    /* check for broken pipes ... */
    signal(SIGPIPE, sigpipe_handler);

    if (cmd_str == NULL)
        return_code = interactive_mode(fd);
    else
        return_code = talk_fcron(cmd_str, fd);

    xexit((return_code == OK) ? EXIT_OK : EXIT_ERR);

    /* never reached */
    return EXIT_OK;

}
Ejemplo n.º 30
0
int bluez_listener(struct addrinfo hints,
		const char *local_address, const char *local_service,
		const char *remote_address, const char *remote_service,
		set_sockopt_handler_t set_sockopt_handler, void *hdata,
		listen_callback_t callback, void *cdata,
		time_t timeout, int max_accept)
{
	int fd = -1;
	struct sockaddr_storage ss;
	socklen_t salen = 0;
	char name_buf[BA_STR_SIZE];

	/* make sure arguments are valid and preconditions are respected */
	assert(local_address == NULL || strlen(local_address) > 0);
	assert(remote_address == NULL || strlen(remote_address) > 0);
	assert(callback != NULL);

	/* this function only supports a specific protocol family */
	assert(hints.ai_family == PF_BLUETOOTH);
	
	/* if max_accept is 0, just return */
	if (max_accept == 0)
		return 0;
	
	memset(&ss, 0, sizeof(ss));
	
	/* get the sockaddr */
	if (getbluezaddr(local_address, local_service, &hints,
	                 (struct sockaddr *)&ss, &salen))
	{
		return -1;
	}

	/* setup name_buf if we're in verbose mode */
	if (verbose_mode())
		getbluezname((struct sockaddr *)&ss, hints.ai_protocol,
		             name_buf, sizeof(name_buf));

	fd = socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol);
	if (fd < 0) {
		warning("cannot create the bluez socket: %s", strerror(errno));
		return -1;
	}

	if (set_sockopt_handler != NULL)
		set_sockopt_handler(fd, hdata);

	if (bind(fd, (struct sockaddr *)&ss, salen) < 0) {
		warning(_("bind to source %s failed: %s"),
		        name_buf, strerror(errno));
		return -1;
	}

	if (listen(fd, SOMAXCONN) != 0) {
		warning(_("cannot listen on %s: %s"),
		        name_buf, strerror(errno));
	}

	if (verbose_mode())
		warning(_("listening on %s ..."), name_buf);
	
	/* enter into the accept loop */
 	for (;;) {
		fd_set accept_fdset;
		struct timeval tv, *tvp = NULL;
		struct sockaddr_storage dest;
		socklen_t destlen;
		int ns, err;
		char c_name_buf[BA_STR_SIZE];

		FD_ZERO(&accept_fdset);
		FD_SET(fd, &accept_fdset);

		/* setup timeout */
		if (timeout > 0) {
			tv.tv_sec = timeout;
			tv.tv_usec = 0;
			tvp = &tv;
		}

		/* wait for an incoming connection */
		err = select(fd + 1, &accept_fdset, NULL, NULL, tvp);

		if (err <= 0) {
			if (err < 0 && errno == EINTR)
				continue;
			if (err == 0)
				warning(_("connection timed out"));
			else
				warning("select error: %s", strerror(errno));
			return -1;
		}

		/* double check that the fd is actually set */
		if (!FD_ISSET(fd, &accept_fdset))
			continue;

		destlen = sizeof(dest);	
		ns = accept(fd, (struct sockaddr *)&dest, &destlen);
		if (ns < 0) {
			warning("accept failed: %s", strerror(errno));
			return -1;
		}

		/* get the name for this client */
		if (verbose_mode())
			getbluezname((struct sockaddr *)&dest,
			             hints.ai_protocol,
				     c_name_buf, sizeof(name_buf));

		/* check if connections from this client are allowed */
		if ((remote_address == NULL && remote_service == NULL) ||
		    (is_allowed((struct sockaddr *)&dest, destlen, &hints,
				remote_address, remote_service) == true))
		{
			if (verbose_mode()) {
				warning(_("connect from %s"), c_name_buf);
			}

			callback(ns, SOCK_SEQPACKET, cdata);

			if (max_accept > 0 && --max_accept == 0)
				break;
		} else {
			close(ns);

			if (verbose_mode()) {
				warning(_("refused connect from %s"),
				        c_name_buf);
			}
		}
	}

	/* close the listening socket */
	close(fd);

	return 0;
}