Ejemplo n.º 1
0
int LdapInit()
{
    int ret,msgid;
    LDAP *handle = NULL;
    LDAPMessage *result = NULL, *msg;
    LDAPControl     **sctrlsp = NULL;
    struct berval *cred, *rcred;
    int protocol = LDAP_VERSION3;
    struct timeval tv = {3,0};

    ret = ldap_initialize(&handle, my_uri);
    if (ret != LDAP_SUCCESS) {
	cout <<"ldap not initialized\n";
	goto err;
    }

    ret = ldap_set_option(handle, LDAP_OPT_PROTOCOL_VERSION, &protocol);
    if (ret != LDAP_SUCCESS) {
	debugs(1, "ldap set option - %s\n", ldap_err2string(ret));
	goto err;
    }

    cred = (struct berval *)calloc(1, sizeof(*cred));
    rcred = NULL;
    cred->bv_val = (char*)my_pwd;
    cred->bv_len = strlen(my_pwd);

    ret = ldap_sasl_bind(handle,NULL,LDAP_SASL_SIMPLE,cred,sctrlsp,NULL, &msgid);
    if (ret != LDAP_SUCCESS) {
	debugs(1, "ldap bind failed - %s\n", ldap_err2string(ret));
	goto err;
    }

    ret = ldap_result(handle, msgid, 1, NULL, &result);
    if (ret < 0) {
	debugs(1, "ldap bind failed - %s\n", ldap_err2string(ret));
	goto err;
    }
    debugs(3, "ldap bind result %d protocol %d\n", ret, protocol);

    ret = 0;
err:
    return ret;
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{ 
  double duration;
  struct tms start, end;
  ATerm in_term, out_term;

  ATinit(argc, argv, &in_term);

  ATprotectArray(term_stack,   TSIZE);
  ATprotectArray(environment,  ESIZE);

  process_options(argc, argv);

  /* Open input file */

  if (input_file == NULL)
      infile = stdin;
  else
      infile = fopen(input_file, "r");

  /* Push term to be reduced on term stack */

  if ((in_term = ATreadFromFile(infile)) == NULL) {
    ATfprintf(stderr, "not a valid term\n");
    exit(1);
  }

  in_term = /*list_to_consnil*/(in_term);

  debugs(ATfprintf(stderr, "in_term (b) = %t\n", in_term));

  /* Execute the strategy */

  times(&start);
  out_term = doit(in_term); 
  times(&end);
  duration = ((double)(end.tms_utime - start.tms_utime))/((double)CLK_TCK);
 
  if(out_term != NULL)
    {
      /* Open output file */
      if (output_file == NULL)
	  outfile = stdout;
      else
	  outfile = fopen(output_file, "w");
      /* ATfprintf(stdout, "%t\n", out_term); */  
      if(binary_output)
	ATwriteToBinaryFile(/*consnil_to_list*/(out_term), outfile);
      else
	ATwriteToTextFile(/*consnil_to_list*/(out_term), outfile);
    }

  print_profile(duration);

  if (!failed)
    {
      ATfprintf(stderr, "  rewriting succeeded\n");
      exit(0);
    }
  else 
    {
      ATfprintf(stderr, "  rewriting failed\n");
      exit(1);
    }
}
Ejemplo n.º 3
0
Manifest*
Manifest::load(raw_ostream& ErrorStream, Automaton::Type T, StringRef Path) {
  llvm::SourceMgr SM;
  OwningPtr<MemoryBuffer> Buffer;

  error_code Error = MemoryBuffer::getFile(Path, Buffer);
  if (Error != 0) {
    ErrorStream
      << "Failed to open TESLA analysis file '" << Path << "': "
      << Error.message() << "\n"
      ;

    return NULL;
  }

  OwningPtr<ManifestFile> Protobuf(new ManifestFile);

  StringRef buf = Buffer->getBuffer();
  const bool TextFormat =
    buf.ltrim().startswith("automaton")
    or buf.ltrim().startswith("#line 1")       // for preprocessed manifests
    or buf.ltrim().startswith("# 1")           // GNU cpp version of the above
    ;

  const bool success =
    TextFormat
      ? google::protobuf::TextFormat::ParseFromString(buf, Protobuf.get())
      : Protobuf->ParseFromArray(buf.data(), buf.size())
    ;

  if (!success) {
    ErrorStream
      << "Error parsing TESLA manifest '" << Path << "' (in "
      << (TextFormat ? "text" : "binary")
      << " format)\n"
      ;
    return NULL;
  }

  AutomataMap Descriptions;
  map<Identifier,const Automaton*> Automata;

  // Note the top-level automata that are explicitly named as roots.
  ArrayRef<const Usage*> Roots(Protobuf->root().data(), Protobuf->root_size());
  map<Identifier,const Usage*> Uses;
  for (auto *U : Roots)
    Uses[U->identifier()] = U;

  for (auto& A : Protobuf->automaton())
    Descriptions[A.identifier()] = &A;

  vector<Automaton::Lifetime> Lifetimes;

  int id = 0;
  for (auto i : Descriptions) {
    const Identifier& ID = i.first;
    const AutomatonDescription *Descrip = i.second;

    OwningPtr<NFA> N(NFA::Parse(Descrip, Uses[ID], id++));
    if (!N) {
      for (auto i : Automata) delete i.second;
      for (auto i : Descriptions) delete i.second;
      return NULL;
    }

    OwningPtr<Automaton> Result;

    if (T == Automaton::Unlinked)
      Result.reset(N.take());

    else {
      N.reset(N->Link(Descriptions));

      if (T == Automaton::Linked)
        Result.reset(N.take());

      else
        Result.reset(DFA::Convert(N.get()));
    }

    Automaton::Lifetime L = Result->getLifetime();
    if (L.Init != NULL
        and find(Lifetimes.begin(), Lifetimes.end(), L) == Lifetimes.end()) {

        Lifetimes.push_back(L);
        assert(Lifetimes.back() == L);
    }

    Automata[ID] = Result.take();
  }

  raw_ostream& debug = debugs("tesla.manifest.lifetimes");
  debug << "--------\nUnique automata lifetimes:\n";
  for (auto& Lifetime : Lifetimes)
    debug << " * " << Lifetime.String() << "\n";
  debug << "--------\n";

  return new Manifest(Protobuf, Descriptions, Automata, Roots, Lifetimes);
}