示例#1
0
int main(int argc, char *argv[]) {

	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);

	bzero(tmp_file, FILENAMELEN);
	progname = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
	if (!strcmp(progname, "vigr")) {
		program = VIGR;
		xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file));
		xstrncpy(tmp_file, GTMP_FILE, sizeof(tmp_file));
		xstrncpy(tmptmp_file, GTMPTMP_FILE, sizeof(tmptmp_file));
	} else {
		program = VIPW;
		xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file));
		xstrncpy(tmp_file, PTMP_FILE, sizeof(tmp_file));
		xstrncpy(tmptmp_file, PTMPTMP_FILE, sizeof(tmptmp_file));
	}

	if ((argc > 1) && 
	    (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version"))) {
		printf("%s\n", version_string);
		exit(0);
	}

	edit_file(0);

	if (program == VIGR) {
		strncpy(orig_file, SGROUP_FILE, FILENAMELEN-1);
		strncpy(tmp_file, SGTMP_FILE, FILENAMELEN-1);
		strncpy(tmptmp_file, SGTMPTMP_FILE, FILENAMELEN-1);
	} else {
		strncpy(orig_file, SHADOW_FILE, FILENAMELEN-1);
		strncpy(tmp_file, SPTMP_FILE, FILENAMELEN-1);
		strncpy(tmptmp_file, SPTMPTMP_FILE, FILENAMELEN-1);
	}

	if (access(orig_file, F_OK) == 0) {
		char response[80];

		printf((program == VIGR)
		       ? _("You are using shadow groups on this system.\n")
		       : _("You are using shadow passwords on this system.\n"));
		printf(_("Would you like to edit %s now [y/n]? "), orig_file);

		/* EOF means no */
		if (fgets(response, sizeof(response), stdin)) {
			if (response[0] == 'y' || response[0] == 'Y')
				edit_file(1);
		}
	}

	exit(0);
}
示例#2
0
文件: vipw.c 项目: hallyn/util-linux
int main(int argc, char *argv[])
{
	setlocale(LC_ALL, "");
	bindtextdomain(PACKAGE, LOCALEDIR);
	textdomain(PACKAGE);
	atexit(close_stdout);

	if (!strcmp(program_invocation_short_name, "vigr")) {
		program = VIGR;
		xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file));
	} else {
		program = VIPW;
		xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file));
	}

	if (1 < argc) {
		if (!strcmp(argv[1], "-V") || !strcmp(argv[1], "--version")) {
			printf(UTIL_LINUX_VERSION);
			exit(EXIT_SUCCESS);
		}
		if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
			usage(stdout);
		usage(stderr);
	}

	edit_file(0);

	if (program == VIGR) {
		strncpy(orig_file, SGROUP_FILE, FILENAMELEN - 1);
	} else {
		strncpy(orig_file, SHADOW_FILE, FILENAMELEN - 1);
	}

	if (access(orig_file, F_OK) == 0) {
		char response[80];

		printf((program == VIGR)
		       ? _("You are using shadow groups on this system.\n")
		       : _("You are using shadow passwords on this system.\n"));
		/* TRANSLATORS: this program uses for y and n rpmatch(3),
		 * which means they can be translated. */
		printf(_("Would you like to edit %s now [y/n]? "), orig_file);

		if (fgets(response, sizeof(response), stdin)) {
			if (rpmatch(response) == RPMATCH_YES)
				edit_file(1);
		}
	}
	exit(EXIT_SUCCESS);
}
示例#3
0
文件: fulled.c 项目: maccasoft/lora2
void fullscreen_editor (void)
{
   char *p = "\026\001\020\234^X=Down  ^E=Up  ^S=Left  ^D=Right  ^Z=Save  ^K?=Help";

   cls();

   change_attr (BLUE|_LGREY);
   del_line ();
   m_print (" * %s\n", sys.msg_name);

   msg_attrib (&msg, last_msg + 1, 0, 0);

   change_attr (RED|_BLUE);
   del_line ();
   cpos (5, (usr.width ? usr.width : 80) - strlen (p) - 1 + 4);
   m_print (p);

   change_attr (CYAN|_BLACK);
   m_print (bbstxt[B_ONE_CR]);

   fulleditor = 1;
   XON_DISABLE ();
   _BRK_DISABLE ();

   edit_file ("MSGTMP", usr.len - 5, usr.width ? (usr.width - 1) : 79);

   fulleditor = 0;
   XON_ENABLE ();
   _BRK_ENABLE ();
}
示例#4
0
void
edit_file_at_line (const vfs_path_t * what_vpath, gboolean internal, long start_line)
{

#ifdef USE_INTERNAL_EDIT
    if (internal)
        edit_file (what_vpath, start_line);
    else
#endif /* USE_INTERNAL_EDIT */
    {
        static const char *editor = NULL;

        (void) internal;

        if (editor == NULL)
        {
            editor = getenv ("EDITOR");
            if (editor == NULL)
                editor = get_default_editor ();
        }

        execute_external_editor_or_viewer (editor, what_vpath, start_line);
    }

    if (mc_global.mc_run_mode == MC_RUN_FULL)
        update_panels (UP_OPTIMIZE, UP_KEEPSEL);

#ifdef USE_INTERNAL_EDIT
    if (use_internal_edit)
        dialog_switch_process_pending ();
    else
#endif /* USE_INTERNAL_EDIT */
        repaint_screen ();
}
/****
* Retrieve the currently selected file and display it in the configured
* editor.
****/
static void
get_selected_file(HWND hDlg, int command_id)
{
	int index;
	char szBuf[MAXPATHLEN];

	/* get currently selected item */
	index = (int)SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX,
		LB_GETCURSEL, 0, 0L);
	if(index == LB_ERR && command_id == IDC_MAIN_EDIT)
	{
		ErrHandler(hDlg, R_WARNING, RB_OK1, "Nothing selected. Please "
			"select a file from the list");
		return;
	}

	/* empty listbox */
	if(index == LB_ERR)
		return;

	/* get name of selected file */
	SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX, LB_GETTEXT, index, 
		(LONG)(LPSTR)szBuf);
	switch(command_id)
	{
		case IDC_MAIN_EDIT:
		case IDC_MAIN_LISTBOX:
			edit_file(szBuf, 0);
			break;
		case IDC_MAIN_REMOVE:
			file_sel_changed = 1;
			SendDlgItemMessage(hDlg, IDC_MAIN_LISTBOX,
				LB_DELETESTRING, index, 0L);
	}
}
示例#6
0
/*
**  create_comment ()
*/
STATUS
create_comment ()
{
    STATUS                 ret_val ;
    FILE                  *tmpf = NULL ;

    if ((ret_val = bld_cmtName(msg)) != OK)
    {
        disp_line(msg, 0, 0);
    }
    else
    {
        if (SIfopen(cmtLoc, ERx("a"), SI_TXT, TERM_LINE, &tmpf) == OK)
        {
            SIclose(tmpf);
        }
        edit_file(cmtName);
        fix_cursor();
        TDclear(curscr);
        TDtouchwin(mainW);
        TDrefresh(mainW);
    }

    return (ret_val);

} /* end of create_comment */
示例#7
0
void
do_edit_at_line (const char *what, gboolean internal, int start_line)
{
    static const char *editor = NULL;

#ifdef USE_INTERNAL_EDIT
    if (internal)
        edit_file (what, start_line);
    else
#else
    (void) start_line;
#endif /* USE_INTERNAL_EDIT */
    {
        if (editor == NULL)
        {
            editor = getenv ("EDITOR");
            if (editor == NULL)
                editor = get_default_editor ();
        }
        execute_with_vfs_arg (editor, what);
    }

    if (mc_global.mc_run_mode == MC_RUN_FULL)
        update_panels (UP_OPTIMIZE, UP_KEEPSEL);

#ifdef USE_INTERNAL_EDIT
    if (use_internal_edit)
        dialog_switch_process_pending ();
    else
#endif /* USE_INTERNAL_EDIT */
        repaint_screen ();
}
示例#8
0
文件: misc.c 项目: 8l/ted
K_EditFName(char *s)
{
save_edstate();
#if	0
strcpy(fname,s);
#endif
edit_file(s);
return 0;
}
示例#9
0
void Ozette::open_file() {
	Dialog::Form dialog;
	dialog.fields = {
		{"Open", "", &Path::complete_file}
	};
	dialog.commit = [this](UI::Frame &ctx, Dialog::Form::Result &res) {
		std::string path = res.selected_value;
		if (path.empty()) return;
		edit_file(path);
	};
	dialog.show(*_shell.active());
}
示例#10
0
int main(void) {


  // following functions implement the most basic file i/o functionalities

  read_file();
  edit_file();
  create_file();

  


  return 0;

}
示例#11
0
文件: misc.c 项目: 8l/ted
K_GotoGrep(int replace)
{
char *ss=edbf[cursor_row].cstr;
int len=edbf[cursor_row].len;
char *p,*q,*fn,*t;
int row,i;
char s[2048];

if (!ss||!len) return;
memcpy(s,ss,len);
if (!(p=strchr(s,':'))) return;
t=p-1;
while (*t==' ') t--;
t++;
*t=0;
p++;
fn=s;
if (!(q=strchr(p,':'))) return;
*q=0;
while(*p==' ') p++;
#if	0
printf("--%s---%s---\n",fn,p);
#endif
row=atoi(p);
row--;

for(i=0;i<file_no;i++) {
	if (!strcmp(edstate[i].fname,fn)) break;
}
if (i<file_no) {
	goto_file(i);
	goto_line(row);
	return;
}
if (replace) {
	nosave=1;
	close_file_noexit();
}
save_edstate();
#if	0
strcpy(fname,fn);
#endif
edit_file(fn);
goto_line(row);
}
示例#12
0
int main(int argc, char **argv)
{
    char *pl_filename, *gl_filename;

#ifdef NBR
    getpath();
#endif

    if (argc > 3) {
	usage(argv[0]);
	exit(2);
    }

    if (argc >= 2)
	pl_filename = argv[1];
    else
#ifdef NBR
	pl_filename = PlayerFile;
#else
	pl_filename = PLAYERFILE;
#endif
    if (argc == 3)
	gl_filename = argv[2];
    else
#ifdef NBR
	gl_filename = GLOBAL;
#else
	gl_filename = Global;
#endif

    signal(SIGINT, signal_handler);

    /* init curses */
    if (initscr() == NULL) {
	fprintf(stderr, "Unable to initialize curses\n");
	exit(1);
    }

    edit_file(pl_filename, gl_filename);

    /* shut down curses */
    endwin();
    exit(0);
    /*NOTREACHED*/
}
示例#13
0
文件: misc.c 项目: 8l/ted
K_EditMarkWord()
{
char tfname[128];
struct stat fst;

if (!GetMarkWord(tfname)) return;
save_edstate();
if (stat(tfname,&fst)<0) return;
if (S_ISDIR(fst.st_mode)) {
	K_CD(tfname);
}
else	{
#if	0
	strcpy(fname,tfname);
#endif
	edit_file(tfname);
}
return 0;
}
示例#14
0
文件: file.c 项目: Noclip21/cliaspora
char *
get_input(bool fromstdin)
{
	int  c;
	FILE *fp;
	char *path, *buf;

	if (fromstdin) {
		if ((buf = read_file(stdin)) == NULL)
			errx(EXIT_FAILURE, "Failed to read file");
		return (buf);
	}
	if (have_postponed()) {
		do {
			(void)fputs("\nEdit postponed file? (y/n) ", stderr);
			c = tolower(fgetc(stdin));
		} while (c != 'y' && c != 'n');
		if (c == 'y')
			path = get_postponed_path();
		else
			path = NULL;
	} else
		path = NULL;
	do {
		path = edit_file(path);
		if (path == NULL)
			errx(EXIT_FAILURE, "Failed to edit file");
		else
			write_postponed(path);
		do {
			(void)fputs("\nReady to send? (y/n) ", stderr);
			c = tolower(fgetc(stdin));
		} while (c != 'y' && c != 'n');
	} while (c != 'y');
	if ((fp = fopen(path, "r")) == NULL)
		err(EXIT_FAILURE, "fopen(%s)", path);
	if ((buf = read_file(fp)) == NULL)
		errx(EXIT_FAILURE, "Failed to read file");
	delete_tmpfile();
	return (buf);
}
示例#15
0
void do_edit_at_line (const char *what, int start_line)
{
    static const char *editor = NULL;

#ifdef USE_INTERNAL_EDIT
    if (use_internal_edit){
	edit_file (what, start_line);
	update_panels (UP_OPTIMIZE, UP_KEEPSEL);
	repaint_screen ();
	return;
    }
#endif /* USE_INTERNAL_EDIT */
    if (!editor){
	editor = getenv ("EDITOR");
	if (!editor)
	    editor = get_default_editor ();
    }
    execute_with_vfs_arg (editor, what);
    update_panels (UP_OPTIMIZE, UP_KEEPSEL);
    repaint_screen ();
}
示例#16
0
文件: filebrowse.c 项目: 8l/ted
static void open_file(char *s)
{
int i;

if (extend_edstate()) return;

hide_cursor_w();
if(!s[0]) return;
save_edstate();
s=decode_dir(s);
for(i=0;i<file_no;i++)
if (!strcmp(s,edstate[i].fname)) {
	goto_file(i);
	return;
}
#if	0
strcpy(fname,s);
#endif
edit_file(s);
disp_win_title();
}
示例#17
0
文件: server.c 项目: Nienzu/oshw
int main(){
	int socket_fd;
	struct sockaddr_in dest;
	char buffer[B_SIZE];
	socket_fd = socket(PF_INET, SOCK_STREAM, 0);

	bzero(&dest, sizeof(dest));
	dest.sin_family = PF_INET;
	dest.sin_port = htons(8889);
	dest.sin_addr.s_addr = htonl(INADDR_ANY);

	bind(socket_fd, (struct sockaddr*)&dest, sizeof(dest));

	listen(socket_fd, 20);
	FILE *fp;
	bzero(&buffer, B_SIZE);
	
	int client;
	struct sockaddr_in client_addr;
	socklen_t addlen;
	addlen = sizeof(client_addr);
	client = accept(socket_fd, (struct sockaddr*)&client_addr, &addlen);
	
	int check=0;
	char command='\0';
	while(1){
		bzero(&buffer, B_SIZE);  /*always clear the buffer*/
		recv(client, &command, sizeof(command), 0);
		switch(command){
		case 'c':
			recv(client, &buffer, B_SIZE, 0);
			check = check_file(client, buffer);
			//only when file doesn't exist, server will create the file.
			if(check == -1){
				fp = fopen(buffer, "w");
				fclose(fp);
				break;
			}
		case 'e':
			edit_file(client);
			break;
		case 'r':
			/* Here is the remove function. */
			recv(client, &buffer, B_SIZE, 0);
			check = check_file(client, buffer);
			if(check==1)
				remove(buffer);
			break;
		case 'l':
			list_file(client);
			break;
		case 'd':
			trans_file(client);
			break;
		case 'q':
			break;		
		}
		if(command == 'q')
			break;
	}
	close(socket_fd);	
	return 0;
}
示例#18
0
int crontab_main(int argc UNUSED_PARAM, char **argv)
{
	const struct passwd *pas;
	const char *crontab_dir = CRONTABS;
	char *tmp_fname;
	char *new_fname;
	char *user_name;  /* -u USER */
	int fd;
	int src_fd;
	int opt_ler;

	/* file [opts]     Replace crontab from file
	 * - [opts]        Replace crontab from stdin
	 * -u user         User
	 * -c dir          Crontab directory
	 * -l              List crontab for user
	 * -e              Edit crontab for user
	 * -r              Delete crontab for user
	 * bbox also supports -d == -r, but most other crontab
	 * implementations do not. Deprecated.
	 */
	enum {
		OPT_u = (1 << 0),
		OPT_c = (1 << 1),
		OPT_l = (1 << 2),
		OPT_e = (1 << 3),
		OPT_r = (1 << 4),
		OPT_ler = OPT_l + OPT_e + OPT_r,
	};

	opt_complementary = "?1:dr"; /* max one argument; -d implies -r */
	opt_ler = getopt32(argv, "u:c:lerd", &user_name, &crontab_dir);
	argv += optind;

	if (sanitize_env_if_suid()) { /* Clears dangerous stuff, sets PATH */
		/* run by non-root? */
		if (opt_ler & (OPT_u|OPT_c))
			bb_error_msg_and_die("only root can use -c or -u");
	}

	if (opt_ler & OPT_u) {
		pas = getpwnam(user_name);
		if (!pas)
			bb_error_msg_and_die("user %s is not known", user_name);
	} else {
/* XXX: xgetpwuid */
		uid_t my_uid = getuid();
		pas = getpwuid(my_uid);
		if (!pas)
			bb_perror_msg_and_die("unknown uid %d", (int)my_uid);
	}

#define user_name DONT_USE_ME_BEYOND_THIS_POINT

	/* From now on, keep only -l, -e, -r bits */
	opt_ler &= OPT_ler;
	if ((opt_ler - 1) & opt_ler) /* more than one bit set? */
		bb_show_usage();

	/* Read replacement file under user's UID/GID/group vector */
	src_fd = STDIN_FILENO;
	if (!opt_ler) { /* Replace? */
		if (!argv[0])
			bb_show_usage();
		if (NOT_LONE_DASH(argv[0])) {
			src_fd = open_as_user(pas, argv[0]);
			if (src_fd < 0)
				bb_error_msg_and_die("user %s cannot read %s",
						pas->pw_name, argv[0]);
		}
	}

	/* cd to our crontab directory */
	xchdir(crontab_dir);

	tmp_fname = NULL;

	/* Handle requested operation */
	switch (opt_ler) {

	default: /* case OPT_r: Delete */
		unlink(pas->pw_name);
		break;

	case OPT_l: /* List */
		{
			char *args[2] = { pas->pw_name, NULL };
			return bb_cat(args);
			/* list exits,
			 * the rest go play with cron update file */
		}

	case OPT_e: /* Edit */
		tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid());
		/* No O_EXCL: we don't want to be stuck if earlier crontabs
		 * were killed, leaving stale temp file behind */
		src_fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600);
		fchown(src_fd, pas->pw_uid, pas->pw_gid);
		fd = open(pas->pw_name, O_RDONLY);
		if (fd >= 0) {
			bb_copyfd_eof(fd, src_fd);
			close(fd);
			xlseek(src_fd, 0, SEEK_SET);
		}
		close_on_exec_on(src_fd); /* don't want editor to see this fd */
		edit_file(pas, tmp_fname);
		/* fall through */

	case 0: /* Replace (no -l, -e, or -r were given) */
		new_fname = xasprintf("%s.new", pas->pw_name);
		fd = open(new_fname, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600);
		if (fd >= 0) {
			bb_copyfd_eof(src_fd, fd);
			close(fd);
			xrename(new_fname, pas->pw_name);
		} else {
			bb_error_msg("cannot create %s/%s",
					crontab_dir, new_fname);
		}
		if (tmp_fname)
			unlink(tmp_fname);
		/*free(tmp_fname);*/
		/*free(new_fname);*/

	} /* switch */

	/* Bump notification file.  Handle window where crond picks file up
	 * before we can write our entry out.
	 */
	while ((fd = open(CRONUPDATE, O_WRONLY|O_CREAT|O_APPEND, 0600)) >= 0) {
		struct stat st;

		fdprintf(fd, "%s\n", pas->pw_name);
		if (fstat(fd, &st) != 0 || st.st_nlink != 0) {
			/*close(fd);*/
			break;
		}
		/* st.st_nlink == 0:
		 * file was deleted, maybe crond missed our notification */
		close(fd);
		/* loop */
	}
	if (fd < 0) {
		bb_error_msg("cannot append to %s/%s",
				crontab_dir, CRONUPDATE);
	}
	return 0;
}
示例#19
0
STATUS
disp_diff(STATUS acmmt,i4 canons)
{
    STATUS                 ioerr ;
    STATUS                 up_canon = FAIL ;
    char                   cmmtfile [50] ;
    char                   canon_upd = '\0' ;
    char                   junk ;
    char                   menu_ans ;
    bool                   conditional_exp ;

    /* initialize diff window */

    conditional_exp = FALSE;
#ifndef NT_GENERIC
    TEwrite(CL,STlength(CL));
    TEflush();
#endif
    diffW = TDnewwin(MAIN_ROWS,MAIN_COLS,FIRST_MAIN_ROW,FIRST_MAIN_COL);
    diffstW = TDnewwin(STATUS_ROWS,STATUS_COLS,FIRST_STAT_ROW,FIRST_MAIN_COL);
    TDrefresh(diffstW);
    TDrefresh(diffW);

    screenLine = 0;
    old_page = 0;
    bottom_page = 0;
    myPages = NULL;
    ioerr = OK;

    STprintf(cmmtfile,ERx("ct%s.stf"),SEPpidstr);
    diffPtr = sepDiffer->_fptr;

    /*
    **	display diff
    */

    page_down(0);
    if (updateMode)
	    up_canon = OK;

    for (;;)
    {
	if (updateMode)
	{
	    if (editCAns == '\0')
		disp_prompt(DIFF_MENU_M,&menu_ans,DIFF_MENU_AM);
	    else
		menu_ans = 'e';
	}
	else
	    disp_prompt(DIFF_MENU,&menu_ans,DIFF_MENU_A);

	switch (menu_ans)
	{
	   case 'A': case 'a':
		    ioerr = FAIL;
		    break;
	   case 'P': case 'p':
		    page_up();
		    break;
	   case 'N': case 'n':
		    page_down(0);
		    break;
	   case 'C': case 'c':
		    if (acmmt == FAIL && !updateMode)
			disp_prompt(ERx("no comments attached to this command"),
			    &junk,NULL);
		    else
		    {
			edit_file(cmmtfile);
			TDtouchwin(diffW);
			TDrefresh(diffW);
		    }
		    break;
	   case 'E': case 'e':
		    if (up_canon == OK)
		    {
			if (editCAns == '\0')
			{
			    disp_prompt(UPD_CANON,&canon_upd,UPD_CANON_A);
			}
			else
			{
			    canon_upd = editCAns;
			    menu_ans = 'q';
			}

			if (canon_upd == 'M' || canon_upd == 'A' ||
			    canon_upd == 'm' || canon_upd == 'a' )
			    conditional_exp = ask_for_conditional(diffstW,
								  editCAns);

			up_canon = FAIL;
		    }
		    break;
	}
	if (menu_ans == 'Q' || menu_ans == 'q' ||
	    menu_ans == 'A' || menu_ans == 'a' ||
	    menu_ans == 'D' || menu_ans == 'd')
	{
	    disp_prompt(NULLSTR,NULL,NULL);
	    SEPdisconnect = (menu_ans == 'A' || menu_ans == 'a' ||
			     menu_ans == 'D' || menu_ans == 'd');
	    break;
	}
    }

    /*
    **	update test
    */

    if (updateMode)
    {
	LOCATION	cmmtloc;
	short	count;

	/* add comments */

	LOfroms(FILENAME & PATH,cmmtfile,&cmmtloc);
	if (SEP_LOexists(&cmmtloc))
	{
	    append_line(OPEN_COMMENT,1);
	    append_file(cmmtfile);
	    append_line(CLOSE_COMMENT,1);
	    LOdelete(&cmmtloc);
	}

	/* add canons   */
	    
	switch (canon_upd)
	{
	   case 'I':
	   case 'i':
		    append_line(OPEN_CANON,1);
		    append_line(SKIP_SYMBOL,1);
		    append_line(CLOSE_CANON,1);
		    break;
	   case 'M':
	   case 'm':
		    SEPrewind(sepResults, FALSE);
		    if (conditional_exp == TRUE)
		    {
			append_line(OPEN_CANON,0);
			append_line(conditional_prompt,1);
		    }
 		    else
			append_line(OPEN_CANON,1);

		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    append_sepfile(sepGCanons);
		    break;
	   case 'O':
	   case 'o':
		    SEPrewind(sepResults, FALSE);
		    append_line(OPEN_CANON,1);
		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    break;
	   case '\0':
	   case 'E':
	   case 'e':
		    append_sepfile(sepGCanons);
		    break;
	   case 'A':
	   case 'a':
		    append_sepfile(sepGCanons);
		    SEPrewind(sepResults, FALSE);
		    if (conditional_exp == TRUE)
		    {
			append_line(OPEN_CANON,0);
			append_line(conditional_prompt,1);
		    }
		    else
			append_line(OPEN_CANON,1);

		    append_sepfile(sepResults);
		    append_line(CLOSE_CANON,1);
		    break;
	}
    }
    MEtfree(SEP_ME_TAG_PAGES);
    TDdelwin(diffW);
    TDdelwin(diffstW);
    return(ioerr);
}
示例#20
0
int
main(int argc, char **argv)
{

#ifdef HAVE_LIBPAM
    int    retcode = 0;
    const char * const * env;
#endif
#ifdef USE_SETE_ID
    struct passwd *pass;
#endif

    memset(buf, 0, sizeof(buf));
    memset(file, 0, sizeof(file));

    if (strrchr(argv[0],'/')==NULL) prog_name = argv[0];
    else prog_name = strrchr(argv[0],'/')+1;
    
    uid = getuid();

    /* get current dir */
    if ( getcwd(orig_dir, sizeof(orig_dir)) == NULL )
	die_e("getcwd");

    /* interpret command line options */
    parseopt(argc, argv);

#ifdef USE_SETE_ID
    if ( ! (pass = getpwnam(USERNAME)) )
	die("user \"%s\" is not in passwd file. Aborting.", USERNAME);
    fcrontab_uid = pass->pw_uid;
    fcrontab_gid = pass->pw_gid;

#ifdef HAVE_LIBPAM
    /* Open PAM session for the user and obtain any security
       credentials we might need */

    debug("username: %s", user);
    retcode = pam_start("fcrontab", user, &apamconv, &pamh);
    if (retcode != PAM_SUCCESS) die_pame(pamh, retcode, "Could not start PAM");
    retcode = pam_authenticate(pamh, 0);    /* is user really user? */
    if (retcode != PAM_SUCCESS)
	die_pame(pamh, retcode, "Could not authenticate user using PAM (%d)", retcode);
    retcode = pam_acct_mgmt(pamh, 0); /* permitted access? */
    if (retcode != PAM_SUCCESS)
	die_pame(pamh, retcode, "Could not init PAM account management (%d)", retcode);
    retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED);
    if (retcode != PAM_SUCCESS) die_pame(pamh, retcode, "Could not set PAM credentials");
    retcode = pam_open_session(pamh, 0);
    if (retcode != PAM_SUCCESS) die_pame(pamh, retcode, "Could not open PAM session");

    env = (const char * const *) pam_getenvlist(pamh);
    while (env && *env) {
	if (putenv((char*) *env)) die_e("Could not copy PAM environment");
	env++;
    }

    /* Close the log here, because PAM calls openlog(3) and
       our log messages could go to the wrong facility */
    xcloselog();
#endif /* USE_PAM */

    if (uid != fcrontab_uid)
	if (seteuid(fcrontab_uid) != 0) 
	    die_e("Couldn't change euid to fcrontab_uid[%d]",fcrontab_uid);
    /* change directory */
    if (chdir(fcrontabs) != 0) {
	error_e("Could not chdir to %s", fcrontabs);
	xexit (EXIT_ERR);
    }
    /* get user's permissions */
    if (seteuid(uid) != 0) 
	die_e("Could not change euid to %d", uid); 
    if (setegid(fcrontab_gid) != 0) 
	die_e("Could not change egid to " GROUPNAME "[%d]", fcrontab_gid); 

#else /* USE_SETE_ID */

    if (setuid(ROOTUID) != 0 ) 
	die_e("Could not change uid to ROOTUID"); 
    if (setgid(ROOTGID) != 0)
    	die_e("Could not change gid to ROOTGID");
    /* change directory */
    if (chdir(fcrontabs) != 0) {
	error_e("Could not chdir to %s", fcrontabs);
	xexit (EXIT_ERR);
    }
#endif /* USE_SETE_ID */
    
    /* this program is seteuid : we set default permission mode
     * to 640 for a normal user, 600 for root, for security reasons */
    if ( asuid == ROOTUID )
	umask(066);  /* octal : '0' + number in octal notation */
    else
	umask(026);

    snprintf(buf, sizeof(buf), "%s.orig", user);

    /* determine what action should be taken */
    if ( file_opt ) {

	if ( strcmp(argv[file_opt], "-") == 0 )

	    xexit(install_stdin());

	else {

	    if ( *argv[file_opt] != '/' )
		/* this is just the file name, not the path : complete it */
		snprintf(file, sizeof(file), "%s/%s", orig_dir, argv[file_opt]);
	    else {
		strncpy(file, argv[file_opt], sizeof(file) - 1);
		file[sizeof(file)-1] = '\0';
	    }

	    if (make_file(file) == OK)
		xexit(EXIT_OK);
	    else
		xexit(EXIT_ERR);

	}

    } 

    /* remove user's entries */
    if ( rm_opt == 1 ) {
	if ( remove_fcrontab(1) == ENOENT )
	    fprintf(stderr, "no fcrontab for %s\n", user);
	xexit (EXIT_OK);
    }

    /* list user's entries */
    if ( list_opt == 1 ) {
	list_file(buf);
	xexit(EXIT_OK);
    }


    /* edit user's entries */
    if ( edit_opt == 1 ) {
	edit_file(buf);
	xexit(EXIT_OK);
    }

    /* reinstall user's entries */
    if ( reinstall_opt == 1 ) {
	reinstall(buf);
	xexit(EXIT_OK);
    }

    /* never reached */
    return EXIT_OK;
}
示例#21
0
static bool HandleClient(t_x11 *x11, int ID, t_gmx *gmx)
{
    t_pulldown *pd;

    pd = gmx->pd;

    switch (ID)
    {
        /* File Menu */
        case IDDUMPWIN:
            write_gmx(x11, gmx, IDDODUMP);
            break;
        case IDDODUMP:
            if (gmx->man->bAnimate)
            {
                hide_but(x11, gmx->man->vbox);
            }
            dump_it(gmx->man);
            if (gmx->man->bAnimate)
            {
                show_but(x11, gmx->man->vbox);
            }
            break;
        case IDCLOSE:
        case IDIMPORT:
        case IDEXPORT:
            ShowDlg(gmx->dlgs[edExport]);
            break;
        case IDDOEXPORT:
            write_sto_conf(gmx->confout, *gmx->man->top.name,
                           &(gmx->man->top.atoms),
                           gmx->man->x, NULL, gmx->man->molw->ePBC, gmx->man->box);
            break;
        case IDQUIT:
            show_mb(gmx, emQuit);
            break;
        case IDTERM:
            done_gmx(x11, gmx);
            return true;

        /* Edit Menu */
        case IDEDITTOP:
            edit_file("topol.gmx");
            break;
        case IDEDITCOORDS:
            edit_file("confin.gmx");
            break;
        case IDEDITPARAMS:
            edit_file("mdparin.gmx");
            break;

        /* Display Menu */
        case IDFILTER:
            if (gmx->filter)
            {
                ShowDlg(gmx->dlgs[edFilter]);
            }
            break;
        case IDDOFILTER:
            do_filter(x11, gmx->man, gmx->filter);
            break;
        case IDANIMATE:
            check_pd_item(pd, IDANIMATE, toggle_animate(x11, gmx->man));
            break;
        case IDLABELSOFF:
            no_labels(x11, gmx->man);
            break;
        case IDRESETVIEW:
            reset_view(gmx->man->view);
            ExposeWin(x11->disp, gmx->man->molw->wd.self);
            break;
        case IDPHOTO:
            show_mb(gmx, emNotImplemented);
            break;
        case IDBONDOPTS:
            ShowDlg(gmx->dlgs[edBonds]);
            break;
        case IDTHIN:
            set_bond_type(x11, gmx->man->molw, eBThin);
            break;
        case IDFAT:
            set_bond_type(x11, gmx->man->molw, eBFat);
            break;
        case IDVERYFAT:
            set_bond_type(x11, gmx->man->molw, eBVeryFat);
            break;
        case IDBALLS:
            set_bond_type(x11, gmx->man->molw, eBSpheres);
            break;
        case IDNOBOX:
            set_box_type(x11, gmx->man->molw, esbNone);
            break;
        case IDRECTBOX:
            set_box_type(x11, gmx->man->molw, esbRect);
            break;
        case IDTRIBOX:
            set_box_type(x11, gmx->man->molw, esbTri);
            break;
        case IDTOBOX:
            set_box_type(x11, gmx->man->molw, esbTrunc);
            break;

        /* Analysis Menu */
        case IDBOND:
        case IDANGLE:
        case IDDIH:
        case IDRMS:
        case IDRDF:
        case IDENERGIES:
        case IDCORR:
            show_mb(gmx, emNotImplemented);
            break;

        /* Help Menu */
        case IDHELP:
            show_mb(gmx, emHelp);
            break;
        case IDABOUT:
            show_logo(x11, gmx->logo);
            break;

        default:
            break;
    }
    return false;
}