Exemplo n.º 1
0
char *pargs_print_line(t_pargs *pa,bool bLeadingSpace)
{
  char buf[LONGSTR],*buf2,*tmp;

  snew(buf2,LONGSTR+strlen(pa->desc));
  snew(tmp,LONGSTR+strlen(pa->desc));
  
  if (pa->type == etBOOL)
    sprintf(buf,"-[no]%s",pa->option+1);
  else
    strcpy(buf,pa->option);
  if (strlen(buf)>((OPTLEN+TYPELEN)-max(strlen(argtp[pa->type]),4))) {
    sprintf(buf2,"%s%s %-6s %-6s  %-s\n",
	    bLeadingSpace ? " " : "",buf,
	    argtp[pa->type],pa_val(pa,tmp,LONGSTR-1),check_tty(pa->desc));
  } else if (strlen(buf)>OPTLEN) {
    /* so type can be 3 or 4 char's, this fits in the %4s */
    sprintf(buf2,"%s%-14s %-4s %-6s  %-s\n",
	    bLeadingSpace ? " " : "",buf,argtp[pa->type],
	    pa_val(pa,tmp,LONGSTR-1),check_tty(pa->desc));
  } else
    sprintf(buf2,"%s%-12s %-6s %-6s  %-s\n",
	    bLeadingSpace ? " " : "",buf,argtp[pa->type],
	    pa_val(pa,tmp,LONGSTR-1),check_tty(pa->desc));
  
  sfree(tmp);
    
  tmp = wrap_lines(buf2,78,28,FALSE);
  
  sfree(buf2);
  
  return tmp;
}
Exemplo n.º 2
0
Logger::Logger (std::ostream& o, bool enabled)
:
logger_on_ (enabled),
o_ (o)
{
    check_tty ();
}
Exemplo n.º 3
0
static void
check_idleness(time_t *now, hrtime_t *hr_now)
{

	/*
	 * Check idleness only when autoshutdown is enabled.
	 */
	if (!autoshutdown_en) {
		checkidle_time = 0;
		return;
	}

	info->pd_ttychars_idle = check_tty(hr_now, asinfo.ttychars_thold);
	info->pd_loadaverage_idle =
	    check_load_ave(hr_now, asinfo.loadaverage_thold);
	info->pd_diskreads_idle = check_disks(hr_now, asinfo.diskreads_thold);
	info->pd_nfsreqs_idle = check_nfs(hr_now, asinfo.nfsreqs_thold);

#ifdef DEBUG
	(void) fprintf(stderr, "Idle ttychars for %d secs.\n",
			info->pd_ttychars_idle);
	(void) fprintf(stderr, "Idle loadaverage for %d secs.\n",
			info->pd_loadaverage_idle);
	(void) fprintf(stderr, "Idle diskreads for %d secs.\n",
			info->pd_diskreads_idle);
	(void) fprintf(stderr, "Idle nfsreqs for %d secs.\n",
			info->pd_nfsreqs_idle);
#endif

	checkidle_time = *now + IDLECHK_INTERVAL;
}
Exemplo n.º 4
0
Logger::Logger (bool enabled)
:
logger_on_ (enabled),
o_ (std::cerr)
{
    check_tty ();
}
Exemplo n.º 5
0
void
print_tty_formatted(FILE *out, int nldesc, const char **desc,int indent,
                    t_linkdata *links,const char *program,gmx_bool bWiki)
{
  char *buf;
  char *temp;
  int buflen,i,j;

  buflen = 80*nldesc;
  snew(buf,buflen);
  for(i=0; (i<nldesc); i++) {
    if ((strlen(buf)>0) && 
	(buf[strlen(buf)-1] !=' ') && (buf[strlen(buf)-1] !='\n'))
      strcat(buf," ");
    if (bWiki)
      temp=NWR(desc[i]);
    else
      temp=check_tty(desc[i]);
    if (strlen(buf) + strlen(temp) >= (size_t)(buflen-2)) {
      buflen += strlen(temp);
      srenew(buf,buflen);
    }
    strcat(buf,temp);
    sfree(temp);
  }
  /* Make lines of at most 79 characters */
  temp = wrap_lines(buf,78,indent,FALSE);
  fprintf(out,"%s\n",temp);
  sfree(temp);
  sfree(buf);
}
Exemplo n.º 6
0
static void write_ttyman(FILE *out,
                         const char *program,
                         int nldesc, const char **desc,
                         int nfile, t_filenm *fnm,
                         int npargs, t_pargs *pa,
                         int nbug, const char **bugs, gmx_bool bHeader,
                         t_linkdata *links)
{
    int   i;
    char  buf[256];
    char *tmp;

    if (bHeader)
    {
        fprintf(out, "%s\n\n", check_tty(program));
        fprintf(out, "%s\n%s\n", GromacsVersion(), mydate(buf, 255, FALSE));
    }
    if (nldesc > 0)
    {
        fprintf(out, "DESCRIPTION\n-----------\n");
        print_tty_formatted(out, nldesc, desc, 0, links, program, FALSE);
    }
    if (nbug > 0)
    {
        fprintf(out, "\n");
        fprintf(out, "KNOWN PROBLEMS\n----------\n");
        for (i = 0; i < nbug; i++)
        {
            snew(tmp, strlen(bugs[i])+3);
            strcpy(tmp, "* ");
            strcpy(tmp+2, check_tty(bugs[i]));
            fprintf(out, "%s\n", wrap_lines(tmp, 78, 2, FALSE));
            sfree(tmp);
        }
    }
    if (nfile > 0)
    {
        fprintf(out, "\n");
        pr_fns(out, nfile, fnm);
    }
    if (npargs > 0)
    {
        print_pargs(out, npargs, pa, FALSE);
    }
}
Exemplo n.º 7
0
static void spk_ttyio_tiocmset(unsigned int set, unsigned int clear)
{
	mutex_lock(&speakup_tty_mutex);
	if (check_tty(speakup_tty)) {
		mutex_unlock(&speakup_tty_mutex);
		return;
	}

	speakup_tty->ops->tiocmset(speakup_tty, set, clear);
	mutex_unlock(&speakup_tty_mutex);
}
Exemplo n.º 8
0
static void spk_ttyio_send_xchar(char ch)
{
	mutex_lock(&speakup_tty_mutex);
	if (check_tty(speakup_tty)) {
		mutex_unlock(&speakup_tty_mutex);
		return;
	}

	speakup_tty->ops->send_xchar(speakup_tty, ch);
	mutex_unlock(&speakup_tty_mutex);
}
Exemplo n.º 9
0
void
mux_init(void)
{
    int i;

    FD_ZERO(&input_sources);
    
    for (i=0; i<MAX_SOURCES; i++)
      input_handler[i] = NULL;

    have_tty = check_tty();
}
Exemplo n.º 10
0
static void spk_ttyio_flush_buffer(void)
{
	mutex_lock(&speakup_tty_mutex);
	if (check_tty(speakup_tty)) {
		mutex_unlock(&speakup_tty_mutex);
		return;
	}

	if (speakup_tty->ops->flush_buffer)
		speakup_tty->ops->flush_buffer(speakup_tty);

	mutex_unlock(&speakup_tty_mutex);
}
Exemplo n.º 11
0
/* Open an archive file.  The argument specifies whether we are
   reading or writing, or both.  */
static void _open_archive(shfs_arch_t *arch, int wanted_access)
{

  if (arch->record_size == 0)
return;

  if (archive_names == 0)
return;

  tar_stat_destroy (&current_stat_info);

  arch->arch_record_index = 0;
  shfs_arch_init_buffer(arch);

  /* When updating the archive, we start with reading.  */
  arch->access_mode = wanted_access == ACCESS_UPDATE ? ACCESS_READ : wanted_access;
  check_tty (arch->access_mode);

  read_full_records = read_full_records_option;

  arch->records_read = 0;

  switch (wanted_access)
  {
    case ACCESS_READ:
      open_compressed_archive(arch);
      break;

    case ACCESS_WRITE:
      break;

    case ACCESS_UPDATE:
      break;
  }

  switch (wanted_access)
  {
    case ACCESS_READ:
      shfs_arch_buffer_next(arch);       /* read it in, check for EOF */
      break;

    case ACCESS_UPDATE:
    case ACCESS_WRITE:
      arch->records_written = 0;
      break;
  }
}
Exemplo n.º 12
0
static void write_ttyman(FILE *out,
			 char *program,
			 int nldesc,char **desc,
			 int nfile,t_filenm *fnm,
			 int npargs,t_pargs *pa,
			 int nbug,char **bugs,bool bHeader)
{
  int i;
  char *tmp;
  
  if (bHeader) {
    fprintf(out,"%s\n\n",check_tty(program));
    fprintf(out,"%s\n%s\n",GromacsVersion(),mydate());
  }
  if (nldesc > 0) {
    fprintf(out,"DESCRIPTION:\n\n");
    print_tty_formatted(out,nldesc,desc);
  }
  if (nbug > 0) {
    fprintf(out,"\n");
    for(i=0; i<nbug; i++) {
      snew(tmp,strlen(bugs[i])+3);
      strcpy(tmp,"* ");
      strcpy(tmp+2,bugs[i]);
      fprintf(out,"%s\n",wrap_lines(tmp,80,2));
      sfree(tmp);
    }
  }
  if (nfile > 0) {
    fprintf(out,"\n");
    pr_fns(out,nfile,fnm);
  }
  if (npargs > 0) {
    print_pargs(out,npargs,pa);
  }
}
Exemplo n.º 13
0
void print_tty_formatted(FILE *out, int nldesc, char **desc)
{
  char *buf,*temp;
  int i,j;

  /* Just to be sure */
  j=0;
  for(i=0; (i<nldesc); i++) 
    j+=strlen(desc[i])+10;
  snew(buf,j);
  for(i=0; (i<nldesc); i++) {
    if ((strlen(buf)>0) && 
	(buf[strlen(buf)-1] !=' ') && (buf[strlen(buf)-1] !='\n'))
      strcat(buf," ");
    temp=check_tty(desc[i]);
    strcat(buf,temp);
    sfree(temp);
  }
  /* Make lines of at most 79 characters */
  temp = wrap_lines(buf,80,0);
  fprintf(out,"%s\n",temp);
  sfree(temp);
  sfree(buf);
}
Exemplo n.º 14
0
std::string HelpWriterContext::substituteMarkup(const std::string &text) const
{
    char *resultStr = check_tty(text.c_str());
    scoped_ptr_sfree resultGuard(resultStr);
    return std::string(resultStr);
}
Exemplo n.º 15
0
/* Get the path to the timestamp to use. */
static int
get_timestamp_name(pam_handle_t *pamh, int argc, const char **argv,
		   char *path, size_t len)
{
	const char *user, *tty;
	const void *void_tty;
	const char *tdir = TIMESTAMPDIR;
	char ruser[BUFLEN];
	int i, debug = 0;

	/* Parse arguments. */
	for (i = 0; i < argc; i++) {
		if (strcmp(argv[i], "debug") == 0) {
			debug = 1;
		}
	}
	for (i = 0; i < argc; i++) {
		if (strncmp(argv[i], "timestampdir=", 13) == 0) {
			tdir = argv[i] + 13;
			if (debug) {
				pam_syslog(pamh, LOG_DEBUG,
				       "storing timestamps in `%s'",
				       tdir);
			}
		}
	}
	i = check_dir_perms(pamh, tdir);
	if (i != PAM_SUCCESS) {
		return i;
	}
	/* Get the name of the target user. */
	if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS) {
		user = NULL;
	}
	if ((user == NULL) || (strlen(user) == 0)) {
		return PAM_AUTH_ERR;
	}
	if (debug) {
		pam_syslog(pamh, LOG_DEBUG, "becoming user `%s'", user);
	}
	/* Get the name of the source user. */
	if (get_ruser(pamh, ruser, sizeof(ruser)) || strlen(ruser) == 0) {
		return PAM_AUTH_ERR;
	}
	if (debug) {
		pam_syslog(pamh, LOG_DEBUG, "currently user `%s'", ruser);
	}
	/* Get the name of the terminal. */
	if (pam_get_item(pamh, PAM_TTY, &void_tty) != PAM_SUCCESS) {
		tty = NULL;
	} else {
		tty = void_tty;
	}
	if ((tty == NULL) || (strlen(tty) == 0)) {
		tty = ttyname(STDIN_FILENO);
		if ((tty == NULL) || (strlen(tty) == 0)) {
			tty = ttyname(STDOUT_FILENO);
		}
		if ((tty == NULL) || (strlen(tty) == 0)) {
			tty = ttyname(STDERR_FILENO);
		}
		if ((tty == NULL) || (strlen(tty) == 0)) {
			/* Match sudo's behavior for this case. */
			tty = "unknown";
		}
	}
	if (debug) {
		pam_syslog(pamh, LOG_DEBUG, "tty is `%s'", tty);
	}
	/* Snip off all but the last part of the tty name. */
	tty = check_tty(tty);
	if (tty == NULL) {
		return PAM_AUTH_ERR;
	}
	/* Generate the name of the file used to cache auth results.  These
	 * paths should jive with sudo's per-tty naming scheme. */
	if (format_timestamp_name(path, len, tdir, tty, ruser, user) >= (int)len) {
		return PAM_AUTH_ERR;
	}
	if (debug) {
		pam_syslog(pamh, LOG_DEBUG, "using timestamp file `%s'", path);
	}
	return PAM_SUCCESS;
}
Exemplo n.º 16
0
extern int login_main(int argc, char **argv)
{
	char tty[BUFSIZ];
	char full_tty[200];
	char fromhost[512];
	char username[USERNAME_SIZE];
	const char *tmp;
	int amroot;
	int flag;
	int failed;
	int count=0;
	struct passwd *pw, pw_copy;
#ifdef CONFIG_WHEEL_GROUP
	struct group *grp;
#endif
	int opt_preserve = 0;
	int opt_fflag = 0;
	char *opt_host = 0;
	int alarmstarted = 0;
#ifdef CONFIG_SELINUX
	int flask_enabled = is_flask_enabled();
	security_id_t sid = 0, old_tty_sid, new_tty_sid;
#endif

	username[0]=0;
	amroot = ( getuid ( ) == 0 );
	signal ( SIGALRM, alarm_handler );
	alarm ( TIMEOUT );
	alarmstarted = 1;

	while (( flag = getopt(argc, argv, "f:h:p")) != EOF ) {
		switch ( flag ) {
		case 'p':
			opt_preserve = 1;
			break;
		case 'f':
			/*
			 * username must be a separate token
			 * (-f root, *NOT* -froot). --marekm
			 */
			if ( optarg != argv[optind-1] )
				bb_show_usage( );

			if ( !amroot ) 		/* Auth bypass only if real UID is zero */
				bb_error_msg_and_die ( "-f permission denied" );

			safe_strncpy(username, optarg, USERNAME_SIZE);
			opt_fflag = 1;
			break;
		case 'h':
			opt_host = optarg;
			break;
		default:
			bb_show_usage( );
		}
	}

	if (optind < argc)             // user from command line (getty)
		safe_strncpy(username, argv[optind], USERNAME_SIZE);

	if ( !isatty ( 0 ) || !isatty ( 1 ) || !isatty ( 2 ))
		return EXIT_FAILURE;		/* Must be a terminal */

#ifdef CONFIG_FEATURE_U_W_TMP
	checkutmp ( !amroot );
#endif

	tmp = ttyname ( 0 );
	if ( tmp && ( strncmp ( tmp, "/dev/", 5 ) == 0 ))
		safe_strncpy ( tty, tmp + 5, sizeof( tty ));
	else if ( tmp && *tmp == '/' )
		safe_strncpy ( tty, tmp, sizeof( tty ));
	else
		safe_strncpy ( tty, "UNKNOWN", sizeof( tty ));

#ifdef CONFIG_FEATURE_U_W_TMP
	if ( amroot )
		memset ( utent.ut_host, 0, sizeof utent.ut_host );
#endif

	if ( opt_host ) {
#ifdef CONFIG_FEATURE_U_W_TMP
		safe_strncpy ( utent.ut_host, opt_host, sizeof( utent. ut_host ));
#endif
		snprintf ( fromhost, sizeof( fromhost ) - 1, " on `%.100s' from `%.200s'", tty, opt_host );
	}
	else
		snprintf ( fromhost, sizeof( fromhost ) - 1, " on `%.100s'", tty );

	setpgrp();

	openlog ( "login", LOG_PID | LOG_CONS | LOG_NOWAIT, LOG_AUTH );

	while ( 1 ) {
		failed = 0;

		if ( !username[0] )
			if(!login_prompt ( username ))
				return EXIT_FAILURE;

		if ( !alarmstarted && ( TIMEOUT > 0 )) {
			alarm ( TIMEOUT );
			alarmstarted = 1;
		}

		if (!( pw = getpwnam ( username ))) {
			pw_copy.pw_name   = "UNKNOWN";
			pw_copy.pw_passwd = "!";
			opt_fflag = 0;
			failed = 1;
		} else
			pw_copy = *pw;

		pw = &pw_copy;

		if (( pw-> pw_passwd [0] == '!' ) || ( pw-> pw_passwd[0] == '*' ))
			failed = 1;

		if ( opt_fflag ) {
			opt_fflag = 0;
			goto auth_ok;
		}

		if (!failed && ( pw-> pw_uid == 0 ) && ( !check_tty ( tty )))
			failed = 1;

		/* Don't check the password if password entry is empty (!) */
		if ( !pw-> pw_passwd[0] )
			goto auth_ok;

		/* authorization takes place here */
		if ( correct_password ( pw ))
			goto auth_ok;

		failed = 1;

auth_ok:
		if ( !failed)
			break;

		{ // delay next try
			time_t start, now;

			time ( &start );
			now = start;
			while ( difftime ( now, start ) < FAIL_DELAY) {
				sleep ( FAIL_DELAY );
				time ( &now );
			}
		}

		puts("Login incorrect");
		username[0] = 0;
		if ( ++count == 3 ) {
			syslog ( LOG_WARNING, "invalid password for `%s'%s\n", pw->pw_name, fromhost);
			return EXIT_FAILURE;
	}
	}

	alarm ( 0 );
	if ( check_nologin ( pw-> pw_uid == 0 ))
		return EXIT_FAILURE;

#ifdef CONFIG_FEATURE_U_W_TMP
	setutmp ( username, tty );
#endif
#ifdef CONFIG_SELINUX
	if (flask_enabled)
	{
		struct stat st;

		if (get_default_sid(username, 0, &sid))
		{
			fprintf(stderr, "Unable to get SID for %s\n", username);
			exit(1);
		}
		if (stat_secure(tty, &st, &old_tty_sid))
		{
			fprintf(stderr, "stat_secure(%.100s) failed: %.100s\n", tty, strerror(errno));
			return EXIT_FAILURE;
		}
		if (security_change_sid (sid, old_tty_sid, SECCLASS_CHR_FILE, &new_tty_sid) != 0)
		{
			fprintf(stderr, "security_change_sid(%.100s) failed: %.100s\n", tty, strerror(errno));
			return EXIT_FAILURE;
		}
		if(chsid(tty, new_tty_sid) != 0)
		{
			fprintf(stderr, "chsid(%.100s, %d) failed: %.100s\n", tty, new_tty_sid, strerror(errno));
			return EXIT_FAILURE;
		}
	}
	else
		sid = 0;
#endif

	if ( *tty != '/' )
		snprintf ( full_tty, sizeof( full_tty ) - 1, "/dev/%s", tty);
	else
		safe_strncpy ( full_tty, tty, sizeof( full_tty ) - 1 );

	if ( !is_my_tty ( full_tty ))
		syslog ( LOG_ERR, "unable to determine TTY name, got %s\n", full_tty );

	/* Try these, but don't complain if they fail
	 * (for example when the root fs is read only) */
	chown ( full_tty, pw-> pw_uid, pw-> pw_gid );
	chmod ( full_tty, 0600 );

	change_identity ( pw );
	tmp = pw-> pw_shell;
	if(!tmp || !*tmp)
		tmp = DEFAULT_SHELL;
	setup_environment ( tmp, 1, !opt_preserve, pw );

	motd ( );
	signal ( SIGALRM, SIG_DFL );	/* default alarm signal */

	if ( pw-> pw_uid == 0 )
		syslog ( LOG_INFO, "root login %s\n", fromhost );
	run_shell ( tmp, 1, 0, 0
#ifdef CONFIG_SELINUX
	, sid
#endif
	 );	/* exec the shell finally. */

	return EXIT_FAILURE;
}
Exemplo n.º 17
0
void
mux_loop(void)
{
    int i, nfds;
    fd_set inputs, outputs;
    struct timeval tv, *tvp;

    mux_end_loop_p = 0;

    for (;;) {
	/*
	 * Exit if mux_end_loop_p has been set to true by a handler:
	 */
	if (mux_end_loop_p)
	  break;
	tvp = NULL;
	tv.tv_sec = 0;
	if (have_tty) {
#ifdef CMU_ZWGCPLUS
            tv.tv_sec = plus_timequeue_events();
           if (tv.tv_sec > 10) tv.tv_sec = 10;
#else
	    tv.tv_sec = 10;
#endif
	    tv.tv_usec = 0;
#ifdef CMU_ZWGCPLUS
	} else {
	   tv.tv_sec = plus_timequeue_events();
	   tv.tv_usec = 0;
#endif
	}
	if (tv.tv_sec)
	 tvp = &tv;

	/*
	 * Do a select on all the file descriptors we care about to
	 * wait until at least one of them has input available:
	 */
	inputs = input_sources;
	FD_ZERO(&outputs);

#ifdef HAVE_ARES
	nfds = ares_fds(achannel, &inputs, &outputs);
	if (nfds < max_source + 1)
	    nfds = max_source + 1;
	tvp = ares_timeout(achannel, tvp, &tv);
#else
	nfds = max_source + 1;
#endif

	i = select(nfds, &inputs, &outputs, NULL, tvp);

	if (i == -1) {
	    if (errno == EINTR)
		continue;    /* on a signal restart checking mux_loop_end_p */
	    else
		FATAL_TRAP( errno, "while selecting" );
	}
	else if (i == 0) {
	    if (have_tty && !check_tty()) {
		mux_end_loop_p = 1;
		continue;
	    }
	}

#ifdef HAVE_ARES
	ares_process(achannel, &inputs, &outputs);
#endif

	/*
	 * Call all input handlers whose corresponding file descriptors have
	 * input:
	 */
	for(i=0; i<=max_source; i++)
	  if (FD_ISSET(i, &inputs) && input_handler[i]) {
#ifdef DEBUG
	      if (zwgc_debug)
		fprintf(stderr,
			"mux_loop...activity on fd %d, calling %lx(%lx)\n",
			i, (unsigned long)input_handler[i],
			 (unsigned long)input_handler_arg[i]);
#endif
	      input_handler[i](input_handler_arg[i]);
	  }
    }
}
Exemplo n.º 18
0
int cr_check(void)
{
	struct ns_id ns = { .type = NS_CRIU, .ns_pid = PROC_SELF, .nd = &mnt_ns_desc };
	int ret = 0;

	if (!is_root_user())
		return -1;

	root_item = alloc_pstree_item();
	if (root_item == NULL)
		return -1;

	root_item->pid.real = getpid();

	if (collect_pstree_ids())
		return -1;

	ns.id = root_item->ids->mnt_ns_id;

	mntinfo = collect_mntinfo(&ns, false);
	if (mntinfo == NULL)
		return -1;

	if (chk_feature) {
		ret = chk_feature();
		goto out;
	}

	ret |= check_map_files();
	ret |= check_sock_diag();
	ret |= check_ns_last_pid();
	ret |= check_sock_peek_off();
	ret |= check_kcmp();
	ret |= check_prctl();
	ret |= check_fcntl();
	ret |= check_proc_stat();
	ret |= check_tcp();
	ret |= check_fdinfo_ext();
	ret |= check_unaligned_vmsplice();
	ret |= check_tty();
	ret |= check_so_gets();
	ret |= check_ipc();
	ret |= check_sigqueuinfo();
	ret |= check_ptrace_peeksiginfo();
	ret |= check_ptrace_suspend_seccomp();
	ret |= check_ptrace_dump_seccomp_filters();
	ret |= check_mem_dirty_track();
	ret |= check_posix_timers();
	ret |= check_tun_cr(0);
	ret |= check_timerfd();
	ret |= check_mnt_id();
	ret |= check_aio_remap();
	ret |= check_fdinfo_lock();
	ret |= check_clone_parent_vs_pid();

out:
	if (!ret)
		print_on_level(DEFAULT_LOGLEVEL, "Looks good.\n");

	return ret;
}
Exemplo n.º 19
0
static void write_py(FILE *out,const char *program,
		     int nldesc,const char **desc,
		     int nfile,t_filenm *fnm,
		     int npargs,t_pargs *pa,
		     int nbug,const char **bugs,
		     t_linkdata *links)
{
  gmx_bool bHidden;
  const char *cls = program;
  char *tmp;
  int  i,j;

  /* Header stuff */  
  fprintf(out,"#!/usr/bin/python\n\nfrom GmxDialog import *\n\n");
  
  /* Class definition */
  fprintf(out,"class %s:\n",cls);
  fprintf(out,"    def __init__(self,tk):\n");
  
  /* Help text */
  fprintf(out,"        %s_help = \"\"\"\n",cls);
  fprintf(out,"        DESCRIPTION\n");
  print_tty_formatted(out,nldesc,desc,8,links,program,FALSE);
  if (nbug > 0) {
    fprintf(out,"\n        BUGS and PROBLEMS\n");
    for(i=0; i<nbug; i++) {
      snew(tmp,strlen(bugs[i])+3);
      strcpy(tmp,"* ");
      strcpy(tmp+2,check_tty(bugs[i]));
      fprintf(out,"%s\n",wrap_lines(tmp,78,10,TRUE));
      sfree(tmp);
    }
  }
  fprintf(out,"        \"\"\"\n\n        # Command line options\n");
  /* File options */
  fprintf(out,"        flags = []\n");
  for(i=0; (i<nfile); i++) 
    fprintf(out,"        flags.append(pca_file('%s',\"%s\",0,%d))\n",
	    ftp2ext_generic(fnm[i].ftp),fnm[i].opt ? fnm[i].opt : "k",
	    is_optional(&(fnm[i])));
	    
	    
  /* Other options */
  for(i=0; (i<npargs); i++) {
    switch(pa[i].type) {
    case etINT:
      fprintf(out,"        flags.append(pca_int(\"%s\",\"%s\",%d,%d))\n",
	      pa[i].option,pa[i].desc,*pa[i].u.i,is_hidden(&(pa[i])));
      break;
    case etREAL:
    case etTIME:
      fprintf(out,"        flags.append(pca_float(\"%s\",\"%s\",%f,%d))\n",
	      pa[i].option,pa[i].desc,*pa[i].u.r,is_hidden(&(pa[i])));
      break;
    case etSTR:
    case etBOOL:
      fprintf(out,"        flags.append(pca_gmx_bool(\"%s\",\"%s\",%d,%d))\n",
	      pa[i].option,pa[i].desc,*pa[i].u.b,is_hidden(&(pa[i])));
      break;
    case etRVEC:
      fprintf(stderr,"Sorry, no rvecs yet...\n");
      break;
    case etENUM:
      fprintf(out,"        flags.append(pca_enum(\"%s\",\"%s\",\n",
	      pa[i].option,pa[i].desc);
      fprintf(out,"        ['%s'",pa[i].u.c[1]);
      for(j=2; (pa[i].u.c[j] != NULL); j++)
	fprintf(out,",'%s'",pa[i].u.c[j]);
      fprintf(out,"],%d))\n",is_hidden(&(pa[i])));
    default:
      break;
    }
  }
    
  /* Make the dialog box */
  fprintf(out,"        gmxd = gmx_dialog(tk,\"%s\",flags,%s_help)\n\n",
	  cls,cls);
	  
  /* Main loop */
  fprintf(out,"#####################################################\n");
  fprintf(out,"tk     = Tk()\n");
  fprintf(out,"my%s = %s(tk)\n",cls,cls);
  fprintf(out,"tk.mainloop()\n");
}