コード例 #1
0
ファイル: codaconfedit.c プロジェクト: cmusatyalab/coda
int main(int argc, char **argv)
{
    char *conffile;
    const char *p, *val;
    int i, len;
    FAILIF(argc < 2, "Usage: %s <conffile> [<variable> [<value>]]\n", argv[0]);

    conffile = codaconf_file(argv[1]);

    if (argc < 3) {
        if (!conffile) {
            fprintf(stdout, "/dev/null\n");
            exit(EXIT_FAILURE);
        }
        fprintf(stdout, "%s\n", conffile);
        exit(EXIT_SUCCESS);
    }

    /* Hmm, should we really copy the template file on lookups as well. On one
     * hand it makes a 'readonly' operation 'write' data. On the other hand
     * there would otherwise be no other way to use the default template
     * without modifications */
    if (!conffile) {
        copy_template(argv[1]);
        conffile = codaconf_file(argv[1]);
        FAILIF(!conffile, "Failed to copy template file to '%s'\n", argv[1]);
    }

    codaconf_init_one(conffile);
    val = codaconf_lookup(argv[2], NULL);

    if (argc < 4) {
        FAILIF(!val, "Variable '%s' not found in '%s'\n", argv[2], conffile);

        fprintf(stdout, "%s\n", val);
        exit(EXIT_SUCCESS);
    }

    /* argc >= 4 */
    /* check if this value was already set */
    if (val) {
        p = val;
        for (i = 3; i <= argc; i++) {
            len = strlen(argv[i]);
            if (strncmp(argv[i], p, len) != 0)
                break;
            p = p + len;
            if (*p != ' ')
                break;
            p++;
        }
        if (i == argc - 1 && *p == '\0')
            exit(EXIT_SUCCESS);
    }

    do_rewrite(conffile, argc, argv);

    exit(EXIT_SUCCESS);
}
コード例 #2
0
ファイル: cmlmmoderate.C プロジェクト: MhdAlyan/courier
static int domodbounce(afxipipestream &i,std::string s)
{
	std::string	buf;
	std::string	from;
	std::string	replyto;

	{
		std::string	headerbuf="";

		while (std::getline(i, buf).good())
		{
			if (buf == "")	break;
			headerbuf += buf;
			headerbuf += '\n';
		}

		from=header_s(headerbuf, "from");
		replyto=header_s(headerbuf, "replyto");
	}

	std::string	boundary=mkboundary_msg_s(i);

	if (replyto.size())	from=replyto;

const char	*argv[6];

	argv[0]="sendmail";
	argv[1]="-f";

	std::string	me=get_verp_return("owner");

	argv[2]=me.c_str();
	argv[3]="-N";
	argv[4]="fail";
	argv[5]=0;

	pid_t	p;
	afxopipestream	ack(sendmail(argv, p));

	ack << "From: " << me << std::endl
		<< "Reply-To: " << me << std::endl
		<< "To: " << from << std::endl
		<< "Mime-Version: 1.0" << std::endl
		<< "Content-Type: multipart/mixed; boundary=\"" << boundary <<
			"\"" << std::endl
		<< "Content-Transfer-Encoding: 8bit" << std::endl;

	copy_template(ack, "modrejheader.tmpl", "");

	ack << std::endl;
	ack << "This is a MIME formatted message." << std::endl;
	ack << std::endl << "--" << boundary << std::endl;
	copy_template(ack, "modrejbody.tmpl", "");
	ack << s << std::endl << "--" << boundary << std::endl;
	ack << "Content-Type: message/rfc822" << std::endl << std::endl;

	i.seekg(0);
	if (i.bad())
	{
		perror("seek");
		return (EX_OSERR);
	}
	std::getline(i, buf); // Magic-Token: header

int	rc=docopy_noseek(i, ack);

	ack << std::endl << "--" << boundary << "--" << std::endl;

	ack.flush();
	if (ack.bad())
	{
		kill(p, SIGTERM);
		wait4sendmail(p);
		return (EX_OSERR);
	}

	ack.close();
int	rc2=wait4sendmail(p);

	if (rc2)	rc=rc2;
	return (rc);
}