Esempio n. 1
0
void
test_lseek(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_lseek_fd(&ntests, &lost_points);

	ntests++;
	result = lseek_fd_device();
	handle_result(result, &lost_points);

	ntests++;
	result = lseek_file_stdin();
	handle_result(result, &lost_points);

	ntests++;
	result = lseek_loc_negative();
	handle_result(result, &lost_points);

	ntests++;
	result = lseek_loc_pasteof();
	handle_result(result, &lost_points);

	ntests++;
	result = lseek_whence_inval();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 2
0
void
test_sbrk(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	ntests++;
	result = sbrk_neg();
	handle_result(result, &lost_points);

	ntests++;
	result = sbrk_bigpos();
	handle_result(result, &lost_points);

	ntests++;
	result = sbrk_bigneg();
	handle_result(result, &lost_points);

	ntests++;
	result = sbrk_unalignedpos();
	handle_result(result, &lost_points);

	ntests++;
	result = sbrk_unalignedneg();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 3
0
void
test_remove(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_remove_path(&ntests, &lost_points);

	ntests++;
	result = remove_dir();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_dot();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_dotdot();
	handle_result(result, &lost_points);

	ntests++;
	result = remove_empty();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 4
0
int main(int argc, char** argv) {
    DB_RESULT result;
    char clause[256];
    int retval, n, nerr;

    for(int c = 1; c < argc; c++) {
        std::string option(argv[c]);
        if(option == "-h" || option == "--help") {
            usage(argv[0]);
            exit(0);
        } else if(option == "-v" || option == "--version") {
            printf("%s\n", SVN_VERSION);
            exit(0);
        } else if (option == "--repair") {
            repair = true;
        } else {
            fprintf(stderr, "unknown command line argument: %s\n\n", argv[c]);
            usage(argv[0]);
            exit(1);
        }
    }

    retval = config.parse_file();
    if (retval) exit(1);

    retval = boinc_db.open(
                 config.db_name, config.db_host, config.db_user, config.db_passwd
             );
    if (retval) {
        printf("boinc_db.open: %s\n", boincerror(retval));
        exit(1);
    }

    n = nerr = 0;
    printf("Unsent results:\n");
    sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_UNSENT);
    while (!result.enumerate(clause)) {
        retval = handle_result(result);
        n++;
        if (retval) nerr++;
    }
    printf("%d out of %d errors\n", nerr, n);
    n = nerr = 0;
    printf("In progress results:\n");
    sprintf(clause, "where server_state=%d", RESULT_SERVER_STATE_IN_PROGRESS);
    while (!result.enumerate(clause)) {
        retval = handle_result(result);
        n++;
        if (retval) nerr++;
    }
    printf("%d out of %d errors\n", nerr, n);
}
Esempio n. 5
0
static void
handle_player_method_call(GDBusConnection *connection,
			const char *sender,
			const char *object_path,
			const char *interface_name,
			const char *method_name,
			GVariant *parameters,
			GDBusMethodInvocation *invocation,
			XmrMprisPlugin *plugin)

{
	if(g_strcmp0(object_path, MPRIS_OBJECT_NAME) != 0 ||
	    g_strcmp0(interface_name, MPRIS_PLAYER_INTERFACE) != 0)
	{
		g_dbus_method_invocation_return_error(invocation,
						       G_DBUS_ERROR,
						       G_DBUS_ERROR_NOT_SUPPORTED,
						       "Method %s.%s not supported",
						       interface_name,
						       method_name);
		return;
	}

	if (g_strcmp0(method_name, "Next") == 0)
	{
		xmr_window_play_next(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else if (g_strcmp0(method_name, "Pause") == 0)
	{
		xmr_window_pause(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else if (g_strcmp0 (method_name, "Play") == 0)
	{
		xmr_window_play(plugin->window);
		handle_result(invocation, TRUE, NULL);
	}
	else
	{
		g_dbus_method_invocation_return_error(invocation,
					G_DBUS_ERROR,
					G_DBUS_ERROR_NOT_SUPPORTED,
					"Method %s.%s not supported",
					interface_name,
					method_name);
	}
}
Esempio n. 6
0
void
test_open(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_open_path(&ntests, &lost_points);

	ntests++;
	result = open_badflags();
	handle_result(result, &lost_points);

	ntests++;
	result = open_empty();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 7
0
void
test_ioctl(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	test_ioctl_fd(&ntests, &lost_points);

	/* Since we don't actually define any ioctls, this is not meaningful */
	ntests++;
	result = ioctl_badcode();
	handle_result(result, &lost_points);

	ntests++;
	result = ioctl_badbuf();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 8
0
void
test_symlink(void)
{
	int ntests = 0, lost_points = 0;
	int result;


	test_symlink_paths(&ntests, &lost_points);

	ntests++;
	result = symlink_empty1();
	handle_result(result, &lost_points);

	ntests++;
	result = symlink_empty2();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 9
0
static PyObject* evaluate_snippet(PyObject* self, PyObject* args, PyObject *keywds)
{
    const char *filename, *src;
    char *out;
    unsigned max_stack = 500, gc_min_objects = 1000, max_trace = 20;
    double gc_growth_trigger = 2;
    int error;
    PyObject *ext_vars = NULL, *ext_codes = NULL;
    PyObject *tla_vars = NULL, *tla_codes = NULL;
    PyObject *import_callback = NULL;
    PyObject *native_callbacks = NULL;
    struct JsonlangVm *vm;
    static char *kwlist[] = {
        "filename", "src",
        "max_stack", "gc_min_objects", "gc_growth_trigger", "ext_vars",
        "ext_codes", "tla_vars", "tla_codes", "max_trace", "import_callback",
        "native_callbacks",
        NULL
    };

    (void) self;

    if (!PyArg_ParseTupleAndKeywords(
        args, keywds, "ss|IIdOOOOIOO", kwlist,
        &filename, &src,
        &max_stack, &gc_min_objects, &gc_growth_trigger, &ext_vars,
        &ext_codes, &tla_vars, &tla_codes, &max_trace, &import_callback,
        &native_callbacks)) {
        return NULL;
    }

    vm = jsonlang_make();
    jsonlang_max_stack(vm, max_stack);
    jsonlang_gc_min_objects(vm, gc_min_objects);
    jsonlang_max_trace(vm, max_trace);
    jsonlang_gc_growth_trigger(vm, gc_growth_trigger);
    if (!handle_vars(vm, ext_vars, 0, 0)) return NULL;
    if (!handle_vars(vm, ext_codes, 1, 0)) return NULL;
    if (!handle_vars(vm, tla_vars, 0, 1)) return NULL;
    if (!handle_vars(vm, tla_codes, 1, 1)) return NULL;
    struct ImportCtx ctx = { vm, import_callback };
    if (!handle_import_callback(&ctx, import_callback)) {
        return NULL;
    }
    struct NativeCtx *ctxs = NULL;
    if (!handle_native_callbacks(vm, native_callbacks, &ctxs)) {
        free(ctxs);
        return NULL;
    }
    out = jsonlang_evaluate_snippet(vm, filename, src, &error);
    free(ctxs);
    return handle_result(vm, out, error);
}
Esempio n. 10
0
void
test_execv(void)
{
	int ntests = 0, result = 0, lost_points = 0;
	ntests++;
	result = exec_badprog(NULL, "exec with NULL program");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_badprog(INVAL_PTR, "exec with invalid pointer program");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_badprog(KERN_PTR, "exec with kernel pointer program");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_emptyprog();
	handle_result(result, &lost_points);

	ntests++;
	result = exec_badargs(NULL, "exec with NULL arglist");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_badargs(INVAL_PTR, "exec with invalid pointer arglist");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_badargs(KERN_PTR, "exec with kernel pointer arglist");
	handle_result(result, &lost_points);


	ntests++;
	result = exec_onearg(INVAL_PTR, "exec with invalid pointer arg");
	handle_result(result, &lost_points);

	ntests++;
	result = exec_onearg(KERN_PTR, "exec with kernel pointer arg");
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 11
0
static PyObject* evaluate_file(PyObject* self, PyObject* args, PyObject *keywds)
{
    const char *filename;
    char *out;
    unsigned max_stack = 500, gc_min_objects = 1000, max_trace = 20;
    double gc_growth_trigger = 2;
    int error;
    PyObject *ext_vars = NULL, *import_callback = NULL;
    struct JsonnetVm *vm;
    static char *kwlist[] = {"filename", "max_stack", "gc_min_objects", "gc_growth_trigger", "ext_vars", "max_trace", "import_callback", NULL};

    (void) self;

    if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|IIdOIO", kwlist,
                                     &filename,
                                     &max_stack, &gc_min_objects, &gc_growth_trigger, &ext_vars,
                                     &max_trace, &import_callback)) {
        return NULL;
    }

    vm = jsonnet_make();
    jsonnet_max_stack(vm, max_stack);
    jsonnet_gc_min_objects(vm, gc_min_objects);
    jsonnet_max_trace(vm, max_trace);
    jsonnet_gc_growth_trigger(vm, gc_growth_trigger);
    if (!handle_ext_vars(vm, ext_vars)) {
        return NULL;
    }
    struct ImportCtx ctx = { vm, import_callback };
    if (!handle_import_callback(&ctx, import_callback)) {
        return NULL;
    }

    out = jsonnet_evaluate_file(vm, filename, &error);
    return handle_result(vm, out, error);
}
Esempio n. 12
0
int
ACE_TMAIN (int , ACE_TCHAR **)
{
  PublisherPolicyTest publisher;
  SubscriberPolicyTest subscriber;
  DatawriterPolicyTest datawriter;
  DatareaderPolicyTest datareader;
  TopicPolicyTest topic;
  StatesTest states;
  DomainParticipantPolicyTest domainparticipant;

  int ret = 0;
  int test = 0;
  try
    {
      test = publisher.run ();
      ret += handle_result (test, "Publisher");
      test = subscriber.run ();
      ret += handle_result (test, "Subscriber");
      test = datawriter.run ();
      ret += handle_result (test, "Datawriter");
      test = datareader.run ();
      ret += handle_result (test, "DataReader");
      test = topic.run ();
      ret += handle_result (test, "Topic");
      test = domainparticipant.run ();
      ret += handle_result (test, "DomainParticipant");
      test = states.run ();
      ret += handle_result (test, "States");
      ret += test_string_seq ();
    }
  catch (...)
    {
      ACE_ERROR ((LM_ERROR, "ERROR: Unexpected exception caught."));
      return -1;
    }
  return 0;
}
Esempio n. 13
0
/* basic parsing test */
static void
parse_test (struct peer *peer, struct test_segment *t, int type)
{
  int parse_ret = 0, nlri_ret = 0;
  struct attr attr = { };
  struct bgp_nlri nlri = { };
  struct bgp_attr_parser_args attr_args = {
    .peer = peer,
    .length = t->len,
    .total = 1,
    .attr = &attr,
    .type = type,
    .flags = BGP_ATTR_FLAG_OPTIONAL, 
    .startp = BGP_INPUT_PNT (peer),
  };
#define RANDOM_FUZZ 35
  
  stream_reset (peer->ibuf);
  stream_put (peer->ibuf, NULL, RANDOM_FUZZ);
  stream_set_getp (peer->ibuf, RANDOM_FUZZ);
  
  stream_write (peer->ibuf, t->data, t->len);
  
  printf ("%s: %s\n", t->name, t->desc);
  
  if (type == BGP_ATTR_MP_REACH_NLRI)
    parse_ret = bgp_mp_reach_parse (&attr_args, &nlri);
  else
    parse_ret = bgp_mp_unreach_parse (&attr_args, &nlri);
  
  if (parse_ret == 0 && t->afi_valid == VALID_AFI)
    assert (nlri.afi == t->afi && nlri.safi == t->safi);
  
  if (!parse_ret)
    {
      if (type == BGP_ATTR_MP_REACH_NLRI)
        nlri_ret = bgp_nlri_parse (peer, &attr, &nlri);
      else
        nlri_ret = bgp_nlri_parse (peer, NULL, &nlri);
    }
  
  handle_result (peer, t, parse_ret, nlri_ret);
}

static struct bgp *bgp;
static as_t asn = 100;

int
main (void)
{
  struct peer *peer;
  int i, j;
  
  conf_bgp_debug_fsm = -1UL;
  conf_bgp_debug_events = -1UL;
  conf_bgp_debug_packet = -1UL;
  conf_bgp_debug_normal = -1UL;
  conf_bgp_debug_as4 = -1UL;
  term_bgp_debug_fsm = -1UL;
  term_bgp_debug_events = -1UL;
  term_bgp_debug_packet = -1UL;
  term_bgp_debug_normal = -1UL;
  term_bgp_debug_as4 = -1UL;
  
  master = thread_master_create ();
  bgp_master_init ();
  bgp_option_set (BGP_OPT_NO_LISTEN);
  bgp_attr_init ();
  bgp_address_init ();
  
  if (fileno (stdout) >= 0) 
    tty = isatty (fileno (stdout));
  
  if (bgp_get (&bgp, &asn, NULL))
    return -1;
  
  peer = peer_create_accept (bgp);
  peer->host = (char *)"foo";
  peer->status = Established;
  
  for (i = AFI_IP; i < AFI_MAX; i++)
    for (j = SAFI_UNICAST; j < SAFI_MAX; j++)
      {
        peer->afc[i][j] = 1;
        peer->afc_adv[i][j] = 1;
      }
  
  i = 0;
  while (mp_reach_segments[i].name)
    parse_test (peer, &mp_reach_segments[i++], BGP_ATTR_MP_REACH_NLRI);

  i = 0;
  while (mp_unreach_segments[i].name)
    parse_test (peer, &mp_unreach_segments[i++], BGP_ATTR_MP_UNREACH_NLRI);

  printf ("failures: %d\n", failed);
  return failed;
}
Esempio n. 14
0
int main()
{
    char input[16];
    int done = 0, state;

    if (!engine_init())
        return 1;
    init_states();

    while (!done)
    {
        state = read_keyword(input, sizeof(input));
        if (state == 0)
            break;
        if (state == STATE_ERROR)
            continue;
        
        //fprintf(stderr, "cmd %s state %d\n", input, state);


        switch (state)
        {
        case STATE_BLACK:
            engine_set_color(BLACK);
            break;
        case STATE_WHITE:
            engine_set_color(WHITE);
            break;
        case STATE_CGCBOARD:
            write_string("\n");
            break;
        case STATE_DRAW:
            engine_offer_draw();
            break;
        case STATE_FORCE:
            engine_set_go(0);
            break;
        case STATE_GO:
            engine_set_go(1);
            break;
        case STATE_NEW:
            engine_new();
            break;
        case STATE_RANDOM:
            engine_set_random(!engine_get_random());
            break;
        case STATE_RESULT:
            if (!handle_result())
                done = 1;
            break;
        case STATE_REMOVE:
            engine_undo();
            engine_undo();
            break;
        case STATE_QUIT:
            write_string("bye\n");
            done = 1;
            break;
        case STATE_SD:
            if (!handle_sd())
                done = 1;
            break;
        case STATE_UNDO:
            engine_undo();
            break;
        case STATE_MOVE:
            engine_move(str_to_move(input));
            break;
        case STATE_PLAY:
            engine_go();
            break;
        }
    }

    engine_destroy();

    return 0;
}
Esempio n. 15
0
int do_psync_account_stopshare(psync_shareid_t usershareids[], int nusershareid, psync_shareid_t teamshareids[], int nteamshareid, char **err) {
 psync_socket *api;
  binresult *bres;
  uint64_t result,userresult,teamresult;
  char *ids1 = NULL;
  char *ids2 = NULL;
  char *idsp = 0;
  int i,pind = 1, numparam = 1,k;
  binparam *t;
  const binresult *userres, *teamres, *statres;
  *err  = 0;
  
  numparam +=  !!nusershareid + !!nteamshareid;
  if (unlikely(numparam == 1))
    return -3;
    
  t = (binparam *) psync_malloc(numparam*sizeof(binparam));
  
  init_param_str(t, "auth", psync_my_auth);
  
  if (nusershareid) {
    ids1 = (char *) psync_malloc(nusershareid*FOLDERID_ENTRY_SIZE);
    idsp = ids1;
    for (i = 0; i < nusershareid; ++i) {
      k = sprintf(idsp, "%lld",(long long) usershareids[i]);
      if (unlikely(k <= 0 )) break;
      idsp[k] = ',';
      idsp = idsp + k + 1;
    }
    if (i > 0)
      *(idsp - 1) = '\0';
    //debug(D_NOTICE, "usershareids %s",ids1);
    init_param_str(t + pind++, "usershareids", ids1);
  }
  
  if (nteamshareid) {
    ids2 = (char *) psync_malloc(nteamshareid*FOLDERID_ENTRY_SIZE);
    idsp = ids2;
    for (i = 0; i < nteamshareid; ++i) {
      k = sprintf(idsp, "%lld", (long long) teamshareids[i]);
      if (unlikely(k <= 0 )) break;
      idsp[k] = ',';
      idsp = idsp + k + 1;
    }
    if (i > 0)
      *(idsp - 1) = '\0';
    //debug(D_NOTICE, "teamshareids %s",ids2);
    init_param_str(t + pind++, "teamshareids", ids2);
  }
  
  api=psync_apipool_get();
  if (unlikely(!api)) {
    debug(D_WARNING, "Can't gat api from the pool. No pool ?\n");
    return -2;
  }
  
  bres =  do_send_command(api, "account_stopshare", sizeof("account_stopshare") - 1, t, pind, -1, 1);
  
  if (likely(bres))
    psync_apipool_release(api);
  else {
    psync_apipool_release_bad(api);
    debug(D_WARNING, "Send command returned in valid result.\n");
    return -2;
  }
  
  result=psync_find_result(bres, "result", PARAM_NUM)->num;
  if (unlikely(result))
    return handle_result(bres, result, err);
 
  statres = psync_find_result(bres, "status", PARAM_HASH);
  teamres = psync_find_result(statres, "team", PARAM_ARRAY)->array[0];
  teamresult = psync_find_result(teamres, "result", PARAM_NUM)->num;
  userres = psync_find_result(statres, "user", PARAM_ARRAY)->array[0];
  userresult = psync_find_result(userres, "result", PARAM_NUM)->num;
  if (!userresult || !teamresult)
    result = 0;
  else {
    if(userresult == INVALID_SHAREDID_RESULT && teamresult == INVALID_SHAREDID_RESULT)
      result = handle_result(userres, userresult, err); 
    else if (userresult)
      result = handle_result(userres, userresult, err); 
    else 
      result = handle_result(teamres, teamresult, err); 
  }
  
  if (ids1)
    psync_free(ids1);
  if (ids2)
    psync_free(ids2);
  
  psync_free(bres);
  psync_free(t);
  
  return result;
  
}
Esempio n. 16
0
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#ifdef MACOS
#include <stdlib.h>
#ifdef THINK_C
#include <console.h>
#include <unix.h>
#include <fcntl.h>
#endif /* THINK_C */
#include "macos.h"
#else /* MACOS */
#if defined( DOS ) || defined( _WIN32 )
#ifdef DOS
#include "msdos.h"
#endif
#if defined( WINSOCK ) || defined( _WIN32 )
#include "console.h"
#endif /* WINSOCK */
#else /* DOS */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/file.h>
#ifndef VMS
#include <fcntl.h>
#include <unistd.h>
#endif /* VMS */
#endif /* DOS */
#endif /* MACOS */

#include "lber.h"
#include "ldap.h"

#if !defined( PCNFS ) && !defined( WINSOCK ) && !defined( MACOS )
#define MOD_USE_BVALS
#endif /* !PCNFS && !WINSOCK && !MACOS */

#ifdef NEEDPROTOS
static void handle_result( LDAP *ld, LDAPMessage *lm );
static void print_ldap_result( LDAP *ld, LDAPMessage *lm, char *s );
static void print_search_entry( LDAP *ld, LDAPMessage *res );
static void free_list( char **list );
#else
static void handle_result();
static void print_ldap_result();
static void print_search_entry();
static void free_list();
#endif /* NEEDPROTOS */

#define NOCACHEERRMSG \
		"don't compile with -DNO_CACHE if you desire local caching"

char *dnsuffix;

#ifndef WINSOCK
static char *
getline( char *line, int len, FILE *fp, char *prompt )
{
    printf(prompt);

    if ( fgets( line, len, fp ) == NULL )
        return( NULL );

    line[ strlen( line ) - 1 ] = '\0';

    return( line );
}
#endif /* WINSOCK */

static char **
get_list( char *prompt )
{
    static char	buf[256];
    int		num;
    char		**result;

    num = 0;
    result = (char **) 0;
    while ( 1 ) {
        getline( buf, sizeof(buf), stdin, prompt );

        if ( *buf == '\0' )
            break;

        if ( result == (char **) 0 )
            result = (char **) malloc( sizeof(char *) );
        else
            result = (char **) realloc( result,
                                        sizeof(char *) * (num + 1) );

        result[num++] = (char *) strdup( buf );
    }
    if ( result == (char **) 0 )
        return( NULL );
    result = (char **) realloc( result, sizeof(char *) * (num + 1) );
    result[num] = NULL;

    return( result );
}


static void
free_list( char **list )
{
    int	i;

    if ( list != NULL ) {
        for ( i = 0; list[ i ] != NULL; ++i ) {
            free( list[ i ] );
        }
        free( (char *)list );
    }
}


#ifdef MOD_USE_BVALS
static int
file_read( char *path, struct berval *bv )
{
    FILE		*fp;
    long		rlen;
    int		eof;

    if (( fp = fopen( path, "r" )) == NULL ) {
        perror( path );
        return( -1 );
    }

    if ( fseek( fp, 0L, SEEK_END ) != 0 ) {
        perror( path );
        fclose( fp );
        return( -1 );
    }

    bv->bv_len = ftell( fp );

    if (( bv->bv_val = (char *)malloc( bv->bv_len )) == NULL ) {
        perror( "malloc" );
        fclose( fp );
        return( -1 );
    }

    if ( fseek( fp, 0L, SEEK_SET ) != 0 ) {
        perror( path );
        fclose( fp );
        return( -1 );
    }

    rlen = fread( bv->bv_val, 1, bv->bv_len, fp );
    eof = feof( fp );
    fclose( fp );

    if ( rlen != bv->bv_len ) {
        perror( path );
        free( bv->bv_val );
        return( -1 );
    }

    return( bv->bv_len );
}
#endif /* MOD_USE_BVALS */


static LDAPMod **
get_modlist( char *prompt1, char *prompt2, char *prompt3 )
{
    static char	buf[256];
    int		num;
    LDAPMod		tmp;
    LDAPMod		**result;
#ifdef MOD_USE_BVALS
    struct berval	**bvals;
#endif /* MOD_USE_BVALS */

    num = 0;
    result = NULL;
    while ( 1 ) {
        if ( prompt1 ) {
            getline( buf, sizeof(buf), stdin, prompt1 );
            tmp.mod_op = atoi( buf );

            if ( tmp.mod_op == -1 || buf[0] == '\0' )
                break;
        }

        getline( buf, sizeof(buf), stdin, prompt2 );
        if ( buf[0] == '\0' )
            break;
        tmp.mod_type = strdup( buf );

        tmp.mod_values = get_list( prompt3 );
#ifdef MOD_USE_BVALS
        if ( tmp.mod_values != NULL ) {
            int	i;

            for ( i = 0; tmp.mod_values[i] != NULL; ++i )
                ;
            bvals = (struct berval **)calloc( i + 1,
                                              sizeof( struct berval *));
            for ( i = 0; tmp.mod_values[i] != NULL; ++i ) {
                bvals[i] = (struct berval *)malloc(
                               sizeof( struct berval ));
                if ( strncmp( tmp.mod_values[i], "{FILE}",
                              6 ) == 0 ) {
                    if ( file_read( tmp.mod_values[i] + 6,
                                    bvals[i] ) < 0 ) {
                        return( NULL );
                    }
                } else {
                    bvals[i]->bv_val = tmp.mod_values[i];
                    bvals[i]->bv_len =
                        strlen( tmp.mod_values[i] );
                }
            }
            tmp.mod_bvalues = bvals;
            tmp.mod_op |= LDAP_MOD_BVALUES;
        }
#endif /* MOD_USE_BVALS */

        if ( result == NULL )
            result = (LDAPMod **) malloc( sizeof(LDAPMod *) );
        else
            result = (LDAPMod **) realloc( result,
                                           sizeof(LDAPMod *) * (num + 1) );

        result[num] = (LDAPMod *) malloc( sizeof(LDAPMod) );
        *(result[num]) = tmp;	/* struct copy */
        num++;
    }
    if ( result == NULL )
        return( NULL );
    result = (LDAPMod **) realloc( result, sizeof(LDAPMod *) * (num + 1) );
    result[num] = NULL;

    return( result );
}


#ifdef LDAP_REFERRALS
int
bind_prompt( LDAP *ld, char **dnp, char **passwdp, int *authmethodp,
             int freeit )
{
    static char	dn[256], passwd[256];

    if ( !freeit ) {
#ifdef KERBEROS
        getline( dn, sizeof(dn), stdin, "re-bind method (0->simple, "
                 "1->krbv41, 2->krbv42, 3->krbv41&2)? " );
        if (( *authmethodp = atoi( dn )) == 3 ) {
            *authmethodp = LDAP_AUTH_KRBV4;
        } else {
            *authmethodp |= 0x80;
        }
#else /* KERBEROS */
        *authmethodp = LDAP_AUTH_SIMPLE;
#endif /* KERBEROS */

        getline( dn, sizeof(dn), stdin, "re-bind dn? " );
        strcat( dn, dnsuffix );
        *dnp = dn;

        if ( *authmethodp == LDAP_AUTH_SIMPLE && dn[0] != '\0' ) {
            getline( passwd, sizeof(passwd), stdin,
                     "re-bind password? " );
        } else {
            passwd[0] = '\0';
        }
        *passwdp = passwd;
    }

    return( LDAP_SUCCESS );
}
#endif /* LDAP_REFERRALS */


int
#ifdef WINSOCK
ldapmain(
#else /* WINSOCK */
main(
#endif /* WINSOCK */
    int argc, char **argv )
{
    LDAP		*ld;
    int		i, c, port, cldapflg, errflg, method, id, msgtype;
    char		line[256], command1, command2, command3;
    char		passwd[64], dn[256], rdn[64], attr[64], value[256];
    char		filter[256], *host, **types;
    char		**exdn;
    char		*usage = "usage: %s [-u] [-h host] [-d level] "
                         "[-s dnsuffix] [-p port] [-t file] [-T file]\n";
    int		bound, all, scope, attrsonly;
    LDAPMessage	*res;
    LDAPMod		**mods, **attrs;
    struct timeval	timeout;
    char		*copyfname = NULL;
    int		copyoptions = 0;
    LDAPURLDesc	*ludp;

    extern char	*optarg;
    extern int	optind;

#ifdef MACOS
    if (( argv = get_list( "cmd line arg?" )) == NULL ) {
        exit( 1 );
    }
    for ( argc = 0; argv[ argc ] != NULL; ++argc ) {
        ;
    }
#endif /* MACOS */

    host = NULL;
    port = LDAP_PORT;
    dnsuffix = "";
    cldapflg = errflg = 0;

    while (( c = getopt( argc, argv, "uh:d:s:p:t:T:" )) != -1 ) {
        switch( c ) {
        case 'u':
#ifdef CLDAP
            cldapflg++;
#else /* CLDAP */
            printf( "Compile with -DCLDAP for UDP support\n" );
#endif /* CLDAP */
            break;

        case 'd':
#ifdef LDAP_DEBUG
            ldap_debug = atoi( optarg );
            if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
                lber_debug = ldap_debug;
            }
#else
            printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
            break;

        case 'h':
            host = optarg;
            break;

        case 's':
            dnsuffix = optarg;
            break;

        case 'p':
            port = atoi( optarg );
            break;

#if !defined(MACOS) && !defined(DOS)
        case 't':	/* copy ber's to given file */
            copyfname = strdup( optarg );
            copyoptions = LBER_TO_FILE;
            break;

        case 'T':	/* only output ber's to given file */
            copyfname = strdup( optarg );
            copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY);
            break;
#endif

        default:
            ++errflg;
        }
    }

    if ( host == NULL && optind == argc - 1 ) {
        host = argv[ optind ];
        ++optind;
    }

    if ( errflg || optind < argc - 1 ) {
        fprintf( stderr, usage, argv[ 0 ] );
        exit( 1 );
    }

    printf( "%sldap_open( %s, %d )\n", cldapflg ? "c" : "",
            host == NULL ? "(null)" : host, port );

    if ( cldapflg ) {
#ifdef CLDAP
        ld = cldap_open( host, port );
#endif /* CLDAP */
    } else {
        ld = ldap_open( host, port );
    }

    if ( ld == NULL ) {
        perror( "ldap_open" );
        exit(1);
    }

#if !defined(MACOS) && !defined(DOS)
    if ( copyfname != NULL ) {
        if ( (ld->ld_sb.sb_fd = open( copyfname, O_WRONLY | O_CREAT,
                                      0600 ))  == -1 ) {
            perror( copyfname );
            exit ( 1 );
        }
        ld->ld_sb.sb_options = copyoptions;
    }
#endif

    bound = 0;
    timeout.tv_sec = 0;
    timeout.tv_usec = 0;

    (void) memset( line, '\0', sizeof(line) );
    while ( getline( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
        command1 = line[0];
        command2 = line[1];
        command3 = line[2];

        switch ( command1 ) {
        case 'a':	/* add or abandon */
            switch ( command2 ) {
            case 'd':	/* add */
                getline( dn, sizeof(dn), stdin, "dn? " );
                strcat( dn, dnsuffix );
                if ( (attrs = get_modlist( NULL, "attr? ",
                                           "value? " )) == NULL )
                    break;
                if ( (id = ldap_add( ld, dn, attrs )) == -1 )
                    ldap_perror( ld, "ldap_add" );
                else
                    printf( "Add initiated with id %d\n",
                            id );
                break;

            case 'b':	/* abandon */
                getline( line, sizeof(line), stdin, "msgid? " );
                id = atoi( line );
                if ( ldap_abandon( ld, id ) != 0 )
                    ldap_perror( ld, "ldap_abandon" );
                else
                    printf( "Abandon successful\n" );
                break;
            default:
                printf( "Possibilities: [ad]d, [ab]ort\n" );
            }
            break;

        case 'b':	/* asynch bind */
#ifdef KERBEROS
            getline( line, sizeof(line), stdin,
                     "method (0->simple, 1->krbv41, 2->krbv42)? " );
            method = atoi( line ) | 0x80;
#else /* KERBEROS */
            method = LDAP_AUTH_SIMPLE;
#endif /* KERBEROS */
            getline( dn, sizeof(dn), stdin, "dn? " );
            strcat( dn, dnsuffix );

            if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
                getline( passwd, sizeof(passwd), stdin,
                         "password? " );
            else
                passwd[0] = '\0';

            if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
                fprintf( stderr, "ldap_bind failed\n" );
                ldap_perror( ld, "ldap_bind" );
            } else {
                printf( "Bind initiated\n" );
                bound = 1;
            }
            break;

        case 'B':	/* synch bind */
#ifdef KERBEROS
            getline( line, sizeof(line), stdin,
                     "method 0->simple 1->krbv41 2->krbv42 3->krb? " );
            method = atoi( line );
            if ( method == 3 )
                method = LDAP_AUTH_KRBV4;
            else
                method = method | 0x80;
#else /* KERBEROS */
            method = LDAP_AUTH_SIMPLE;
#endif /* KERBEROS */
            getline( dn, sizeof(dn), stdin, "dn? " );
            strcat( dn, dnsuffix );

            if ( dn[0] != '\0' )
                getline( passwd, sizeof(passwd), stdin,
                         "password? " );
            else
                passwd[0] = '\0';

            if ( ldap_bind_s( ld, dn, passwd, method ) !=
                    LDAP_SUCCESS ) {
                fprintf( stderr, "ldap_bind_s failed\n" );
                ldap_perror( ld, "ldap_bind_s" );
            } else {
                printf( "Bind successful\n" );
                bound = 1;
            }
            break;

        case 'c':	/* compare */
            getline( dn, sizeof(dn), stdin, "dn? " );
            strcat( dn, dnsuffix );
            getline( attr, sizeof(attr), stdin, "attr? " );
            getline( value, sizeof(value), stdin, "value? " );

            if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
                ldap_perror( ld, "ldap_compare" );
            else
                printf( "Compare initiated with id %d\n", id );
            break;

        case 'd':	/* turn on debugging */
#ifdef LDAP_DEBUG
            getline( line, sizeof(line), stdin, "debug level? " );
            ldap_debug = atoi( line );
            if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
                lber_debug = ldap_debug;
            }
#else
            printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
            break;

        case 'E':	/* explode a dn */
            getline( line, sizeof(line), stdin, "dn? " );
            exdn = ldap_explode_dn( line, 0 );
            for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
                printf( "\t%s\n", exdn[i] );
            }
            break;

        case 'g':	/* set next msgid */
            getline( line, sizeof(line), stdin, "msgid? " );
            ld->ld_msgid = atoi( line );
            break;

        case 'v':	/* set version number */
            getline( line, sizeof(line), stdin, "version? " );
            ld->ld_version = atoi( line );
            break;

        case 'm':	/* modify or modifyrdn */
            if ( strncmp( line, "modify", 4 ) == 0 ) {
                getline( dn, sizeof(dn), stdin, "dn? " );
                strcat( dn, dnsuffix );
                if ( (mods = get_modlist(
                                 "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
                                 "attribute type? ", "attribute value? " ))
                        == NULL )
                    break;
                if ( (id = ldap_modify( ld, dn, mods )) == -1 )
                    ldap_perror( ld, "ldap_modify" );
                else
                    printf( "Modify initiated with id %d\n",
                            id );
            } else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
                getline( dn, sizeof(dn), stdin, "dn? " );
                strcat( dn, dnsuffix );
                getline( rdn, sizeof(rdn), stdin, "newrdn? " );
                if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
                    ldap_perror( ld, "ldap_modrdn" );
                else
                    printf( "Modrdn initiated with id %d\n",
                            id );
            } else {
                printf( "Possibilities: [modi]fy, [modr]dn\n" );
            }
            break;

        case 'q':	/* quit */
#ifdef CLDAP
            if ( cldapflg )
                cldap_close( ld );
#endif /* CLDAP */
#ifdef LDAP_REFERRALS
            if ( !cldapflg )
#else /* LDAP_REFERRALS */
            if ( !cldapflg && bound )
#endif /* LDAP_REFERRALS */
                ldap_unbind( ld );
            exit( 0 );
            break;

        case 'r':	/* result or remove */
            switch ( command3 ) {
            case 's':	/* result */
                getline( line, sizeof(line), stdin,
                         "msgid (-1=>any)? " );
                if ( line[0] == '\0' )
                    id = -1;
                else
                    id = atoi( line );
                getline( line, sizeof(line), stdin,
                         "all (0=>any, 1=>all)? " );
                if ( line[0] == '\0' )
                    all = 1;
                else
                    all = atoi( line );
                if (( msgtype = ldap_result( ld, id, all,
                                             &timeout, &res )) < 1 ) {
                    ldap_perror( ld, "ldap_result" );
                    break;
                }
                printf( "\nresult: msgtype %d msgid %d\n",
                        msgtype, res->lm_msgid );
                handle_result( ld, res );
                res = NULLMSG;
                break;

            case 'm':	/* remove */
                getline( dn, sizeof(dn), stdin, "dn? " );
                strcat( dn, dnsuffix );
                if ( (id = ldap_delete( ld, dn )) == -1 )
                    ldap_perror( ld, "ldap_delete" );
                else
                    printf( "Remove initiated with id %d\n",
                            id );
                break;

            default:
                printf( "Possibilities: [rem]ove, [res]ult\n" );
                break;
            }
            break;

        case 's':	/* search */
            getline( dn, sizeof(dn), stdin, "searchbase? " );
            strcat( dn, dnsuffix );
            getline( line, sizeof(line), stdin,
                     "scope (0=Base, 1=One Level, 2=Subtree)? " );
            scope = atoi( line );
            getline( filter, sizeof(filter), stdin,
                     "search filter (e.g. sn=jones)? " );
            types = get_list( "attrs to return? " );
            getline( line, sizeof(line), stdin,
                     "attrsonly (0=attrs&values, 1=attrs only)? " );
            attrsonly = atoi( line );

            if ( cldapflg ) {
#ifdef CLDAP
                getline( line, sizeof(line), stdin,
                         "Requestor DN (for logging)? " );
                if ( cldap_search_s( ld, dn, scope, filter, types,
                                     attrsonly, &res, line ) != 0 ) {
                    ldap_perror( ld, "cldap_search_s" );
                } else {
                    printf( "\nresult: msgid %d\n",
                            res->lm_msgid );
                    handle_result( ld, res );
                    res = NULLMSG;
                }
#endif /* CLDAP */
            } else {
                if (( id = ldap_search( ld, dn, scope, filter,
                                        types, attrsonly  )) == -1 ) {
                    ldap_perror( ld, "ldap_search" );
                } else {
                    printf( "Search initiated with id %d\n", id );
                }
            }
            free_list( types );
            break;

        case 't':	/* set timeout value */
            getline( line, sizeof(line), stdin, "timeout? " );
            timeout.tv_sec = atoi( line );
            break;

        case 'U':	/* set ufn search prefix */
            getline( line, sizeof(line), stdin, "ufn prefix? " );
            ldap_ufn_setprefix( ld, line );
            break;

        case 'u':	/* user friendly search w/optional timeout */
            getline( dn, sizeof(dn), stdin, "ufn? " );
            strcat( dn, dnsuffix );
            types = get_list( "attrs to return? " );
            getline( line, sizeof(line), stdin,
                     "attrsonly (0=attrs&values, 1=attrs only)? " );
            attrsonly = atoi( line );

            if ( command2 == 't' ) {
                id = ldap_ufn_search_c( ld, dn, types,
                                        attrsonly, &res, ldap_ufn_timeout,
                                        &timeout );
            } else {
                id = ldap_ufn_search_s( ld, dn, types,
                                        attrsonly, &res );
            }
            if ( res == NULL )
                ldap_perror( ld, "ldap_ufn_search" );
            else {
                printf( "\nresult: err %d\n", id );
                handle_result( ld, res );
                res = NULLMSG;
            }
            free_list( types );
            break;

        case 'l':	/* URL search */
            getline( line, sizeof(line), stdin,
                     "attrsonly (0=attrs&values, 1=attrs only)? " );
            attrsonly = atoi( line );
            getline( line, sizeof(line), stdin, "LDAP URL? " );
            if (( id = ldap_url_search( ld, line, attrsonly  ))
                    == -1 ) {
                ldap_perror( ld, "ldap_url_search" );
            } else {
                printf( "URL search initiated with id %d\n", id );
            }
            break;

        case 'p':	/* parse LDAP URL */
            getline( line, sizeof(line), stdin, "LDAP URL? " );
            if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
                fprintf( stderr, "ldap_url_parse: error %d\n", i );
            } else {
                printf( "\t  host: " );
                if ( ludp->lud_host == NULL ) {
                    printf( "DEFAULT\n" );
                } else {
                    printf( "<%s>\n", ludp->lud_host );
                }
                printf( "\t  port: " );
                if ( ludp->lud_port == 0 ) {
                    printf( "DEFAULT\n" );
                } else {
                    printf( "%d\n", ludp->lud_port );
                }
                printf( "\t    dn: <%s>\n", ludp->lud_dn );
                printf( "\t attrs:" );
                if ( ludp->lud_attrs == NULL ) {
                    printf( " ALL" );
                } else {
                    for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
                        printf( " <%s>", ludp->lud_attrs[ i ] );
                    }
                }
                printf( "\n\t scope: %s\n",
                        ludp->lud_scope == LDAP_SCOPE_ONELEVEL ? "ONE"
                        : ludp->lud_scope == LDAP_SCOPE_BASE ? "BASE" :
                        ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "SUB" :
                        "**invalid**" );
                printf( "\tfilter: <%s>\n", ludp->lud_filter );
                ldap_free_urldesc( ludp );
            }
            break;

        case 'n':	/* set dn suffix, for convenience */
            getline( line, sizeof(line), stdin, "DN suffix? " );
            strcpy( dnsuffix, line );
            break;

        case 'e':	/* enable cache */
#ifdef NO_CACHE
            printf( NOCACHEERRMSG );
#else /* NO_CACHE */
            getline( line, sizeof(line), stdin,
                     "Cache timeout (secs)? " );
            i = atoi( line );
            getline( line, sizeof(line), stdin,
                     "Maximum memory to use (bytes)? " );
            if ( ldap_enable_cache( ld, i, atoi( line )) == 0 ) {
                printf( "local cache is on\n" );
            } else {
                printf( "ldap_enable_cache failed\n" );
            }
#endif /* NO_CACHE */
            break;

        case 'x':	/* uncache entry */
#ifdef NO_CACHE
            printf( NOCACHEERRMSG );
#else /* NO_CACHE */
            getline( line, sizeof(line), stdin, "DN? " );
            ldap_uncache_entry( ld, line );
#endif /* NO_CACHE */
            break;

        case 'X':	/* uncache request */
#ifdef NO_CACHE
            printf( NOCACHEERRMSG );
#else /* NO_CACHE */
            getline( line, sizeof(line), stdin, "request msgid? " );
            ldap_uncache_request( ld, atoi( line ));
#endif /* NO_CACHE */
            break;

        case 'o':	/* set ldap options */
            getline( line, sizeof(line), stdin,
                     "alias deref (0=never, 1=searching, 2"
                     "=finding, 3=always)?" );
            ld->ld_deref = atoi( line );
            getline( line, sizeof(line), stdin, "timelimit?" );
            ld->ld_timelimit = atoi( line );
            getline( line, sizeof(line), stdin, "sizelimit?" );
            ld->ld_sizelimit = atoi( line );

            ld->ld_options = 0;

#ifdef STR_TRANSLATION
            getline( line, sizeof(line), stdin,
                     "Automatic translation of T.61 strings "
                     "(0=no, 1=yes)?" );
            if ( atoi( line ) == 0 ) {
                ld->ld_lberoptions &= ~LBER_TRANSLATE_STRINGS;
            } else {
                ld->ld_lberoptions |= LBER_TRANSLATE_STRINGS;
#ifdef LDAP_CHARSET_8859
                getline( line, sizeof(line), stdin,
                         "Translate to/from ISO-8859 "
                         "(0=no, 1=yes?" );
                if ( atoi( line ) != 0 ) {
                    ldap_set_string_translators( ld,
                                                 ldap_8859_to_t61,
                                                 ldap_t61_to_8859 );
                }
#endif /* LDAP_CHARSET_8859 */
            }
#endif /* STR_TRANSLATION */

#ifdef LDAP_DNS
            getline( line, sizeof(line), stdin,
                     "Use DN & DNS to determine where to send "
                     "requests (0=no, 1=yes)?" );
            if ( atoi( line ) != 0 ) {
                ld->ld_options |= LDAP_OPT_DNS;
            }
#endif /* LDAP_DNS */

#ifdef LDAP_REFERRALS
            getline( line, sizeof(line), stdin,
                     "Recognize and chase referrals (0=no, 1=yes)?");
            if ( atoi( line ) != 0 ) {
                ld->ld_options |= LDAP_OPT_REFERRALS;
                getline( line, sizeof(line), stdin,
                         "Prompt for bind credentials when "
                         "chasing referrals (0=no, 1=yes)?" );
                if ( atoi( line ) != 0 ) {
                    ldap_set_rebind_proc( ld, bind_prompt );
                }
            }
#endif /* LDAP_REFERRALS */
            break;

        case 'O':	/* set cache options */
#ifdef NO_CACHE
            printf( NOCACHEERRMSG );
#else /* NO_CACHE */
            getline( line, sizeof(line), stdin,
                     "cache errors (0=smart, 1=never, 2=always)?" );
            switch( atoi( line )) {
            case 0:
                ldap_set_cache_options( ld, 0 );
                break;
            case 1:
                ldap_set_cache_options( ld,
                                        LDAP_CACHE_OPT_CACHENOERRS );
                break;
            case 2:
                ldap_set_cache_options( ld,
                                        LDAP_CACHE_OPT_CACHEALLERRS );
                break;
            default:
                printf( "not a valid cache option\n" );
            }
#endif /* NO_CACHE */
            break;

        case '?':	/* help */
            printf( "Commands: [ad]d         [ab]andon         [b]ind\n" );
            printf( "          [B]ind async  [c]ompare         [l]URL search\n" );
            printf( "          [modi]fy      [modr]dn          [rem]ove\n" );
            printf( "          [res]ult      [s]earch          [q]uit/unbind\n\n" );
            printf( "          [u]fn search  [ut]fn search with timeout\n" );
            printf( "          [d]ebug       [e]nable cache    set ms[g]id\n" );
            printf( "          d[n]suffix    [t]imeout         [v]ersion\n" );
            printf( "          [U]fn prefix  [x]uncache entry  [X]uncache request\n" );
            printf( "          [?]help       [o]ptions         [O]cache options\n" );
            printf( "          [E]xplode dn  [p]arse LDAP URL\n" );
            break;

        default:
            printf( "Invalid command.  Type ? for help.\n" );
            break;
        }

        (void) memset( line, '\0', sizeof(line) );
    }

    return( 0 );
}
Esempio n. 17
0
void
test_waitpid(void)
{
	int ntests = 0, lost_points = 0;
	int result;

	ntests++;
	result = wait_badpid(-8, "wait for pid -8");
	handle_result(result, &lost_points);

	ntests++;
	result = wait_badpid(-1, "wait for pid -1");
	handle_result(result, &lost_points);

	ntests++;
	result = wait_badpid(0, "pid zero");
	handle_result(result, &lost_points);

	ntests++;
	result = wait_badpid(NONEXIST_PID, "nonexistent pid");
	handle_result(result, &lost_points);


	ntests++;
	result = wait_nullstatus();
	handle_result(result, &lost_points);

	ntests++;
	result = wait_badstatus(INVAL_PTR, "wait with invalid pointer status");
	handle_result(result, &lost_points);

	ntests++;
	result = wait_badstatus(KERN_PTR, "wait with kernel pointer status");
	handle_result(result, &lost_points);


	ntests++;
	result = wait_unaligned();
	handle_result(result, &lost_points);


	ntests++;
	result = wait_badflags();
	handle_result(result, &lost_points);


	ntests++;
	result = wait_self();
	handle_result(result, &lost_points);

	ntests++;
	result = wait_parent();
	handle_result(result, &lost_points);

	ntests++;
	result = wait_siblings();
	handle_result(result, &lost_points);

	if(!lost_points)
		success(TEST161_SUCCESS, SECRET, "/testbin/badcall");
}
Esempio n. 18
0
int
main( int argc, char **argv )
{
	LDAP		*ld = NULL;
	int		i, c, port, errflg, method, id, msgtype;
	char		line[256], command1, command2, command3;
	char		passwd[64], dn[256], rdn[64], attr[64], value[256];
	char		filter[256], *host, **types;
	char		**exdn;
	static const char usage[] =
		"usage: %s [-u] [-h host] [-d level] [-s dnsuffix] [-p port] [-t file] [-T file]\n";
	int		bound, all, scope, attrsonly;
	LDAPMessage	*res;
	LDAPMod		**mods, **attrs;
	struct timeval	timeout;
	char		*copyfname = NULL;
	int		copyoptions = 0;
	LDAPURLDesc	*ludp;

	host = NULL;
	port = LDAP_PORT;
	dnsuffix = "";
	errflg = 0;

	while (( c = getopt( argc, argv, "h:d:s:p:t:T:" )) != -1 ) {
		switch( c ) {
		case 'd':
#ifdef LDAP_DEBUG
			ldap_debug = atoi( optarg );
#ifdef LBER_DEBUG
			if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
				ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
			}
#endif
#else
			printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
			break;

		case 'h':
			host = optarg;
			break;

		case 's':
			dnsuffix = optarg;
			break;

		case 'p':
			port = atoi( optarg );
			break;

		case 't':	/* copy ber's to given file */
			copyfname = strdup( optarg );
/*			copyoptions = LBER_TO_FILE; */
			break;

		case 'T':	/* only output ber's to given file */
			copyfname = strdup( optarg );
/*			copyoptions = (LBER_TO_FILE | LBER_TO_FILE_ONLY); */
			break;

		default:
		    ++errflg;
		}
	}

	if ( host == NULL && optind == argc - 1 ) {
		host = argv[ optind ];
		++optind;
	}

	if ( errflg || optind < argc - 1 ) {
		fprintf( stderr, usage, argv[ 0 ] );
		exit( EXIT_FAILURE );
	}
	
	printf( "ldap_init( %s, %d )\n",
		host == NULL ? "(null)" : host, port );

	ld = ldap_init( host, port );

	if ( ld == NULL ) {
		perror( "ldap_init" );
		exit( EXIT_FAILURE );
	}

	if ( copyfname != NULL ) {
		if ( ( ld->ld_sb->sb_fd = open( copyfname, O_WRONLY|O_CREAT|O_EXCL,
		    0600 ))  == -1 ) {
			perror( copyfname );
			exit ( EXIT_FAILURE );
		}
		ld->ld_sb->sb_options = copyoptions;
	}

	bound = 0;
	timeout.tv_sec = 0;
	timeout.tv_usec = 0;

	(void) memset( line, '\0', sizeof(line) );
	while ( get_line( line, sizeof(line), stdin, "\ncommand? " ) != NULL ) {
		command1 = line[0];
		command2 = line[1];
		command3 = line[2];

		switch ( command1 ) {
		case 'a':	/* add or abandon */
			switch ( command2 ) {
			case 'd':	/* add */
				get_line( dn, sizeof(dn), stdin, "dn? " );
				strcat( dn, dnsuffix );
				if ( (attrs = get_modlist( NULL, "attr? ",
				    "value? " )) == NULL )
					break;
				if ( (id = ldap_add( ld, dn, attrs )) == -1 )
					ldap_perror( ld, "ldap_add" );
				else
					printf( "Add initiated with id %d\n",
					    id );
				break;

			case 'b':	/* abandon */
				get_line( line, sizeof(line), stdin, "msgid? " );
				id = atoi( line );
				if ( ldap_abandon( ld, id ) != 0 )
					ldap_perror( ld, "ldap_abandon" );
				else
					printf( "Abandon successful\n" );
				break;
			default:
				printf( "Possibilities: [ad]d, [ab]ort\n" );
			}
			break;

		case 'b':	/* asynch bind */
			method = LDAP_AUTH_SIMPLE;
			get_line( dn, sizeof(dn), stdin, "dn? " );
			strcat( dn, dnsuffix );

			if ( method == LDAP_AUTH_SIMPLE && dn[0] != '\0' )
				get_line( passwd, sizeof(passwd), stdin,
				    "password? " );
			else
				passwd[0] = '\0';

			if ( ldap_bind( ld, dn, passwd, method ) == -1 ) {
				fprintf( stderr, "ldap_bind failed\n" );
				ldap_perror( ld, "ldap_bind" );
			} else {
				printf( "Bind initiated\n" );
				bound = 1;
			}
			break;

		case 'B':	/* synch bind */
			method = LDAP_AUTH_SIMPLE;
			get_line( dn, sizeof(dn), stdin, "dn? " );
			strcat( dn, dnsuffix );

			if ( dn[0] != '\0' )
				get_line( passwd, sizeof(passwd), stdin,
				    "password? " );
			else
				passwd[0] = '\0';

			if ( ldap_bind_s( ld, dn, passwd, method ) !=
			    LDAP_SUCCESS ) {
				fprintf( stderr, "ldap_bind_s failed\n" );
				ldap_perror( ld, "ldap_bind_s" );
			} else {
				printf( "Bind successful\n" );
				bound = 1;
			}
			break;

		case 'c':	/* compare */
			get_line( dn, sizeof(dn), stdin, "dn? " );
			strcat( dn, dnsuffix );
			get_line( attr, sizeof(attr), stdin, "attr? " );
			get_line( value, sizeof(value), stdin, "value? " );

			if ( (id = ldap_compare( ld, dn, attr, value )) == -1 )
				ldap_perror( ld, "ldap_compare" );
			else
				printf( "Compare initiated with id %d\n", id );
			break;

		case 'd':	/* turn on debugging */
#ifdef LDAP_DEBUG
			get_line( line, sizeof(line), stdin, "debug level? " );
			ldap_debug = atoi( line );
#ifdef LBER_DEBUG
			if ( ldap_debug & LDAP_DEBUG_PACKETS ) {
				ber_set_option( NULL, LBER_OPT_DEBUG_LEVEL, &ldap_debug );
			}
#endif
#else
			printf( "Compile with -DLDAP_DEBUG for debugging\n" );
#endif
			break;

		case 'E':	/* explode a dn */
			get_line( line, sizeof(line), stdin, "dn? " );
			exdn = ldap_explode_dn( line, 0 );
			for ( i = 0; exdn != NULL && exdn[i] != NULL; i++ ) {
				printf( "\t%s\n", exdn[i] );
			}
			break;

		case 'g':	/* set next msgid */
			get_line( line, sizeof(line), stdin, "msgid? " );
			ld->ld_msgid = atoi( line );
			break;

		case 'v':	/* set version number */
			get_line( line, sizeof(line), stdin, "version? " );
			ld->ld_version = atoi( line );
			break;

		case 'm':	/* modify or modifyrdn */
			if ( strncmp( line, "modify", 4 ) == 0 ) {
				get_line( dn, sizeof(dn), stdin, "dn? " );
				strcat( dn, dnsuffix );
				if ( (mods = get_modlist(
				    "mod (0=>add, 1=>delete, 2=>replace -1=>done)? ",
				    "attribute type? ", "attribute value? " ))
				    == NULL )
					break;
				if ( (id = ldap_modify( ld, dn, mods )) == -1 )
					ldap_perror( ld, "ldap_modify" );
				else
					printf( "Modify initiated with id %d\n",
					    id );
			} else if ( strncmp( line, "modrdn", 4 ) == 0 ) {
				get_line( dn, sizeof(dn), stdin, "dn? " );
				strcat( dn, dnsuffix );
				get_line( rdn, sizeof(rdn), stdin, "newrdn? " );
				if ( (id = ldap_modrdn( ld, dn, rdn )) == -1 )
					ldap_perror( ld, "ldap_modrdn" );
				else
					printf( "Modrdn initiated with id %d\n",
					    id );
			} else {
				printf( "Possibilities: [modi]fy, [modr]dn\n" );
			}
			break;

		case 'q':	/* quit */
			ldap_unbind( ld );
			exit( EXIT_SUCCESS );
			break;

		case 'r':	/* result or remove */
			switch ( command3 ) {
			case 's':	/* result */
				get_line( line, sizeof(line), stdin,
				    "msgid (-1=>any)? " );
				if ( line[0] == '\0' )
					id = -1;
				else
					id = atoi( line );
				get_line( line, sizeof(line), stdin,
				    "all (0=>any, 1=>all)? " );
				if ( line[0] == '\0' )
					all = 1;
				else
					all = atoi( line );
				if (( msgtype = ldap_result( ld, id, all,
				    &timeout, &res )) < 1 ) {
					ldap_perror( ld, "ldap_result" );
					break;
				}
				printf( "\nresult: msgtype %d msgid %d\n",
				    msgtype, res->lm_msgid );
				handle_result( ld, res );
				res = NULL;
				break;

			case 'm':	/* remove */
				get_line( dn, sizeof(dn), stdin, "dn? " );
				strcat( dn, dnsuffix );
				if ( (id = ldap_delete( ld, dn )) == -1 )
					ldap_perror( ld, "ldap_delete" );
				else
					printf( "Remove initiated with id %d\n",
					    id );
				break;

			default:
				printf( "Possibilities: [rem]ove, [res]ult\n" );
				break;
			}
			break;

		case 's':	/* search */
			get_line( dn, sizeof(dn), stdin, "searchbase? " );
			strcat( dn, dnsuffix );
			get_line( line, sizeof(line), stdin,
			    "scope (0=baseObject, 1=oneLevel, 2=subtree, 3=children)? " );
			scope = atoi( line );
			get_line( filter, sizeof(filter), stdin,
			    "search filter (e.g. sn=jones)? " );
			types = get_list( "attrs to return? " );
			get_line( line, sizeof(line), stdin,
			    "attrsonly (0=attrs&values, 1=attrs only)? " );
			attrsonly = atoi( line );

			    if (( id = ldap_search( ld, dn, scope, filter,
				    types, attrsonly  )) == -1 ) {
				ldap_perror( ld, "ldap_search" );
			    } else {
				printf( "Search initiated with id %d\n", id );
			    }
			free_list( types );
			break;

		case 't':	/* set timeout value */
			get_line( line, sizeof(line), stdin, "timeout? " );
			timeout.tv_sec = atoi( line );
			break;

		case 'p':	/* parse LDAP URL */
			get_line( line, sizeof(line), stdin, "LDAP URL? " );
			if (( i = ldap_url_parse( line, &ludp )) != 0 ) {
			    fprintf( stderr, "ldap_url_parse: error %d\n", i );
			} else {
			    printf( "\t  host: " );
			    if ( ludp->lud_host == NULL ) {
				printf( "DEFAULT\n" );
			    } else {
				printf( "<%s>\n", ludp->lud_host );
			    }
			    printf( "\t  port: " );
			    if ( ludp->lud_port == 0 ) {
				printf( "DEFAULT\n" );
			    } else {
				printf( "%d\n", ludp->lud_port );
			    }
			    printf( "\t    dn: <%s>\n", ludp->lud_dn );
			    printf( "\t attrs:" );
			    if ( ludp->lud_attrs == NULL ) {
				printf( " ALL" );
			    } else {
				for ( i = 0; ludp->lud_attrs[ i ] != NULL; ++i ) {
				    printf( " <%s>", ludp->lud_attrs[ i ] );
				}
			    }
			    printf( "\n\t scope: %s\n",
					ludp->lud_scope == LDAP_SCOPE_BASE ? "baseObject"
					: ludp->lud_scope == LDAP_SCOPE_ONELEVEL ? "oneLevel"
					: ludp->lud_scope == LDAP_SCOPE_SUBTREE ? "subtree"
#ifdef LDAP_SCOPE_SUBORDINATE
					: ludp->lud_scope == LDAP_SCOPE_SUBORDINATE ? "children"
#endif
					: "**invalid**" );
			    printf( "\tfilter: <%s>\n", ludp->lud_filter );
			    ldap_free_urldesc( ludp );
			}
			    break;

		case 'n':	/* set dn suffix, for convenience */
			get_line( line, sizeof(line), stdin, "DN suffix? " );
			strcpy( dnsuffix, line );
			break;

		case 'o':	/* set ldap options */
			get_line( line, sizeof(line), stdin, "alias deref (0=never, 1=searching, 2=finding, 3=always)?" );
			ld->ld_deref = atoi( line );
			get_line( line, sizeof(line), stdin, "timelimit?" );
			ld->ld_timelimit = atoi( line );
			get_line( line, sizeof(line), stdin, "sizelimit?" );
			ld->ld_sizelimit = atoi( line );

			LDAP_BOOL_ZERO(&ld->ld_options);

			get_line( line, sizeof(line), stdin,
				"Recognize and chase referrals (0=no, 1=yes)?" );
			if ( atoi( line ) != 0 ) {
				LDAP_BOOL_SET(&ld->ld_options, LDAP_BOOL_REFERRALS);
				get_line( line, sizeof(line), stdin,
					"Prompt for bind credentials when chasing referrals (0=no, 1=yes)?" );
				if ( atoi( line ) != 0 ) {
					ldap_set_rebind_proc( ld, bind_prompt, NULL );
				}
			}
			break;

		case '?':	/* help */
			printf(
"Commands: [ad]d         [ab]andon         [b]ind\n"
"          [B]ind async  [c]ompare\n"
"          [modi]fy      [modr]dn          [rem]ove\n"
"          [res]ult      [s]earch          [q]uit/unbind\n\n"
"          [d]ebug       set ms[g]id\n"
"          d[n]suffix    [t]imeout         [v]ersion\n"
"          [?]help       [o]ptions"
"          [E]xplode dn  [p]arse LDAP URL\n" );
			break;

		default:
			printf( "Invalid command.  Type ? for help.\n" );
			break;
		}

		(void) memset( line, '\0', sizeof(line) );
	}

	return( 0 );
}
Esempio n. 19
0
void
handle_method_call (GDBusConnection * connection,
    const gchar * sender,
    const gchar * object_path,
    const gchar * interface_name,
    const gchar * method_name,
    GVariant * parameters, GDBusMethodInvocation * invocation, SnappyMP * myobj)
{
  gboolean ret = TRUE;
  GError *error = NULL;

  if (g_strcmp0 (object_path, MPRIS_OBJECT_NAME) != 0 ||
      g_strcmp0 (interface_name, MPRIS_PLAYER_INTERFACE) != 0) {
    g_dbus_method_invocation_return_error (invocation,
        G_DBUS_ERROR,
        G_DBUS_ERROR_NOT_SUPPORTED,
        "Method %s.%s not supported", interface_name, method_name);
    return;
  }

  if (g_strcmp0 (method_name, "OpenUri") == 0) {
    gchar *uri;

    // g_print ("openUri.. uri: %s\n", uri);
    g_variant_get (parameters, "(s)", &uri);
    my_object_change_uri (myobj, uri);

    g_dbus_method_invocation_return_value (invocation, NULL);

  } else if (g_strcmp0 (method_name, "Next") == 0) {
    /// ToDo: next track call

    handle_result (invocation, ret, error);

  } else if (g_strcmp0 (method_name, "Play") == 0) {
    engine_play (myobj->engine);

    handle_result (invocation, ret, error);

  } else if (g_strcmp0 (method_name, "Pause") == 0) {
    change_state (myobj->engine, "Paused");

    handle_result (invocation, ret, error);
  } else if (g_strcmp0 (method_name, "Stop") == 0) {
    engine_stop (myobj->engine);

    handle_result (invocation, ret, error);

  } else if (g_strcmp0 (method_name, "Seek") == 0) {
    gint64 offset, position;
    gfloat relative;

    g_variant_get (parameters, "(x)", &offset);
    relative = offset / 100000000.0;
    position = myobj->engine->media_duration * relative;
    // g_print ("offset: %ld    relative: %f", offset, relative);
    engine_seek (myobj->engine, position, FALSE);

    handle_result (invocation, ret, error);

  }
}
Esempio n. 20
0
int main_loop(APP& app) {
    DB_WORKUNIT wu;
    DB_RESULT canonical_result, result;
    DB_APP_VERSION app_version;     // http://boinc.berkeley.edu/doxygen/server/html/classDB__APP__VERSION.html
    char buf[256];
    char buf2[256];
    int retval;
    task_t task;


    while(1) {
        check_stop_daemons();

        sprintf(buf, "WHERE appid=%d AND assimilate_state=%d AND error_mask<>16", app.id, ASSIMILATE_READY);
        // Заполнение полей текущего ворк юнита
        retval = wu.enumerate(buf);
        if (retval) {
            if (retval != ERR_DB_NOT_FOUND) {
                log_messages.printf(MSG_DEBUG, "DB connection lost, exiting\n");
                exit(0);
            }
        }

        // Заполнение полей текущего задания
        sscanf(wu.name, "%[^_]_%d_%d_%[^_]_%d_%*d_%d.%[^_]", task.app_name, &task.id, &task.uid, task.name, &task.timestamp, &task.size, task.extension);
        sprintf(buf, "SELECT login FROM user WHERE id=%d", task.uid);
        mysql_query(frontend_db, buf);
        mysql_result = mysql_store_result(frontend_db);
        if ((row = mysql_fetch_row(mysql_result)) != NULL) {
            strcpy(task.login, row[0]);
        }

        // Создание списка результатов задания
        vector<RESULT> results;
        if (strlen(task.name) > 0) {
            sprintf(buf, "INNER JOIN workunit ON result.id = workunit.canonical_resultid WHERE workunit.name like \"%%_%d_%d_%s_%%\" and workunit.assimilate_state=%d and workunit.error_mask<>16", task.id, task.uid, task.name, ASSIMILATE_READY);
            while (!result.enumerate(buf)) {
                results.push_back(result);
            }
        }

        // Склеивание заданий
        if ((results.size() == task.size) && (task.size != 0)) {
            log_messages.printf(MSG_NORMAL,"[%d_%s] Assimilating task\n", task.uid, task.name);
            retval = handle_result(task, results);
            if (retval) {
                log_messages.printf(MSG_CRITICAL,"[%d_%s] Assimilation failed\n", task.uid, task.name);
            } else {
                // Обновление записей в базе
                if (update_db) {
                    sprintf(buf, "assimilate_state=%d, transition_time=%d", ASSIMILATE_DONE, (int)time(0));
                    sprintf(buf2, "appid=%d and assimilate_state=%d and name like \"%%_%d_%d_%s_%%\"", app.id, ASSIMILATE_READY, task.id, task.uid, task.name);
                    wu.update_fields_noid(buf, buf2);
                    boinc_db.commit_transaction();
                    // Обновление планктона
                    update_plankton(task, app_version);
                    update_plankton_percent(results, task);
                }
                log_messages.printf(MSG_NORMAL,"[%d_%s] Task assimilated\n", task.uid, task.name);

                //Очистка всех структур
                wu.clear();
                memset(&task, 0, sizeof(task));
                results.clear();
            }
        } else {
            if (results.size()) {
                update_plankton_percent(results, task);
            }
        }
        sleep(SLEEP_INTERVAL);
    }
}
void JSONBooleanGenerator::boolean_value(bool to_write)
  {
    validate(to_write);
    handle_result(to_write);
  }