Example #1
0
PUBLIC void edit_temporary_file ARGS3(
	char *,		filename,
	char *,		position,
	char *,		message)
{
#ifdef UNIX
    struct stat stat_info;
#endif
    char *format = "%s %s";
    char *command = NULL;
    char *editor_arg = "";
    int params = 1;
    int rv;

    if (strstr(editor, "pico")) {
	editor_arg = " -t"; /* No prompt for filename to use */
    }
    if (editor_can_position() && *position) {
#ifdef VMS
	format = "%s %s -%s%s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, filename);
	HTAddParam(&command, format, params++, position);
	HTAddParam(&command, format, params++, editor_arg);
	HTEndParam(&command, format, params);
#else
	format = "%s +%s%s %s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, position);
	HTAddParam(&command, format, params++, editor_arg);
	HTAddParam(&command, format, params++, filename);
	HTEndParam(&command, format, params);
#endif
    }
#ifdef DOSPATH
    else if (strncmp(editor, "VZ", 2)==0) {
	/* for Vz editor */
	format = "%s %s -%s";
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, HTDOS_short_name(filename));
	HTAddParam(&command, format, params++, position);
	HTEndParam(&command, format, params);
    } else if (strncmp(editor, "edit", 4)==0) {
	/* for standard editor */
	HTAddXpand(&command, format, params++, editor);
	HTAddParam(&command, format, params++, HTDOS_short_name(filename));
	HTEndParam(&command, format, params);
    }
#endif
    else {
#ifdef _WINDOWS
	if (strchr(editor, ' '))
	    HTAddXpand(&command, format, params++, HTDOS_short_name(editor));
	else
	    HTAddXpand(&command, format, params++, editor);
#else
	HTAddXpand(&command, format, params++, editor);
#endif
	HTAddParam(&command, format, params++, filename);
	HTEndParam(&command, format, params);
    }
    if (message != NULL) {
	_statusline(message);
    }

    CTRACE((tfp, "LYEdit: %s\n", command));
    CTRACE_SLEEP(MessageSecs);

    stop_curses();

#ifdef UNIX
    set_errno(0);
#endif
    if ((rv = LYSystem(command)) != 0) {	/* Spawn Editor */
	start_curses();
	/*
	 *  If something went wrong, we should probably return soon;
	 *  currently we don't, but at least put out a message. - kw
	 */
	{
#ifdef UNIX
	    CTRACE((tfp, "ExtEditForm: system() returned %d (0x%x), %s\n",
		   rv, rv, errno ? LYStrerror(errno) : "reason unknown"));
	    LYFixCursesOn("show error warning:");
	    if (rv == -1) {
		HTUserMsg2(gettext("Error starting editor, %s"),
			   LYStrerror(errno));
	    } else if (WIFSIGNALED(rv)) {
		HTAlwaysAlert(NULL, gettext("Editor killed by signal"));
	    } else if (WIFEXITED(rv) && WEXITSTATUS(rv) != 127) {
		HTUserMsg2(gettext("Editor returned with exit code %d"),
			   WEXITSTATUS(rv));
	    } else
#endif
		HTAlwaysAlert(NULL, ERROR_SPAWNING_EDITOR);
	}
    } else {
	start_curses();
    }
#ifdef UNIX
    /*
     *  Delete backup file, if that's your style.
     */
    HTSprintf0 (&command, "%s~", filename);
    if (stat (command, &stat_info) == 0)
	remove (command);
#endif
    FREE(command);
}
Example #2
0
/*	Translate by rules					HTTranslate()
 *	------------------
 *
 *	The most recently defined rules are applied first.
 *
 * On entry,
 *	required	points to a string whose equivalent value is needed
 * On exit,
 *	returns		the address of the equivalent string allocated from
 *			the heap which the CALLER MUST FREE. If no translation
 *			occurred, then it is a copy of the original.
 * NEW FEATURES:
 *			When a "protect" or "defprot" rule is matched,
 *			a call to HTAA_setCurrentProtection() or
 *			HTAA_setDefaultProtection() is made to notify
 *			the Access Authorization module that the file is
 *			protected, and so it knows how to handle it.
 *								-- AL
 */
char *HTTranslate(const char *required)
{
    rule *r;
    char *current = NULL;
    char *msgtmp = NULL;
    const char *pMsg;
    int proxy_none_flag = 0;
    int permitredir_flag = 0;

    StrAllocCopy(current, required);

    HTAA_clearProtections();	/* Reset from previous call -- AL */

    for (r = rules; r; r = r->next) {
	char *p = r->pattern;
	int m = 0;		/* Number of characters matched against wildcard */
	const char *q = current;

	for (; *p && *q; p++, q++) {	/* Find first mismatch */
	    if (*p != *q)
		break;
	}

	if (*p == '*') {	/* Match up to wildcard */
	    m = strlen(q) - strlen(p + 1);	/* Amount to match to wildcard */
	    if (m < 0)
		continue;	/* tail is too short to match */
	    if (0 != strcmp(q + m, p + 1))
		continue;	/* Tail mismatch */
	} else
	    /* Not wildcard */ if (*p != *q)
	    continue;		/* plain mismatch: go to next rule */

	if (!rule_cond_ok(r))	/* check condition, next rule if false - kw */
	    continue;

	switch (r->op) {	/* Perform operation */

#ifdef ACCESS_AUTH
	case HT_DefProt:
	case HT_Protect:
	    {
		char *local_copy = NULL;
		char *p2;
		char *eff_ids = NULL;
		char *prot_file = NULL;

		CTRACE((tfp, "HTRule: `%s' matched %s %s: `%s'\n",
			current,
			(r->op == HT_Protect ? "Protect" : "DefProt"),
			"rule, setup",
			(r->equiv ? r->equiv :
			 (r->op == HT_Protect ? "DEFAULT" : "NULL!!"))));

		if (r->equiv) {
		    StrAllocCopy(local_copy, r->equiv);
		    p2 = local_copy;
		    prot_file = HTNextField(&p2);
		    eff_ids = HTNextField(&p2);
		}

		if (r->op == HT_Protect)
		    HTAA_setCurrentProtection(current, prot_file, eff_ids);
		else
		    HTAA_setDefaultProtection(current, prot_file, eff_ids);

		FREE(local_copy);

		/* continue translating rules */
	    }
	    break;
#endif /* ACCESS_AUTH */

	case HT_UserMsg:	/* Produce message immediately */
	    LYFixCursesOn("show rule message:");
	    HTUserMsg2((r->equiv ? r->equiv : "Rule: %s"), current);
	    break;
	case HT_InfoMsg:	/* Produce messages immediately */
	case HT_Progress:
	case HT_Alert:
	    LYFixCursesOn("show rule message:");	/* and fall through */
	case HT_AlwaysAlert:
	    pMsg = r->equiv ? r->equiv :
		(r->op == HT_AlwaysAlert) ? "%s" : "Rule: %s";
	    if (strchr(pMsg, '%')) {
		HTSprintf0(&msgtmp, pMsg, current);
		pMsg = msgtmp;
	    }
	    switch (r->op) {	/* Actually produce message */
	    case HT_InfoMsg:
		HTInfoMsg(pMsg);
		break;
	    case HT_Progress:
		HTProgress(pMsg);
		break;
	    case HT_Alert:
		HTAlert(pMsg);
		break;
	    case HT_AlwaysAlert:
		HTAlwaysAlert("Rule alert:", pMsg);
		break;
	    default:
		break;
	    }
	    FREE(msgtmp);
	    break;

	case HT_PermitRedir:	/* Set special flag */
	    permitredir_flag = 1;
	    CTRACE((tfp, "HTRule: Mark for redirection permitted\n"));
	    break;

	case HT_Pass:		/* Authorised */
	    if (!r->equiv) {
		if (proxy_none_flag) {
		    char *temp = NULL;

		    StrAllocCopy(temp, "NoProxy=");
		    StrAllocCat(temp, current);
		    FREE(current);
		    current = temp;
		}
		CTRACE((tfp, "HTRule: Pass `%s'\n", current));
		return current;
	    }
	    /* Else fall through ...to map and pass */

	case HT_Map:
	case HT_Redirect:
	case HT_RedirectPerm:
	    if (*p == *q) {	/* End of both strings, no wildcard */
		CTRACE((tfp, "For `%s' using `%s'\n", current, r->equiv));
		StrAllocCopy(current, r->equiv);	/* use entire translation */
	    } else {
		char *ins = strchr(r->equiv, '*');	/* Insertion point */

		if (ins) {	/* Consistent rule!!! */
		    char *temp = NULL;

		    HTSprintf0(&temp, "%.*s%.*s%s",
			       (int) (ins - r->equiv),
			       r->equiv,
			       m,
			       q,
			       ins + 1);
		    CTRACE((tfp, "For `%s' using `%s'\n",
			    current, temp));
		    FREE(current);
		    current = temp;	/* Use this */

		} else {	/* No insertion point */
		    char *temp = NULL;

		    StrAllocCopy(temp, r->equiv);
		    CTRACE((tfp, "For `%s' using `%s'\n",
			    current, temp));
		    FREE(current);
		    current = temp;	/* Use this */
		}		/* If no insertion point exists */
	    }
	    if (r->op == HT_Pass) {
		if (proxy_none_flag) {
		    char *temp = NULL;

		    StrAllocCopy(temp, "NoProxy=");
		    StrAllocCat(temp, current);
		    FREE(current);
		    current = temp;
		}
		CTRACE((tfp, "HTRule: ...and pass `%s'\n",
			current));
		return current;
	    } else if (r->op == HT_Redirect) {
		CTRACE((tfp, "HTRule: ...and redirect to `%s'\n",
			current));
		redirecting_url = current;
		HTPermitRedir = (BOOL) (permitredir_flag == 1);
		return (char *) 0;
	    } else if (r->op == HT_RedirectPerm) {
		CTRACE((tfp, "HTRule: ...and redirect like 301 to `%s'\n",
			current));
		redirecting_url = current;
		permanent_redirection = TRUE;
		HTPermitRedir = (BOOL) (permitredir_flag == 1);
		return (char *) 0;
	    }
	    break;

	case HT_UseProxy:
	    if (r->equiv && 0 == strcasecomp(r->equiv, "none")) {
		CTRACE((tfp, "For `%s' will not use proxy\n", current));
		proxy_none_flag = 1;
	    } else if (proxy_none_flag) {
		CTRACE((tfp, "For `%s' proxy server ignored: %s\n",
			current,
			NONNULL(r->equiv)));
	    } else {
		char *temp = NULL;

		StrAllocCopy(temp, "Proxied=");
		StrAllocCat(temp, r->equiv);
		StrAllocCat(temp, current);
		CTRACE((tfp, "HTRule: proxy server found: %s\n",
			NONNULL(r->equiv)));
		FREE(current);
		return temp;
	    }
	    break;

	case HT_Invalid:
	case HT_Fail:		/* Unauthorised */
	    CTRACE((tfp, "HTRule: *** FAIL `%s'\n", current));
	    FREE(current);
	    return (char *) 0;
	}			/* if tail matches ... switch operation */

    }				/* loop over rules */

    if (proxy_none_flag) {
	char *temp = NULL;

	StrAllocCopy(temp, "NoProxy=");
	StrAllocCat(temp, current);
	FREE(current);
	return temp;
    }

    return current;
}
Example #3
0
int remote_session( char *acc_method, char *host )
{
  char *program;
  char *user = host;
  char *password = 0;
  char *cp;
  char *hostname;
  char *port;
  char *command = 0;
  enum _login_protocol  login_protocol = rlogin;
  cp = host;
  for ( ; cp[0]; cp++ )
  {
    if ( !( *(short*)(*(int*)(__ctype_b_loc( )) + ( cp[0] * 2 )) & 8 ) && cp[0] != '_' && cp[0] != '-' && cp[0] != ':' && cp[0] != '.' && cp[0] != '@' )
    {
      cp[0] = 0;
      break;
    }
    else
    {
      // cp++;
    }
  }
  hostname = strchr( host, '@' );
  if ( hostname )
  {
    hostname[0] = 0;
    hostname++;
  }
  else
  {
    hostname = host;
    user = 0;
  }
  port = strchr( hostname, ':' );
  if ( port )
  {
    port[0] = 0;
    port++;
  }
  if ( hostname == 0 || hostname[0] == 0 )
  {
    if ( WWW_TraceFlag )
    {
      fprintf( TraceFP( ), "HTTelnet: No host specified!\n" );
    }
    return -204;
  }
  else
  {
    if ( ( valid_hostname( hostname ) & 255 ) == 0 )
    {
      char *prefix = 0;
      char *line = 0;
      if ( WWW_TraceFlag )
      {
        fprintf( TraceFP( ), "HTTelnet: Invalid hostname %s!\n", host );
      }
      HTSprintf0( &prefix, gettext( "remote %s session:" ), acc_method );
      HTSprintf0( &line, gettext( "Invalid hostname %s" ), host );
      HTAlwaysAlert( prefix, line );
      if ( prefix )
      {
        free( prefix );
        prefix = 0;
      }
      if ( line )
      {
        free( line );
        line = 0;
      }
      return -204;
    }
    else
    {
      if ( user )
      {
        password = strchr( user, ':' );
        if ( password )
        {
          password[0] = 0;
          password++;
        }
      }
      if ( HTSecure )
      {
        puts( "\n\nSorry, but the service you have selected is one" );
        puts( "to which you have to log in.  If you were running www" );
        puts( "on your own computer, you would be automatically connected." );
        puts( "For security reasons, this is not allowed when" );
        puts( "you log in to this information service remotely.\n" );
        printf( "You can manually connect to this service using %s\n", acc_method );
        printf( "to host %s", hostname );
        if ( user )
          printf( ", user name %s", user );
        if ( password )
          printf( ", password %s", password );
        if ( port )
          printf( ", port %s", port );
        puts( ".\n" );
        return -204;
      }
      else
      {
        if ( user && login_protocol != rlogin )
          printf( "When you are connected, log in as:  %s\n", user );
        if ( password && login_protocol != rlogin )
          printf( "                  The password is:  %s\n", password );
        fflush( stdout );
        switch ( login_protocol )
        {
        case rlogin:
          program = HTGetProgramPath( 11 );
          if ( program == 0 )
          {
            LYSystem( command );
            return -204;
          }
          HTAddParam( &command, "%s %s%s%s", 1, program );
          HTAddParam( &command, "%s %s%s%s", 2, hostname );
          HTSACat( &command, "" );
          HTAddParam( &command, "%s %s%s%s", 4, user );
          HTEndParam( &command, "%s %s%s%s", 4 );
          break;
        case tn3270:
          program = HTGetProgramPath( 17 );
          if ( program == 0 )
          {
            LYSystem( command );
            return -204;
          }
          HTAddParam( &command, "%s %s %s", 1, program );
          HTAddParam( &command, "%s %s %s", 2, hostname );
          HTAddParam( &command, "%s %s %s", 3, port );
          HTEndParam( &command, "%s %s %s", 3 );
          break;
        case telnet:
          program = HTGetProgramPath( 16 );
          if ( program == 0 )
          {
            LYSystem( command );
            return -204;
          }
          HTAddParam( &command, "%s %s %s", 1, program );
          HTAddParam( &command, "%s %s %s", 2, hostname );
          HTAddParam( &command, "%s %s %s", 3, port );
          HTEndParam( &command, "%s %s %s", 3 );
          break;
        }
      }
    }
  }
}