示例#1
0
int main(int argc, char **argv) {
  if (argc < 2) {
    print_usage();
    return 1;
  }
  std::string cmd = argv[1];

  // If there are files specified as part of the command
  // collect them into a vector.
  std::vector<std::string> files(argv + 2, argv + argc);

  uid_t euid = geteuid();
  auto print_spooler = spool_controller();

  if (cmd == ADD)
    print_spooler.add_files(files);
  else if (cmd == RM)
    print_spooler.rm_files(files);
  else if (cmd == LS)
    print_spooler.ls_files();
  else
    print_usage();

  // We restore the euid because spool_info's destructor needs it so that it
  // can write the info file back into its place within the spool directory.
  seteuid(euid);
  return 0;
}
示例#2
0
int
main(int argc, char **argv)
{
	int ch, ret = 0, rflag = 0, argindex, tries;
	struct passwd *pstruct;
	struct stat statbuf;
#ifndef att
	FILE *pwf;		/* fille ptr for opened passwd file */
#endif
	char *usertype = NULL;
	int rc;

	cmdname = argv[0];

	if( geteuid() != 0 ) {
		errmsg( M_PERM_DENIED );
		exit( EX_NO_PERM );
	}

	opterr = 0;			/* no print errors from getopt */
	usertype = getusertype(argv[0]);
	
	while( (ch = getopt(argc, argv, "r")) != EOF ) {
		switch(ch) {
			case 'r':
				rflag++;
				break;
			case '?':
				if (is_role(usertype))
					errmsg( M_DRUSAGE );
				else
					errmsg( M_DUSAGE );
				exit( EX_SYNTAX );
		}
	}

	if( optind != argc - 1 ) {
		if (is_role(usertype))
			errmsg( M_DRUSAGE );
		else
			errmsg( M_DUSAGE );
		exit( EX_SYNTAX );
	}

	logname = argv[optind];

#ifdef att
	pstruct = getpwnam(logname);
#else
	/*
	 * Do this with fgetpwent to make sure we are only looking on local
	 * system (since passmgmt only works on local system).
	 */
	if ((pwf = fopen("/etc/passwd", "r")) == NULL) {
		errmsg( M_OOPS, "open", "/etc/passwd");
		exit(EX_FAILURE);
	}
	while ((pstruct = fgetpwent(pwf)) != NULL)
		if (strcmp(pstruct->pw_name, logname) == 0)
			break;

	fclose(pwf);
#endif

	if (pstruct == NULL) {
		errmsg( M_EXIST, logname );
		exit( EX_NAME_NOT_EXIST );
	}

	if( isbusy(logname) ) {
		errmsg( M_BUSY, logname, "remove" );
		exit( EX_BUSY );
	}

	/* that's it for validations - now do the work */
	/* set up arguments to  passmgmt in nargv array */
	nargv[0] = PASSMGMT;
	nargv[1] = "-d";	/* delete */
	argindex = 2;		/* next argument */

	/* finally - login name */
	nargv[argindex++] = logname;

	/* set the last to null */
	nargv[argindex++] = NULL;

	/* remove home directory */
	if( rflag ) {
		/* Check Permissions */
		if( stat( pstruct->pw_dir, &statbuf ) ) {
			errmsg(M_OOPS, "find status about home directory", 
			    strerror(errno));
			exit( EX_HOMEDIR );
		}
			
		if( check_perm( statbuf, pstruct->pw_uid, pstruct->pw_gid,
		    S_IWOTH|S_IXOTH ) != 0 ) {
			errmsg( M_NO_PERM, logname, pstruct->pw_dir );
			exit( EX_HOMEDIR );
		}

		if( rm_files(pstruct->pw_dir, logname) != EX_SUCCESS ) 
			exit( EX_HOMEDIR );
	}

	/* now call passmgmt */
	ret = PEX_FAILED;
	for( tries = 3; ret != PEX_SUCCESS && tries--; ) {
		switch( ret = call_passmgmt( nargv ) ) {
		case PEX_SUCCESS:
			ret = edit_group( logname, (char *)0, (int **)0, 1 );
			if( ret != EX_SUCCESS )
				errmsg( M_UPDATE, "deleted" );
			break;

		case PEX_BUSY:
			break;

		case PEX_HOSED_FILES:
			errmsg( M_HOSED_FILES );
			exit( EX_INCONSISTENT );
			break;

		case PEX_SYNTAX:
		case PEX_BADARG:
			/* should NEVER occur that passmgmt usage is wrong */
			if (is_role(usertype))
				errmsg( M_DRUSAGE );
			else
				errmsg( M_DUSAGE );
			exit( EX_SYNTAX );
			break;

		case PEX_BADUID:
			/* uid is used - shouldn't happen but print message anyway */
			errmsg( M_UID_USED, pstruct->pw_uid );
			exit( EX_ID_EXISTS );
			break;

		case PEX_BADNAME:
			/* invalid loname */
			errmsg( M_USED, logname);
			exit( EX_NAME_EXISTS );
			break;

		default:
			errmsg( M_UPDATE, "deleted" );
			exit( ret );
			break;
		}
	}
	if( tries == 0 ) 
		errmsg( M_UPDATE, "deleted" );

/*
 * Now, remove this user from all project entries
 */

	rc = edit_project(logname, (char *)0, (projid_t **)0, 1);
	if (rc != EX_SUCCESS) {
		errmsg(M_UPDATE, "modified");
		exit(rc);
	}
	
	exit( ret );
	/*NOTREACHED*/
}
示例#3
0
文件: main.C 项目: glycerine/shore-mt
int main(int argc, char **argv) {
	GetOpt opt(argc,argv,"8vfcSLBDs:l:b:d:o:r:");
	int c, rc;
	argv0 = argv[0];
	while ((c = opt()) != EOF) {
		switch (c) {
			case '8': // 8 byte serial #; for janet only.
				long_oids = 1;
			break;
			case 'v': // verbose
				verbose_flag = 1;
			break;
			case 'f' : //  overwrite existing module if found.
				overwrite_module = 1;
			break;
			case 'c' : //  syntax check only
				scheck_only = 1;
			break;
			case 'S': // read from standard input
				src_args[src_count++] = "-";
			break;
			case 'B': // print out language binding for all modules processed.
				bind_all = 1;
			break;
			case 'L': // link all modules processed  (from source).
				link_all = 1;
			break;
			case 'D':
				debug++;
			break;
			case 's':
				src_args[src_count++] = opt.optarg;
			break;
			case 'r':
				rm_args[rm_count++] = opt.optarg;
			break;
			case 'l':
				link_args[link_count++] = opt.optarg;
			break;
			case 'b':
				bind_args[bind_count++] = opt.optarg;
			break;
			case 'd':
				dir_args[dir_count++] = opt.optarg;
			break;
			case 'o':
				if (output_arg)	
				{
					cerr << "only one output file name allowed" <<endl;
					usage(argv[0]);
				}
				output_arg = opt.optarg;
			break;
			default:
				usage(argv[0]);
				return 1;
		}
	}
	int i;
	if (debug || verbose_flag) {
		fprintf(stderr,"sdl: command line was\n\t");
		for (i = 0; i < argc; i++)
			fprintf(stderr,"%s ",argv[i]);
		fprintf(stderr,"\n");

		if (src_count>0)
		{
			fprintf(stderr,"compiling sdl source files: ");
			for (i = 0; i<src_count; i++)
				fprintf(stderr,"%s ",src_args[i]);
			fprintf(stderr,"\n");
		}
		if (link_count>0)
		{
			fprintf(stderr,"linking moudles: ");
			for (i = 0; i<link_count; i++)
				fprintf(stderr,"%s ",link_args[i]);
			fprintf(stderr,"\n");
		}
		if (bind_count>0)
		{
			fprintf(stderr,"creating language binding for modules: ");
			for (i = 0; i<bind_count; i++)
				fprintf(stderr,"%s ",bind_args[i]);
			fprintf(stderr,"\n");
		}
		if (dir_count>0)
		{
			fprintf(stderr,"shore directory search path: ");
			for (i = 0; i<dir_count; i++)
				fprintf(stderr,"%s ",dir_args[i]);
			fprintf(stderr,"\n");
		}
		if ( bind_all)
			fprintf(stderr,"-B: printing language binding for all source processed\n");
		if ( link_all)
			fprintf(stderr,"-L: linking modules for all source processed\n");
		if ( overwrite_module)
			fprintf(stderr,"-f: deleting existing modules\n");
		if (scheck_only)
			fprintf(stderr,"-c: syntax check only\n");


	}
	// initialization:
	if (!scheck_only)
		metaobj_init(argc,argv);
	if (src_count)
		insert_rwords();
	if (dir_count)
	{
		w_rc_t crc;
		for (i=0; i<dir_count; i++)
			add_dir(dir_args[i]);
		// also, chdir to 1st dir arg, creating it if necessary.
		W_COERCE(Shore::begin_transaction(3));
		crc = Shore::chdir(dir_args[0]);
		if (crc)
		{
			if (crc.err_num() != SH_NotFound)
				crc.fatal(); //give up
			SH_DO(Shore::mkdir(dir_args[0],0755));
			SH_DO(Shore::chdir(dir_args[0]));
		}
		SH_DO(SH_COMMIT_TRANSACTION);
	}
	// first, remove anything specified by -r
	if (rm_count >0)
		rm_files(rm_count,rm_args);
		
	for (i = 0; i<src_count; i++) {
		if ((rc = process_src( src_args[i])))
			return rc;
		if (sdl_errors)
		{
			fprintf(stderr,"found %d errors processing sdl source file %s\n",
				sdl_errors,src_args[i]);
			return sdl_errors;
		}
	}
	if (src_count && (g_module_list!= 0)) // say what we created
	{
		char * m_dir = dir_count? dir_args[0]: "/types";
		W_COERCE(Shore::begin_transaction(3));
		Ref<sdlDeclaration> lpt;

		for (lpt = g_module_list; lpt != NULL; lpt = lpt->next)
			fprintf(stderr,"created module 	%s/%s\n",m_dir,(char *)lpt->name);
		SH_DO(SH_COMMIT_TRANSACTION);
	}
	if ( scheck_only && (link_count || bind_all || bind_count))
	{
		fprintf(stderr,"cannot link or bind with -c flag\n");
		return sdl_errors;
	}
	if (link_all)
		if (rc = link_all_modules())
			return rc;
	for (i = 0; i < link_count; i++) {
		if ((rc = process_link( link_args[i])))
			return rc;
	}
	if (bind_all) //orint all bindings from src module list
		if (rc = print_all_bindings())
			return rc;
	if (bind_count == 1) // old style binding printout
	{
		if ((rc = process_bind(bind_args[i])))
			return rc;
	}
	else if (bind_count > 0)
	{
		Set<Ref<sdlModule> > omods;
		W_COERCE(Shore::begin_transaction(3));
		
		for (i = 0; i < bind_count; i++) 
		{
			Ref<sdlModule> bmod;
			bmod = lookup_module(bind_args[i]);
			if (bmod == 0) // null value
			{
				cerr << "couldn't find module " <<  bind_args[i] << endl;
				break;
			}
			omods.add(bmod);
		}
		if (omods.get_size()>0 
			&& open_output_file(omods.get_elt(0)->name.string()) == 0)
				print_cxx_binding(omods);
		W_COERCE(SH_COMMIT_TRANSACTION);
	}
	return sdl_errors;
}