Ejemplo n.º 1
0
dofile()
	{

	char  word[WORDSIZE], *wp;
	char  cmd[WORDSIZE] , sub[WORDSIZE] ;
	int   n ;

	log_lev++;   /* one file deeper */
	pen = G_MOVE ;    /* pick up the pen for each new file. */

	while ( (n = getword(word, W_MUST)) > 0) {

		*cmd = 0;
		*sub = 0;

		/* see if it is a system call out */
		if (n == SYS_W || n == SIN_W) {
			/* so shell gets replaced */
			char *ex = "exec " ;
			/* char *ex = "" ;	*/

			strcpy(word, ex);
			wp = (word + strlen(ex)) ;

			(void)getword(wp, W_LITR) ; /*collect litteral string*/

			docmd("sys" , (n==SIN_W ? "in" : "") , word);
			}

		/* see if it is a command */
		else if (*word == cmd_char) {
			wp = word + 1;
			if (!mkcmd(wp, cmd, sub)) continue;

			/* get the (possible) argument */
			(void)getword(word, W_ANY ) ;

			/* got a command, so no arg */
			if (*word == cmd_char || *word == sys_char) { 
				putback(word);
				*word = 0;       /* null argument */
				}

			/* interpret the command, if word not used, putback */
			if (docmd(cmd, sub, word) == DOBACK) putback(word);
			}


		/* a number or some word that we don't care about */
		else {
			docmd("" , "" , word);
			}

		}/* of loop through file */

	log_lev--;        /* back from a file depth */
	}/* of dofile */
Ejemplo n.º 2
0
Archivo: cron.c Proyecto: 99years/plan9
void
printjobs(void)
{
	char buf[8*1024];
	Job *j;
	int i;

	for(i = 0; i < nuser; i++){
		print("user %s\n", users[i].name);
		for(j = users[i].jobs; j; j = j->next)
			if(!mkcmd(j->cmd, buf, sizeof buf))
				print("\tbad job %s on host %s\n",
					j->cmd, j->host);
			else
				print("\tjob %s on host %s\n", buf, j->host);
	}
}
Ejemplo n.º 3
0
struct high_state *load_dfa(struct high_syntax *syntax)
{
    unsigned char name[1024];
    unsigned char buf[1024];
    unsigned char bf[256];
    int clist[256];
    unsigned char *p;
    int c;
    FILE *f = NULL;
    struct ifstack *stack = 0;
    struct high_state *state = 0; /* Current state */
    struct high_state *first = 0; /* First state */
    int line = 0;
    int this_one = 0;
    int inside_subr = 0;

    /* Load it */

    if ((p = (unsigned char *)exists_prefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name)
    {
        strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT);
        f = fopen((char *)name, "r");
    }

    if (!f && (p = (unsigned char *)exists_gprefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name)
    {
        strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT);
        f = fopen((char *)name, "r");
    }

    if (!f)
    {
        return 0;
    }

    /* Parse file */
    while (fgets((char *)buf, 1023, f))
    {
        ++line;
        p = buf;
        c = parse_ws(&p, '#');
        if (!parse_char(&p, '.'))
        {
            if (!parse_ident(&p, bf, sizeof(bf)))
            {
                if (!zcmp(bf, USTR "ifdef"))
                {
                    struct ifstack *st = joe_malloc(sizeof(struct ifstack));
                    st->next = stack;
                    st->else_part = 0;
                    st->ignore = 1;
                    st->skip = 1;
                    st->line = line;
                    if (!stack || !stack->ignore)
                    {
                        parse_ws(&p, '#');
                        if (!parse_ident(&p, bf, sizeof(bf)))
                        {
                            struct high_param *param;
                            for (param = syntax->params; param; param = param->next)
                                if (!zcmp(param->name, bf))
                                {
                                    st->ignore = 0;
                                    break;
                                }
                            st->skip = 0;
                        }
                        else
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: missing parameter for ifdef\n")), name, line);
                        }
                    }
                    stack = st;
                }
                else if (!zcmp(bf, USTR "else"))
                {
                    if (stack && !stack->else_part)
                    {
                        stack->else_part = 1;
                        if (!stack->skip)
                        {
                            stack->ignore = !stack->ignore;
                        }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: else with no matching if\n")), name, line);
                    }
                }
                else if (!zcmp(bf, USTR "endif"))
                {
                    if (stack)
                    {
                        struct ifstack *st = stack;
                        stack = st->next;
                        joe_free(st);
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: endif with no matching if\n")), name, line);
                    }
                }
                else if (!zcmp(bf, USTR "subr"))
                {
                    parse_ws(&p, '#');
                    if (parse_ident(&p, bf, sizeof(bf)))
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line);
                    }
                    else
                    {
                        if (!stack || !stack->ignore)
                        {
                            inside_subr = 1;
                            this_one = 0;
                            if (syntax->subr && !zcmp(bf, syntax->subr))
                            {
                                this_one = 1;
                            }
                        }
                    }
                }
                else if (!zcmp(bf, USTR "end"))
                {
                    if (!stack || !stack->ignore)
                    {
                        this_one = 0;
                        inside_subr = 0;
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Unknown control statement\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing control statement name\n")), name, line);
            }
        }
        else if (stack && stack->ignore)
        {
            /* Ignore this line because of ifdef */
        }
        else if (!parse_char(&p, '='))
        {
            /* Parse color */
            parse_color_def(&syntax->color, p, name, line);
        }
        else if ((syntax->subr && !this_one) || (!syntax->subr && inside_subr))
        {
            /* Ignore this line because it's not the code we want */
        }
        else if (!parse_char(&p, ':'))
        {
            if (!parse_ident(&p, bf, sizeof(bf)))
            {

                state = find_state(syntax, bf);

                if (!first)
                {
                    first = state;
                }

                parse_ws(&p, '#');
                if (!parse_tows(&p, bf))
                {
                    struct high_color *color;
                    for (color = syntax->color; color; color = color->next)
                        if (!zcmp(color->name, bf))
                        {
                            break;
                        }
                    if (color)
                    {
                        state->color = color->color;
                    }
                    else
                    {
                        state->color = 0;
                        i_printf_2((char *)joe_gettext(_("%s %d: Unknown class\n")), name, line);
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing color for state definition\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line);
            }
        }
        else if (!parse_char(&p, '-'))
        {
            /* No. sync lines ignored */
        }
        else
        {
            c = parse_ws(&p, '#');

            if (!c)
            {
            }
            else if (c == '"' || c == '*' || c == '&')
            {
                if (state)
                {
                    struct high_cmd *cmd;
                    int delim = 0;
                    if (!parse_field(&p, USTR "*"))
                    {
                        int z;
                        for (z = 0; z != 256; ++z)
                        {
                            clist[z] = 1;
                        }
                    }
                    else if (!parse_field(&p, USTR "&"))
                    {
                        delim = 1;
                    }
                    else
                    {
                        c = parse_string(&p, bf, sizeof(bf));
                        if (c < 0)
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Bad string\n")), name, line);
                        }
                        else
                        {
                            int z;
                            int first, second;
                            unsigned char *t = bf;
                            for (z = 0; z != 256; ++z)
                            {
                                clist[z] = 0;
                            }
                            while (!parse_range(&t, &first, &second))
                            {
                                if (first > second)
                                {
                                    second = first;
                                }
                                while (first <= second)
                                {
                                    clist[first++] = 1;
                                }
                            }
                        }
                    }
                    /* Create command */
                    cmd = mkcmd();
                    parse_ws(&p, '#');
                    if (!parse_ident(&p, bf, sizeof(bf)))
                    {
                        int z;
                        cmd->new_state = find_state(syntax, bf);
                        parse_options(syntax, cmd, f, p, 0, name, line);

                        /* Install command */
                        if (delim)
                        {
                            state->delim = cmd;
                        }
                        else for (z = 0; z != 256; ++z)
                                if (clist[z])
                                {
                                    state->cmd[z] = cmd;
                                }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing jump\n")), name, line);
                    }
                }
                else
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: No state\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Unknown character\n")), name, line);
            }
        }
    }

    while (stack)
    {
        struct ifstack *st = stack;
        stack = st->next;
        i_printf_2((char *)joe_gettext(_("%s %d: ifdef with no matching endif\n")), name, st->line);
        joe_free(st);
    }

    fclose(f);

    return first;
}
Ejemplo n.º 4
0
void parse_options(struct high_syntax *syntax, struct high_cmd *cmd, FILE *f, unsigned char *p, int parsing_strings, unsigned char *name, int line)
{
    unsigned char buf[1024];
    unsigned char bf[256];
    unsigned char bf1[256];

    while (parse_ws(&p, '#'), !parse_ident(&p, bf, sizeof(bf)))
    {
        if (!zcmp(bf, USTR "buffer"))
        {
            cmd->start_buffering = 1;
        }
        else if (!zcmp(bf, USTR "hold"))
        {
            cmd->stop_buffering = 1;
        }
        else if (!zcmp(bf, USTR "save_c"))
        {
            cmd->save_c = 1;
        }
        else if (!zcmp(bf, USTR "save_s"))
        {
            cmd->save_s = 1;
        }
        else if (!zcmp(bf, USTR "recolor"))
        {
            parse_ws(&p, '#');
            if (!parse_char(&p, '='))
            {
                parse_ws(&p, '#');
                if (parse_int(&p, &cmd->recolor))
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
            }
        }
        else if (!zcmp(bf, USTR "call"))
        {
            parse_ws(&p, '#');
            if (!parse_char(&p, '='))
            {
                parse_ws(&p, '#');
                if (!parse_char(&p, '.'))
                {
                    zcpy(bf, syntax->name);
                    goto subr;
                }
                else if (parse_ident(&p, bf, sizeof(bf)))
                {
                    i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
                }
                else
                {
                    if (!parse_char(&p, '.'))
                    {
subr:
                        if (parse_ident(&p, bf1, sizeof(bf1)))
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line);
                        }
                        cmd->call = load_syntax_subr(bf, bf1, parse_params(syntax->params, &p, name, line));
                    }
                    else
                    {
                        cmd->call = load_syntax_subr(bf, 0, parse_params(syntax->params, &p, name, line));
                    }
                }
            }
            else
            {
                i_printf_2((char *)joe_gettext(_("%s %d: Missing value for option\n")), name, line);
            }
        }
        else if (!zcmp(bf, USTR "return"))
        {
            cmd->rtn = 1;
        }
        else if (!zcmp(bf, USTR "reset"))
        {
            cmd->reset = 1;
        }
        else if (!parsing_strings && (!zcmp(bf, USTR "strings") || !zcmp(bf, USTR "istrings")))
        {
            if (bf[0] == 'i')
            {
                cmd->ignore = 1;
            }
            while (fgets((char *)buf, 1023, f))
            {
                ++line;
                p = buf;
                parse_ws(&p, '#');
                if (*p)
                {
                    if (!parse_field(&p, USTR "done"))
                    {
                        break;
                    }
                    if (parse_string(&p, bf, sizeof(bf)) >= 0)
                    {
                        parse_ws(&p, '#');
                        if (cmd->ignore)
                        {
                            lowerize(bf);
                        }
                        if (!parse_ident(&p, bf1, sizeof(bf1)))
                        {
                            struct high_cmd *kw_cmd = mkcmd();
                            kw_cmd->noeat = 1;
                            kw_cmd->new_state = find_state(syntax, bf1);
                            if (!zcmp(bf, USTR "&"))
                            {
                                cmd->delim = kw_cmd;
                            }
                            else
                            {
                                if (!cmd->keywords)
                                {
                                    cmd->keywords = htmk(64);
                                }
                                htadd(cmd->keywords, zdup(bf), kw_cmd);
                            }
                            parse_options(syntax, kw_cmd, f, p, 1, name, line);
                        }
                        else
                        {
                            i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line);
                        }
                    }
                    else
                    {
                        i_printf_2((char *)joe_gettext(_("%s %d: Missing string\n")), name, line);
                    }
                }
            }
        }
        else if (!zcmp(bf, USTR "noeat"))
        {
            cmd->noeat = 1;
        }
        else if (!zcmp(bf, USTR "mark"))
        {
            cmd->start_mark = 1;
        }
        else if (!zcmp(bf, USTR "markend"))
        {
            cmd->stop_mark = 1;
        }
        else if (!zcmp(bf, USTR "recolormark"))
        {
            cmd->recolor_mark = 1;
        }
        else
        {
            i_printf_2((char *)joe_gettext(_("%s %d: Unknown option\n")), name, line);
        }
    }
}
Ejemplo n.º 5
0
Archivo: cron.c Proyecto: 99years/plan9
void
rexec(User *user, Job *j)
{
	char buf[8*1024];
	int n, fd;
	AuthInfo *ai;

	switch(rfork(RFPROC|RFNOWAIT|RFNAMEG|RFENVG|RFFDG)){
	case 0:
		break;
	case -1:
		clog("can't fork a job for %s: %r\n", user->name);
	default:
		return;
	}

	if(!mkcmd(j->cmd, buf, sizeof buf)){
		clog("internal error: cmd buffer overflow");
		_exits(0);
	}

	/*
	 * local call, auth, cmd with no i/o
	 */
	if(strcmp(j->host, "local") == 0){
		if(becomeuser(user->name) < 0){
			clog("%s: can't change uid for %s on %s: %r",
				user->name, j->cmd, j->host);
			_exits(0);
		}
		putenv("service", "rx");
		clog("%s: ran '%s' on %s", user->name, j->cmd, j->host);
		execl("/bin/rc", "rc", "-lc", buf, nil);
		clog("%s: exec failed for %s on %s: %r",
			user->name, j->cmd, j->host);
		_exits(0);
	}

	/*
	 * remote call, auth, cmd with no i/o
	 * give it 2 min to complete
	 */
	alarm(2*Minute*1000);
	fd = call(j->host);
	if(fd < 0){
		if(fd == -2)
			clog("%s: dangerous host %s", user->name, j->host);
		clog("%s: can't call %s: %r", user->name, j->host);
		_exits(0);
	}
	clog("%s: called %s on %s", user->name, j->cmd, j->host);
	if(becomeuser(user->name) < 0){
		clog("%s: can't change uid for %s on %s: %r",
			user->name, j->cmd, j->host);
		_exits(0);
	}
	ai = auth_proxy(fd, nil, "proto=p9any role=client");
	if(ai == nil){
		clog("%s: can't authenticate for %s on %s: %r",
			user->name, j->cmd, j->host);
		_exits(0);
	}
	clog("%s: authenticated %s on %s", user->name, j->cmd, j->host);
	write(fd, buf, strlen(buf)+1);
	write(fd, buf, 0);
	while((n = read(fd, buf, sizeof(buf)-1)) > 0){
		buf[n] = 0;
		clog("%s: %s\n", j->cmd, buf);
	}
	_exits(0);
}