Esempio n. 1
0
void
server_lock(void)
{
	struct client	       *c;
	static struct passwd   *pw, pwstore;
	static char		pwbuf[_PW_BUF_LEN];
	u_int			i;

	if (server_locked)
		return;

	if (getpwuid_r(getuid(), &pwstore, pwbuf, sizeof pwbuf, &pw) != 0) {
		server_locked_pw = NULL;
		return;
	}
	server_locked_pw = pw;

	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (c == NULL || c->session == NULL)
			continue;

		status_prompt_clear(c);
		status_prompt_set(c,
		    "Password:", server_lock_callback, NULL, c, PROMPT_HIDDEN);
  		server_redraw_client(c);
	}

	server_locked = 1;
}
Esempio n. 2
0
int
match_account_match(struct mail_ctx *mctx, struct expritem *ei)
{
	struct match_account_data	*data = ei->data;
	struct account			*a = mctx->account;
	struct mail			*m = mctx->mail;
	char				*s;
	u_int				 i;

	for (i = 0; i < ARRAY_LENGTH(data->accounts); i++) {
		s = replacestr(
		    &ARRAY_ITEM(data->accounts, i), m->tags, m, &m->rml);
		if (s == NULL || *s == '\0') {
			if (s != NULL)
				xfree(s);
			log_warnx("%s: empty account", a->name);
			return (MATCH_ERROR);
		}
		if (account_match(s, a->name)) {
			xfree(s);
			return (MATCH_TRUE);
		}
		xfree(s);
	}

	return (MATCH_FALSE);
}
Esempio n. 3
0
File: tty.c Progetto: jnbek/tmux
void
tty_write(void (*cmdfn)(
              struct tty *, const struct tty_ctx *), const struct tty_ctx *ctx)
{
    struct window_pane	*wp = ctx->wp;
    struct client		*c;
    u_int		 	 i;

    /* wp can be NULL if updating the screen but not the terminal. */
    if (wp == NULL)
        return;

    if (wp->window->flags & WINDOW_REDRAW || wp->flags & PANE_REDRAW)
        return;
    if (wp->window->flags & WINDOW_HIDDEN || !window_pane_visible(wp))
        return;

    for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
        c = ARRAY_ITEM(&clients, i);
        if (c == NULL || c->session == NULL)
            continue;
        if (c->flags & CLIENT_SUSPENDED)
            continue;

        if (c->session->curw->window == wp->window) {
            if (c->tty.flags & TTY_FREEZE || c->tty.term == NULL)
                continue;
            cmdfn(&c->tty, ctx);
        }
    }
}
int
cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx)
{
	struct session		*s;
	struct session_group	*sg;
	char			*tim, tmp[64];
	u_int			 i, idx;
	time_t			 t;

	for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
		s = ARRAY_ITEM(&sessions, i);
		if (s == NULL)
			continue;

		sg = session_group_find(s);
		if (sg == NULL)
			*tmp = '\0';
		else {
			idx = session_group_index(sg);
			xsnprintf(tmp, sizeof tmp, " (group %u)", idx);
		}

		t = s->creation_time.tv_sec;
		tim = ctime(&t);
		*strchr(tim, '\n') = '\0';

		ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s",
		    s->name, winlink_count(&s->windows), tim, s->sx, s->sy,
		    tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)");
	}

	return (0);
}
Esempio n. 5
0
File: alist.c Progetto: srfrog/epic5
/*
 * Returns an entry that has been displaced, if any.
 */
array_item *add_to_array (array *a, array_item *item)
{
	int 		count;
	int 		location = 0;
	array_item *	ret = NULL;
	u_32int_t	mask; 	/* Dummy var */

	if (a->hash == HASH_INSENSITIVE)
		item->hash = ci_alist_hash(item->name, &mask);
	else
		item->hash = cs_alist_hash(item->name, &mask);

	check_array_size(a);
	if (a->max)
	{
		find_array_item(a, item->name, &count, &location);
		if (count < 0)
		{
			ret = ARRAY_ITEM(a, location);
			a->max--;
		}
		else
			move_array_items(a, location, a->max, 1);
	}

	a->list[location] = item;
	a->max++;
	return ret;
}
Esempio n. 6
0
void
control_notify_window_layout_changed(struct window *w)
{
	struct client		*c;
	struct session		*s;
	struct format_tree	*ft;
	struct winlink		*wl;
	u_int			 i;
	const char		*template;

	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
			continue;
		s = c->session;

		if (winlink_find_by_window_id(&s->windows, w->id) == NULL)
			continue;

#ifndef TMATE_SLAVE
		/*
		 * When the last pane in a window is closed it won't have a
		 * layout root and we don't need to inform the client about the
		 * layout change because the whole window will go away soon.
		 */
		if (w->layout_root == NULL)
			continue;
/* ARGSUSED */
int
cmd_list_clients_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args 	*args = self->args;
	struct client	*c;
	struct session  *s;
	u_int		 i;
	const char	*s_utf8;

	if (args_has(args, 't')) {
		s = cmd_find_session(ctx, args_get(args, 't'), 0);
		if (s == NULL)
			return (-1);
	} else
		s = NULL;

	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (c == NULL || c->session == NULL)
			continue;

		if (c->tty.flags & TTY_UTF8)
			s_utf8 = " (utf8)";
		else
			s_utf8 = "";

		if (s != NULL && s != c->session)
			continue;
		ctx->print(ctx, "%s: %s [%ux%u %s]%s", c->tty.path,
		    c->session->name, c->tty.sx, c->tty.sy,
		    c->tty.termname, s_utf8);
	}

	return (0);
}
Esempio n. 8
0
int
server_unlock(const char *s)
{
    struct client	*c;
    u_int		 i;
    char		*out;

    if (!server_locked)
        return (0);

    if (server_password != NULL) {
        if (s == NULL)
            return (-1);
        out = crypt(s, server_password);
        if (strcmp(out, server_password) != 0)
            return (-1);
    }

    for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
        c = ARRAY_ITEM(&clients, i);
        if (c == NULL)
            continue;

        status_prompt_clear(c);
        server_redraw_client(c);
    }
    server_locked = 0;

    return (0);
}
/* Get an item by its index. */
struct paste_buffer *
paste_get_index(struct paste_stack *ps, u_int idx)
{
	if (idx >= ARRAY_LENGTH(ps))
		return (NULL);
	return (ARRAY_ITEM(ps, idx));
}
Esempio n. 10
0
/* Make an array of all the mboxes to visit. */
int
fetch_mbox_make(struct account *a)
{
	struct fetch_mbox_data	*data = a->data;
	struct fetch_mbox_mbox	*fmbox;
	char			*path;
	u_int			 i, j;
	glob_t			 g;

	ARRAY_INIT(&data->fmboxes);

	for (i = 0; i < ARRAY_LENGTH(data->mboxes); i++) {
		path = ARRAY_ITEM(data->mboxes, i);
		if (glob(path, GLOB_BRACE|GLOB_NOCHECK, NULL, &g) != 0) {
			log_warn("%s: glob(\"%s\")", a->name, path);
			goto error;
		}

		if (g.gl_pathc < 1)
			fatalx("glob returned garbage");
		for (j = 0; j < (u_int) g.gl_pathc; j++) {
			fmbox = xcalloc(1, sizeof *fmbox);
			fmbox->path = xstrdup(g.gl_pathv[j]);
			fmbox->fd = -1;
			fmbox->base = NULL;
			ARRAY_ADD(&data->fmboxes, fmbox);
		}

		globfree(&g);
	}

	return (0);

error:
	for (i = 0; i < ARRAY_LENGTH(&data->fmboxes); i++) {
		fmbox = ARRAY_ITEM(&data->fmboxes, i);

		xfree(fmbox->path);
		xfree(fmbox);
	}
	ARRAY_FREE(&data->fmboxes);

	return (-1);
}
Esempio n. 11
0
/*
 * Move ``start'' through ``end'' array elements ``dir'' places up
 * in the array.  If ``dir'' is negative, move them down in the array.
 * Fill in the vacated spots with NULLs.
 */
void move_array_items (array *a, int start, int end, int dir)
{
	int 	i;

	if (dir > 0)
	{
		for (i = end; i >= start; i--)
			LARRAY_ITEM(a, i + dir) = ARRAY_ITEM(a, i);
		for (i = dir; i > 0; i--)
			LARRAY_ITEM(a, start + i - 1) = NULL;
	}
	else if (dir < 0)
	{
		for (i = start; i <= end; i++)
			LARRAY_ITEM(a, i + dir) = ARRAY_ITEM(a, i);
		for (i = end - dir + 1; i <= end; i++)
			LARRAY_ITEM(a, i) = NULL;
	}
}
Esempio n. 12
0
void
keywords_clear()
{
	int i;

	for (i = 0; i < ARRAY_LENGTH(&keywords); i++)
		xfree(ARRAY_ITEM(&keywords, i));

	ARRAY_CLEAR(&keywords);
}
Esempio n. 13
0
int
cmd_detach_client_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args	*args = self->args;
	struct client	*c, *c2;
	struct session 	*s;
	enum msgtype     msgtype;
	u_int 		 i;

	if (args_has(args, 'P'))
		msgtype = MSG_DETACHKILL;
	else
		msgtype = MSG_DETACH;

	if (args_has(args, 's')) {
		s = cmd_find_session(ctx, args_get(args, 's'), 0);
		if (s == NULL)
			return (-1);

		for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
			c = ARRAY_ITEM(&clients, i);
			if (c != NULL && c->session == s)
				server_write_client(c, msgtype, NULL, 0);
		}
	} else {
		c = cmd_find_client(ctx, args_get(args, 't'));
		if (c == NULL)
			return (-1);

		if (args_has(args, 'a')) {
			for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
				c2 = ARRAY_ITEM(&clients, i);
				if (c2 == NULL || c == c2)
					continue;
				server_write_client(c2, msgtype, NULL, 0);
			}
		} else
			server_write_client(c, msgtype, NULL, 0);
	}

	return (0);
}
Esempio n. 14
0
/* Select state 1. */
int
imap_state_select1(struct account *a, struct fetch_ctx *fctx)
{
	struct fetch_imap_data	*data = a->data;

	if (imap_putln(a, "%u SELECT {%zu}",
	    ++data->tag, strlen(ARRAY_ITEM(data->folders, data->folder))) != 0)
		return (FETCH_ERROR);
	fctx->state = imap_state_select2;
	return (FETCH_BLOCK);
}
Esempio n. 15
0
static int num_clients(void)
{
	unsigned int i, count = 0;

	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		if (ARRAY_ITEM(&clients, i))
			count++;
	}

	return count;
}
Esempio n. 16
0
File: main.c Progetto: pbleser/mdp
void
print_results()
{
	int i;
	struct result *result;

	for (i = 0; i < ARRAY_LENGTH(&results); i++) {
		result = ARRAY_ITEM(&results, i);
		if (result->status == RESULT_SHOW)
			printf("%ls\n", result->value);
	}
}
Esempio n. 17
0
/* Body state. */
int
imap_state_body(struct account *a, struct fetch_ctx *fctx)
{
	struct fetch_imap_data	*data = a->data;
	struct mail		*m = fctx->mail;
	struct fetch_imap_mail	*aux;
	char			*line, *ptr;
	u_int			 n;

	if (imap_getln(a, fctx, IMAP_UNTAGGED, &line) != 0)
		return (FETCH_ERROR);
	if (line == NULL)
		return (FETCH_BLOCK);

	if (sscanf(line, "* %u FETCH (", &n) != 1)
		return (imap_invalid(a, line));
	if ((ptr = strstr(line, "BODY[] {")) == NULL)
		return (imap_invalid(a, line));

	if (sscanf(ptr, "BODY[] {%zu}", &data->size) != 1)
		return (imap_invalid(a, line));
	data->lines = 0;

	/* Fill in local data. */
	aux = xcalloc(1, sizeof *aux);
	aux->uid = ARRAY_FIRST(&data->wanted);
	m->auxdata = aux;
	m->auxfree = imap_free;
	ARRAY_REMOVE(&data->wanted, 0);

	/* Open the mail. */
	if (mail_open(m, data->size) != 0) {
		log_warnx("%s: failed to create mail", a->name);
		return (FETCH_ERROR);
	}
	m->size = 0;

	/* Tag mail. */
	default_tags(&m->tags, data->src);
	if (data->server.host != NULL) {
		add_tag(&m->tags, "server", "%s", data->server.host);
		add_tag(&m->tags, "port", "%s", data->server.port);
	}
	add_tag(&m->tags, "server_uid", "%u", aux->uid);
	add_tag(&m->tags,
	    "folder", "%s", ARRAY_ITEM(data->folders, data->folder));

	/* If we already know the mail is oversize, start off flushing it. */
	data->flushing = data->size > conf.max_size;

	fctx->state = imap_state_line;
	return (FETCH_AGAIN);
}
Esempio n. 18
0
/* Remove the 'which'th item from the given array */
Array_item *BX_array_pop (Array *array, int which)
{
	Array_item *ret = NULL;

	if (which < 0 || which >= array->max)
		return NULL;

	ret = ARRAY_ITEM(array, which);
	move_array_items(array, which + 1, array->max, -1);
	array->max--;
	return ret;
}
Esempio n. 19
0
File: mail.c Progetto: avkrotov/fdm
void
set_wrapped(struct mail *m, char ch)
{
	u_int	i;

	if (m->wrapchar == ch)
		return;
	m->wrapchar = ch;

	for (i = 0; i < ARRAY_LENGTH(&m->wrapped); i++)
		m->data[ARRAY_ITEM(&m->wrapped, i)] = ch;
}
Esempio n. 20
0
/* Remove the 'which'th item from the given array */
array_item *array_pop (array *a, int which)
{
	array_item *ret = NULL;

	if (which < 0 || which >= a->max)
		return NULL;

	ret = ARRAY_ITEM(a, which);
	move_array_items(a, which + 1, a->max, -1);
	a->max--;
	check_array_size(a);
	return ret;
}
Esempio n. 21
0
File: cfg.c Progetto: JonAWhite/tmux
void
cfg_print_causes(struct cmd_q *cmdq)
{
	char	*cause;
	u_int	 i;

	for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
		cause = ARRAY_ITEM(&cfg_causes, i);
		cmdq_print(cmdq, "%s", cause);
		free(cause);
	}
	ARRAY_FREE(&cfg_causes);
}
Esempio n. 22
0
void
window_more_free(struct window_pane *wp)
{
	struct window_more_mode_data	*data = wp->modedata;
	u_int				 i;

	for (i = 0; i < ARRAY_LENGTH(&data->list); i++)
		xfree(ARRAY_ITEM(&data->list, i));
	ARRAY_FREE(&data->list);

	screen_free(&data->screen);
	xfree(data);
}
Esempio n. 23
0
File: control.c Progetto: bholt/tmux
static void
control_foreach_client(control_write_cb *cb, void *user_data)
{
	for (int i = 0; i < (int) ARRAY_LENGTH(&clients); i++) {
		struct client *c = ARRAY_ITEM(&clients, i);
		if (c && c->flags & CLIENT_CONTROL) {
			if (c->flags & CLIENT_SUSPENDED) {
				continue;
			}
			cb(c, user_data);
		}
	}
}
Esempio n. 24
0
void
server_destroy_session(struct session *s)
{
	struct client	*c;
	u_int		 i;
	
	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (c == NULL || c->session != s)
			continue;
		c->session = NULL;
		server_write_client(c, MSG_EXIT, NULL, 0);
	}
}
Esempio n. 25
0
/* Clean up and free data. */
int
fetch_mbox_state_exit(struct account *a, unused struct fetch_ctx *fctx)
{
	struct fetch_mbox_data	*data = a->data;
	u_int			 i;

	for (i = 0; i < ARRAY_LENGTH(&data->fmboxes); i++) {
		if (fetch_mbox_save(a, ARRAY_ITEM(&data->fmboxes, i)) != 0)
			return (FETCH_ERROR);
	}

	fetch_mbox_abort(a);
	return (FETCH_EXIT);
}
Esempio n. 26
0
void
server_status_session(struct session *s)
{
    struct client	*c;
    u_int		 i;

    for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
        c = ARRAY_ITEM(&clients, i);
        if (c == NULL || c->session == NULL)
            continue;
        if (c->session == s)
            server_status_client(c);
    }
}
Esempio n. 27
0
int
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{
	struct args		*args = self->args;
	struct causelist	 causes;
	char			*cause;
	struct window_pane	*wp;
	int			 retval;
	u_int			 i;

	ARRAY_INIT(&causes);

	retval = load_cfg(args->argv[0], ctx, &causes);
	if (ARRAY_EMPTY(&causes))
		return (retval);

	if (retval == 1 && !RB_EMPTY(&sessions) && ctx->cmdclient != NULL) {
		wp = RB_MIN(sessions, &sessions)->curw->window->active;
		window_pane_set_mode(wp, &window_copy_mode);
		window_copy_init_for_output(wp);
		for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
			cause = ARRAY_ITEM(&causes, i);
			window_copy_add(wp, "%s", cause);
			xfree(cause);
		}
	} else {
		for (i = 0; i < ARRAY_LENGTH(&causes); i++) {
			cause = ARRAY_ITEM(&causes, i);
			ctx->print(ctx, "%s", cause);
			xfree(cause);
		}
	}
	ARRAY_FREE(&causes);

	return (retval);
}
Esempio n. 28
0
void
server_redraw_window(struct window *w)
{
    struct client	*c;
    u_int		 i;

    for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
        c = ARRAY_ITEM(&clients, i);
        if (c == NULL || c->session == NULL)
            continue;
        if (c->session->curw->window == w)
            server_redraw_client(c);
    }
    w->flags |= WINDOW_REDRAW;
}
Esempio n. 29
0
void
server_write_window(
    struct window *w, enum hdrtype type, const void *buf, size_t len)
{
    struct client	*c;
    u_int		 i;

    for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
        c = ARRAY_ITEM(&clients, i);
        if (c == NULL || c->session == NULL)
            continue;
        if (c->session->curw->window == w)
            server_write_client(c, type, buf, len);
    }
}
Esempio n. 30
0
void
server_write_session(
    struct session *s, enum msgtype type, const void *buf, size_t len)
{
	struct client	*c;
	u_int		 i;

	for (i = 0; i < ARRAY_LENGTH(&clients); i++) {
		c = ARRAY_ITEM(&clients, i);
		if (c == NULL || c->session == NULL)
			continue;
		if (c->session == s)
			server_write_client(c, type, buf, len);
	}
}