Example #1
0
static void 
WebRunBinCmd(FILE *f, const char *query, int priv)
{
    Console		c = &gConsole;
    struct console_session css;
    ConsoleSession	cs = &css;
    char		*buf;
    char		*tmp;
    int			argc, k;
    char		*argv[MAX_CONSOLE_ARGS];
  
    memset(cs, 0, sizeof(*cs));

    cs->cookie = f;
    cs->console = c;
    cs->close = NULL;
    cs->write = WebConsoleSessionWrite;
    cs->writev = WebConsoleSessionWriteV;
    cs->prompt = WebConsoleSessionShowPrompt;
    cs->context.cs = cs;
    cs->context.priv = priv;

    tmp = buf = Mstrdup(MB_WEB, query);
    for (argc = 0; (argv[argc] = strsep(&tmp, "&")) != NULL;)
	if (argv[argc][0] != '\0')
    	    if (++argc >= MAX_CONSOLE_ARGS)
        	break;

    for (k = 0; k < argc; k++) {
	int	ac, rtn;
	char	*av[MAX_CONSOLE_ARGS];
	char	*buf1;

	buf1 = Malloc(MB_WEB, strlen(argv[k]) + 1);
	http_request_url_decode(argv[k], buf1);
        Log2(LG_CONSOLE, ("[%s] WEB: %s", 
	    cs->context.lnk ? cs->context.lnk->name :
		(cs->context.bund? cs->context.bund->name : ""), 
	    buf1));
	ac = ParseLine(buf1, av, sizeof(av) / sizeof(*av), 0);
	cs->context.errmsg[0] = 0;
	rtn = DoCommandTab(&cs->context, gCommands, ac, av);
	Freee(buf1);
	fprintf(f, "RESULT: %d %s\n", rtn, cs->context.errmsg);
    }
    Freee(buf);
    RESETREF(cs->context.lnk, NULL);
    RESETREF(cs->context.bund, NULL);
    RESETREF(cs->context.rep, NULL);
}
Example #2
0
File: pap.c Project: vstakhov/mpd
static void
PapSendRequest(Link l)
{
	PapInfo pap = &l->lcp.auth.pap;
	char password[AUTH_MAX_PASSWORD];
	int name_len, pass_len;
	u_char *pkt;

	/* Get password corresponding to my authname */
	Log(LG_AUTH, ("[%s] PAP: using authname \"%s\"",
	    l->name, l->lcp.auth.conf.authname));
	if (l->lcp.auth.conf.password[0] != 0) {
		strlcpy(password, l->lcp.auth.conf.password, sizeof(password));
	} else if (AuthGetData(l->lcp.auth.conf.authname, password,
	    sizeof(password), NULL, NULL) < 0) {
		Log(LG_AUTH, ("[%s] PAP: Warning: no secret for \"%s\" found",
		    l->name, l->lcp.auth.conf.authname));
	}
	/* Build response packet */
	name_len = strlen(l->lcp.auth.conf.authname);
	pass_len = strlen(password);

	pkt = Malloc(MB_AUTH, 1 + name_len + 1 + pass_len);
	pkt[0] = name_len;
	memcpy(pkt + 1, l->lcp.auth.conf.authname, name_len);
	pkt[1 + name_len] = pass_len;
	memcpy(pkt + 1 + name_len + 1, password, pass_len);

	/* Send it off */
	AuthOutput(l, PROTO_PAP, PAP_REQUEST, pap->next_id++, pkt,
	    1 + name_len + 1 + pass_len, 0, 0);
	Freee(pkt);
}
Example #3
0
File: util.c Project: vstakhov/mpd
void
LengthenArray(void *array, size_t esize, int *alenp, const char *type)
{
	void **const arrayp = (void **)array;
	void *newa;

	newa = Malloc(type, (*alenp + 1) * esize);
	if (*arrayp != NULL) {
		memcpy(newa, *arrayp, *alenp * esize);
		Freee(*arrayp);
	}
	*arrayp = newa;
	(*alenp)++;
}
Example #4
0
static void 
WebRunCmd(FILE *f, const char *query, int priv)
{
    Console		c = &gConsole;
    struct console_session css;
    ConsoleSession	cs = &css;
    char		*buf;
    char		*tmp;
    int			argc, k;
    char		*argv[MAX_CONSOLE_ARGS];
  
    memset(cs, 0, sizeof(*cs));

    cs->cookie = f;
    cs->console = c;
    cs->close = NULL;
    cs->write = WebConsoleSessionWrite;
    cs->writev = WebConsoleSessionWriteV;
    cs->prompt = WebConsoleSessionShowPrompt;
    cs->context.cs = cs;
    cs->context.priv = priv;

    tmp = buf = Mstrdup(MB_WEB, query);
    for (argc = 0; (argv[argc] = strsep(&tmp, "&")) != NULL;)
	if (argv[argc][0] != '\0')
    	    if (++argc >= MAX_CONSOLE_ARGS)
        	break;

    fprintf(f, "<P><A href=\"/\"><< Back</A></P>\n");

    if (argc == 0) {
	fprintf(f, "<P>No command cpecified!</P>\n");
	goto done;
    }

    fprintf(f, "<PRE>\n");
    for (k = 0; k < argc; k++) {
	int	ac;
	char	*av[MAX_CONSOLE_ARGS];
	char	*buf1;

	buf1 = Malloc(MB_WEB, strlen(argv[k]) + 1);
	http_request_url_decode(argv[k], buf1);
        Log2(LG_CONSOLE, ("[%s] WEB: %s", 
	    cs->context.lnk ? cs->context.lnk->name :
		(cs->context.bund? cs->context.bund->name : ""), 
	    buf1));

	cs->prompt(cs);
	cs->write(cs, "%s\n", buf1);
    
	ac = ParseLine(buf1, av, sizeof(av) / sizeof(*av), 0);
	DoCommand(&cs->context, ac, av, NULL, 0);
	Freee(buf1);
    }
    fprintf(f, "</PRE>\n");
done:
    Freee(buf);
    fprintf(f, "<P><A href=\"/\"><< Back</A></P>\n");
    RESETREF(cs->context.lnk, NULL);
    RESETREF(cs->context.bund, NULL);
    RESETREF(cs->context.rep, NULL);
}
Example #5
0
File: util.c Project: vstakhov/mpd
void
FreeArgs(int ac, char *av[])
{
	while (ac > 0)
		Freee(av[--ac]);
}