Пример #1
0
int do_ignoreuser(User * u, Channel *c, char *cmd, char *nick, char *time) {
	ChannelInfo *ci = c->ci;
	int t;

	if (!cmd) {
		notice_lang(ci->bi->nick, u, OPER_IGNORE_SYNTAX);
		return MOD_CONT;
	}

	if (!stricmp(cmd, "ADD")) {
		if (!nick) {
			notice_lang(ci->bi->nick, u, OPER_IGNORE_SYNTAX);
			return MOD_CONT;
		} else if (!time) {
			notice_lang(ci->bi->nick, u, OPER_IGNORE_SYNTAX);
			return MOD_CONT;
		} else {
			t = dotime(time);

			if (t <= -1) {
				notice_lang(ci->bi->nick, u, OPER_IGNORE_VALID_TIME);
				return MOD_CONT;
			} else if (t == 0) {
				t = 157248000;  /* if 0 is given, we set time to 157248000 seconds == 5 years (let's hope the next restart will  be before that time ;-)) */
				add_ignore(nick, t);
				notice_lang(ci->bi->nick, u, OPER_IGNORE_PERM_DONE, nick);
				alog("[bs_fantasy_ext] %s added %s permanently to the ignore list.", u->nick, nick);
			} else {
				add_ignore(nick, t);
				notice_lang(ci->bi->nick, u, OPER_IGNORE_TIME_DONE, nick, time);
				alog("[bs_fantasy_ext] %s added %s to the ignore list for %d seconds.", u->nick, nick, t);
			}
		}
	} else if (!stricmp(cmd, "LIST")) {
			do_ignorelist(u, ci);
			alog("[bs_fantasy_ext] %s requested the ignore list.", u->nick);
	}

	else if (!stricmp(cmd, "DEL")) {
		if (!nick) {
			notice_lang(ci->bi->nick, u, OPER_IGNORE_SYNTAX);
		} else {
			if (delete_ignore(nick)) {
				notice_lang(ci->bi->nick, u, OPER_IGNORE_DEL_DONE, nick);
				alog("[bs_fantasy_ext] %s deleted %s from the ignore list.", u->nick, nick);
				return MOD_CONT;
			} else
				notice_lang(ci->bi->nick, u, OPER_IGNORE_LIST_NOMATCH, nick);
		}
	} else if (!stricmp(cmd, "CLEAR")) {
		clear_ignores();
		notice_lang(ci->bi->nick, u, OPER_IGNORE_LIST_CLEARED);
		alog("[bs_fantasy_ext] %s cleared the ignore list.", u->nick);
		return MOD_CONT;
	} else
		notice_lang(ci->bi->nick, u, OPER_IGNORE_SYNTAX);
	return MOD_CONT;
}
Пример #2
0
int
main(
	int		argc,
	char		*argv[]
)
{
	int		c;		/* Command line character	 */
	char *		path;		/* Path being processed		 */

	me = argv[0];
	add_ignore( "." );
	add_ignore( ".." );
	while(
		(c = getopt( argc, argv, "aDc:dhFfgl:i:n:o:psuW:w" )) != EOF
	)	{
		switch( c )	{
		default:
			fprintf( stderr, "%s: no -%c yet!\n", me, c );
			/*FALLTHRU*/
		case '?':
			++nonfatal;
			break;
		case 'D':
			++debug;
			break;
		case 'a':
			++a_sw;
			break;
		case 'c':
			whatColumn = atoi( optarg );
			break;
		case 'd':
			++d_sw;
			break;
		case 'F':
			++F_sw;
			break;
		case 'f':
			++f_sw;
			break;
		case 'g':
			combo_sw |= Iwanna_group;
			break;
		case 'h':
			combo_sw |= Iwanna_size;
			break;
		case 'i':
			add_ignore( optarg );
			break;
		case 'l':
			depth = atoi( optarg );
			break;
		case 'p':
			combo_sw |= Iwanna_perms;
			break;
		case 'o':
			ofile = optarg;
			break;
		case 's':
			++s_sw;
			break;
		case 'u':
			combo_sw |= Iwanna_user;
			break;
		case 'W':
			leadin = optarg;
			Nleadin = strlen( leadin );
			break;
		case 'w':
			++w_sw;
			break;
		}
	}
	if( nonfatal )	{
		fprintf( stderr, "%s: illegal switch(es)\n", me );
		fprintf( stderr,
			"usage: %s "
			"[-D] "
			"[-a] "
			"[-d] "
			"[-c] "
			"[-d depth] "
			"[-f] "
			"[-l limit] "
			"[-i subdir] "
			"[-s] "
			"[-o ofile] "
			"[-p] "
			"[-W prefix] "
			"[-w] "
			"[dir...]"
			"\n",
			me
		);
		exit( 1 );
	}
	if( ofile )	{
		(void) unlink( ofile );
		if( freopen( ofile, "w", stdout ) != stdout )	{
			fprintf(stderr, "%s: cannot create '%s'\n", me, ofile);
			exit( 1 );
		}
	}
	/* Take path list from command if anything left on it		 */
	if( optind < argc )	{
		struct stat	st;
		int		others = 0;

		while( optind < argc )	{
			if( others++ )	{
				putchar( '\n' );
			}
			path = argv[ optind++ ];
			if( stat( path, &st ) )	{
				fprintf(
					stderr,
					"%s: "
					"cannot stat '%s'; "
					"errno=%d (%s)"
					".\n",
					me,
					path,
					errno,
					strerror( errno )
				);
				++nonfatal;
				continue;
			}
			printName( path, &st, 0, 1 );
			processDirectory( path, 1 );
		}
	} else	{
		/* Default to current directory				 */

		char		here[ PATH_MAX + 1 ];
		struct stat	st;

		if( !getcwd( here, sizeof( here ) ) )	{
			fprintf(
				stderr,
				"%s: getcwd() failed; errno=%d (%s).\n",
				me,
				errno,
				strerror( errno )
			);
			exit( 1 );
		}
		if( stat( here, &st ) )	{
			fprintf(
				stderr,
				"%s: "
				"cannot stat '%s'; "
				"errno=%d (%s)"
				".\n",
				me,
				here,
				errno,
				strerror( errno )
			);
		} else	{
			printName( here, &st, 0, 1 );
			processCurrentDirectory( here );
		}
	}
	return( nonfatal ? 1 : 0 );
}
Пример #3
0
/*
 * routine:
 *	main
 *
 * purpose:
 *	argument processing and primary dispatch
 *
 * returns:
 *	error codes per filesync.1 (ERR_* in filesync.h)
 *
 * notes:
 *	read filesync.1 in order to understand the argument processing
 *
 *	most of the command line options just set some opt_ global
 *	variable that is later looked at by the code that actually
 *	implements the features.  Only file names are really processed
 *	in this routine.
 */
int
main(int argc, char **argv)
{	int i;
	int c;
	errmask_t errs = ERR_OK;
	int do_prune = 0;
	char *srcname = 0;
	char *dstname = 0;
	struct base *bp;

	/* keep the error messages simple	*/
	argv[0] = "filesync";

	/* gather together all of the options	*/
	while ((c = getopt(argc, argv, "AaehmnqvyD:E:r:s:d:f:o:")) != EOF)
		switch (c) {
			case 'a':	/* always scan for acls	*/
				opt_acls = TRUE;
				break;
			case 'e':	/* everything agrees	*/
				opt_everything = TRUE;
				break;
			case 'h':	/* halt on error	*/
				opt_halt = TRUE;
				break;
			case 'm':	/* preserve modtimes	*/
				opt_mtime = TRUE;
				break;
			case 'n':	/* notouch		*/
				opt_notouch = TRUE;
				break;
			case 'q':	/* quiet		*/
				opt_quiet = TRUE;
				break;
			case 'v':	/* verbose		*/
				opt_verbose = TRUE;
				break;
			case 'y':	/* yes			*/
				opt_yes = TRUE;
				break;
			case 'D':	/* debug options	*/
				if (!isdigit(optarg[0])) {
					dbg_usage();
					exit(ERR_INVAL);
				}
				opt_debug |= strtol(optarg, (char **)NULL, 0);
				break;

			case 'E':	/* error simulation	*/
				if (dbg_set_error(optarg)) {
					err_usage();
					exit(ERR_INVAL);
				}
				opt_errors = TRUE;
				break;

			case 'f':	/* force conflict resolution	*/
				switch (optarg[0]) {
					case 's':
						opt_force = OPT_SRC;
						break;
					case 'd':
						opt_force = OPT_DST;
						break;
					case 'o':
						opt_force = OPT_OLD;
						break;
					case 'n':
						opt_force = OPT_NEW;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'o':	/* one way propagation		*/
				switch (optarg[0]) {
					case 's':
						opt_oneway = OPT_SRC;
						break;
					case 'd':
						opt_oneway = OPT_DST;
						break;
					default:
						fprintf(stderr,
							gettext(ERR_badopt),
							c, optarg);
						errs |= ERR_INVAL;
						break;
				}
				break;

			case 'r':	/* restricted reconciliation	*/
				if (num_restrs < MAX_RLIST)
					rlist[ num_restrs++ ] = optarg;
				else {
					fprintf(stderr, gettext(ERR_tomany),
						MAX_RLIST);
					errs |= ERR_INVAL;
				}
				break;

			case 's':
				if ((srcname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			case 'd':
				if ((dstname = qualify(optarg)) == 0)
					errs |= ERR_MISSING;
				break;

			default:
			case '?':
				errs |= ERR_INVAL;
				break;
		}

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: DBG=%s\n", showflags(dbgmap, opt_debug));

	/* if we have file names, we need a source and destination */
	if (optind < argc) {
		if (srcname == 0) {
			fprintf(stderr, gettext(ERR_nosrc));
			errs |= ERR_INVAL;
		}
		if (dstname == 0) {
			fprintf(stderr, gettext(ERR_nodst));
			errs |= ERR_INVAL;
		}
	}

	/* check for simple usage errors	*/
	if (errs & ERR_INVAL) {
		usage();
		exit(errs);
	}

	/* locate our baseline and rules files	*/
	if (c = findfiles())
		exit(c);

	/* figure out file creation defaults	*/
	whoami();

	/* read in our initial baseline		*/
	if (!new_baseline && (c = read_baseline(file_base)))
		errs |= c;

	/* read in the rules file if we need or have rules	*/
	if (optind >= argc && new_rules) {
		fprintf(stderr, ERR_nonames);
		errs |= ERR_INVAL;
	} else if (!new_rules)
		errs |= read_rules(file_rules);

	/* if anything has failed with our setup, go no further	*/
	if (errs) {
		cleanup(errs);
		exit(errs);
	}

	/*
	 * figure out whether or not we are willing to do a one-sided
	 * analysis (where we don't even look at the other side.  This
	 * is an "I'm just curious what has changed" query, and we are
	 * only willing to do it if:
	 *	we aren't actually going to do anything
	 *	we have a baseline we can compare against
	 * otherwise, we are going to insist on being able to access
	 * both the source and destination.
	 */
	if (opt_notouch && !new_baseline)
		opt_onesided = opt_oneway;

	/*
	 * there are two interested usage scenarios:
	 *	file names specified
	 *		create new rules for the specified files
	 *		evaulate and reconcile only the specified files
	 *	no file names specified
	 *		use already existing rules
	 *		consider restricting them to specified subdirs/files
	 */
	if (optind < argc) {
		/* figure out what base pair we're working on	*/
		bp = add_base(srcname, dstname);

		/* perverse default rules to avoid trouble	*/
		if (new_rules) {
			errs |= add_ignore(0, SUFX_RULES);
			errs |= add_ignore(0, SUFX_BASE);
		}

		/* create include rules for each file/dir arg	*/
		while (optind < argc)
			errs |= add_include(bp, argv[ optind++ ]);

		/*
		 * evaluate the specified base on each side,
		 * being careful to limit evaulation to new rules
		 */
		errs |= evaluate(bp, OPT_SRC, TRUE);
		errs |= evaluate(bp, OPT_DST, TRUE);
	} else {
		/* note any possible evaluation restrictions	*/
		for (i = 0; i < num_restrs; i++)
			errs |= add_restr(rlist[i]);

		/*
		 * we can only prune the baseline file if we have done
		 * a complete (unrestricted) analysis.
		 */
		if (i == 0)
			do_prune = 1;

		/* evaulate each base on each side		*/
		for (bp = bases; bp; bp = bp->b_next) {
			errs |= evaluate(bp, OPT_SRC, FALSE);
			errs |= evaluate(bp, OPT_DST, FALSE);
		}
	}

	/* if anything serious happened, skip reconciliation	*/
	if (errs & ERR_FATAL) {
		cleanup(errs);
		exit(errs);
	}

	/* analyze and deal with the differenecs		*/
	errs |= analyze();

	/* see if there is any dead-wood in the baseline	*/
	if (do_prune) {
		c = prune();

		if (c > 0 && opt_verbose)
			fprintf(stdout, V_prunes, c);
	}

	/* print out a final summary				*/
	summary();

	/* update the rules and baseline files (if needed)	*/
	(void) umask(my_umask);
	errs |= write_baseline(file_base);
	errs |= write_rules(file_rules);

	if (opt_debug & DBG_MISC)
		fprintf(stderr, "MISC: EXIT=%s\n", showflags(errmap, errs));

	/* just returning ERR_RESOLVABLE upsets some people	*/
	if (errs == ERR_RESOLVABLE && !opt_notouch)
		errs = 0;

	/* all done	*/
	cleanup(0);
	return (errs);
}