Esempio n. 1
0
/*
 * lookup instance names by suffix.
 * if isexact == 0: returns instances including ones that associates with
 *					its sub suffixes.
 *					e.g., suffix: "o=<suffix>" is given, these are returned:
 *						  suffixes: o=<suffix>, ou=<ou>,o=<suffix>, ...
 *						  instances: inst of "o=<suffix>",
 *									 inst of "ou=<ou>,o=<suffix>",
 *										...
 * if isexact != 0: returns an instance that associates with the given suffix
 *					e.g., suffix: "o=<suffix>" is given, these are returned:
 *						  suffixes: "o=<suffix>"
 *						  instances: inst of "o=<suffix>"
 * Note: if suffixes 
 */
int
slapi_lookup_instance_name_by_suffix(char *suffix,
							char ***suffixes, char ***instances, int isexact)
{
	Slapi_Backend *be = NULL;
	struct suffixlist *list;
	char *cookie = NULL;
	const char *thisdn;
	int thisdnlen;
	int suffixlen;
	int count;
	int i;
	int rval = -1;

	if (instances == NULL)
		return rval;

	PR_ASSERT(suffix);

	rval = 0;
	suffixlen = strlen(suffix);
	cookie = NULL;
	be = slapi_get_first_backend (&cookie);
	while (be) {
		if (NULL == be->be_suffixlist) {
			be = (backend *)slapi_get_next_backend (cookie);
			continue;
		}
		count = slapi_counter_get_value(be->be_suffixcounter);
		list = be->be_suffixlist;
		for (i = 0; list && i < count; i++) {
			thisdn = slapi_sdn_get_ndn(list->be_suffix);
			thisdnlen = slapi_sdn_get_ndn_len(list->be_suffix);
			if (isexact?suffixlen!=thisdnlen:suffixlen>thisdnlen){
				list = list->next;
				continue;
			}
			if (isexact?(!slapi_UTF8CASECMP(suffix, (char *)thisdn)):
				(!slapi_UTF8CASECMP(suffix,	(char *)thisdn+thisdnlen-suffixlen)))
			{
				charray_add(instances, slapi_ch_strdup(be->be_name));
				if (suffixes)
					charray_add(suffixes, slapi_ch_strdup(thisdn));
			}
			list = list->next;
		}
		be = (backend *)slapi_get_next_backend (cookie);
	}
	slapi_ch_free((void **)&cookie);
	
	return rval;
}
Esempio n. 2
0
struct node_fanout *
ipa_topo_connection_fanout_new (char *from, char *to)
{
   struct node_fanout *new_fanout = (struct node_fanout *)
                                    slapi_ch_malloc(sizeof(struct node_fanout));
   struct node_list *targets = (struct node_list *)
                               slapi_ch_malloc(sizeof(struct node_list));
   targets->next = NULL;
   targets->node = slapi_ch_strdup(to);
   new_fanout->next = NULL;
   new_fanout->node = slapi_ch_strdup(from);
   new_fanout->targets = targets;
   new_fanout->visited = 0;
   return new_fanout;
}
Esempio n. 3
0
/*
   Checks whether an entry has a particular attribute type, and optionally
   returns the value.  Only for use with single-valued attributes - it returns
   the first value it finds.
*/
int
has_attr( Slapi_Entry* target_entry, char* attr_name, char** val ) {
    Slapi_ValueSet *values = NULL;
    Slapi_Value* sval;
    char *actual_type_name = NULL;
    int type_name_disposition = 0, attr_free_flags = 0, rc = 0;

    /* Use vattr interface to support virtual attributes, e.g.
       acctPolicySubentry has a good chance of being supplied by CoS */
    if ( slapi_vattr_values_get( target_entry, attr_name, &values, &type_name_disposition, &actual_type_name, 0, &attr_free_flags) == 0) {
        if( slapi_valueset_first_value( values, &sval ) == -1 ) {
            rc = 0;
        } else {
            rc = 1;
            if( val ) {
                /* Caller wants a copy of the found attribute's value */
                *val = slapi_ch_strdup( slapi_value_get_string( sval ) );
            }
        }
    } else {
        rc = 0;
    }

    slapi_vattr_values_free(&values, &actual_type_name, attr_free_flags);
    return( rc );
}
Esempio n. 4
0
int slapi_over_config( BackendDB *be, ConfigReply *cr )
{
	if ( slapi_over_initialized == 0 ) {
		int rc;

		/* do global initializaiton */
		ldap_pvt_thread_mutex_init( &slapi_hn_mutex );
		ldap_pvt_thread_mutex_init( &slapi_time_mutex );
		ldap_pvt_thread_mutex_init( &slapi_printmessage_mutex );

		if ( slapi_log_file == NULL )
			slapi_log_file = slapi_ch_strdup( LDAP_RUNDIR LDAP_DIRSEP "errors" );

		rc = slapi_int_init_object_extensions();
		if ( rc != 0 )
			return rc;

		rc = slapi_over_init();
		if ( rc != 0 )
			return rc;

		slapi_over_initialized = 1;
	}

	return overlay_config( be, SLAPI_OVERLAY_NAME, -1, NULL, cr );
}
Esempio n. 5
0
int
GetDomainUsername(
	char *pszNTuserdomainid,
	char *pszNTDomain,
	char *pszNTUsername 
)
{
	char	*pszAttr, *pDomain, *pUsername;

	if( !pszNTuserdomainid )
		return( 1 );

	// Split the specially constructed attribute.
	pszAttr = slapi_ch_strdup( pszNTuserdomainid );

	pDomain = pszAttr;

	pUsername = strchr( pszAttr, ':' );
	if( pUsername == NULL )
		return( 1 );

	// Set the end of the NT Domain name, 
	// and the start of the NT username.
	*pUsername = (char)NULL;
	pUsername++;

	strcpy( pszNTDomain, pDomain);
	strcpy( pszNTUsername, pUsername);

	slapi_ch_free( (void**)&pszAttr );

	return( 0 );
}
Esempio n. 6
0
File: urp.c Progetto: ohamada/389ds
static char *
get_rdn_plus_uniqueid(char *sessionid, const char *olddn, const char *uniqueid)
{
	char *newrdn;
	/* Check if the RDN already contains the Unique ID */
	Slapi_DN *sdn= slapi_sdn_new_dn_byval(olddn);
	Slapi_RDN *rdn= slapi_rdn_new();
	slapi_sdn_get_rdn(sdn,rdn);
	PR_ASSERT(uniqueid!=NULL);
	if(slapi_rdn_contains(rdn,SLAPI_ATTR_UNIQUEID,uniqueid,strlen(uniqueid)))
	{
		/* The Unique ID is already in the RDN.
		 * This is a highly improbable collision.
		 * It suggests that a duplicate UUID was generated.
		 * This will cause replication divergence and will
		 * require admin intercession
		 */
		slapi_log_error(SLAPI_LOG_FATAL, sessionid,
				"Annotated DN %s has naming conflict\n", olddn );
		newrdn= NULL;
	}
	else
	{
		slapi_rdn_add(rdn,SLAPI_ATTR_UNIQUEID,uniqueid);
		newrdn= slapi_ch_strdup(slapi_rdn_get_rdn(rdn));
	}
	slapi_sdn_free(&sdn);
	slapi_rdn_free(&rdn);
	return newrdn;
}
Esempio n. 7
0
static int
or_indexer_create (Slapi_PBlock* pb)
{
	auto int rc = LDAP_UNAVAILABLE_CRITICAL_EXTENSION; /* failed to initialize */
	auto char* mrOID = NULL;
	auto void* mrOBJECT = NULL;
	if (slapi_pblock_get (pb, SLAPI_PLUGIN_MR_OID, &mrOID) || mrOID == NULL) {
		slapi_log_err(SLAPI_LOG_FILTER, COLLATE_PLUGIN_SUBSYSTEM,
			"or_indexer_create - No OID parameter\n");
	} else {
		auto indexer_t* ix = indexer_create (mrOID);
		auto char* mrTYPE = NULL;
		slapi_pblock_get (pb, SLAPI_PLUGIN_MR_TYPE, &mrTYPE);
		slapi_log_err(SLAPI_LOG_FILTER, "or_indexer_create", "(oid %s; type %s)\n",
			   mrOID, mrTYPE ? mrTYPE : "<NULL>");
		if (ix != NULL) {
			if (ix->ix_index != NULL &&
			!slapi_pblock_set (pb, SLAPI_PLUGIN_OBJECT, ix) &&
			!slapi_pblock_set (pb, SLAPI_PLUGIN_MR_OID, ix->ix_oid) &&
			!slapi_pblock_set (pb, SLAPI_PLUGIN_MR_INDEX_FN, (void*)op_index_entry) &&
			!slapi_pblock_set (pb, SLAPI_PLUGIN_DESTROY_FN, (void*)op_indexer_destroy)) {
				mrOBJECT = ix;
				rc = 0; /* success */
			} else {
				indexer_free (ix);
			}
		} else { /* mrOID does not identify an ordering rule. */
			/* Is it an ordering rule OID with the substring suffix? */
			auto size_t oidlen = strlen (mrOID);
			if (oidlen > 2 && mrOID[oidlen-2] == '.' &&
			atoi (mrOID + oidlen - 1) == SLAPI_OP_SUBSTRING) {
				auto char* or_oid = slapi_ch_strdup (mrOID);
				or_oid [oidlen-2] = '\0';
				ix = indexer_create (or_oid);
				if (ix != NULL) {
					auto ss_indexer_t* ss = (ss_indexer_t*) slapi_ch_malloc (sizeof (ss_indexer_t));
					ss->ss_indexer = ix;
					oidlen = strlen (ix->ix_oid);
					ss->ss_oid = slapi_ch_malloc (oidlen + 3);
					memcpy (ss->ss_oid, ix->ix_oid, oidlen);
					sprintf (ss->ss_oid + oidlen, ".%1i", SLAPI_OP_SUBSTRING);
					if (ix->ix_index != NULL &&
					!slapi_pblock_set (pb, SLAPI_PLUGIN_OBJECT, ss) &&
					!slapi_pblock_set (pb, SLAPI_PLUGIN_MR_OID, ss->ss_oid) &&
					!slapi_pblock_set (pb, SLAPI_PLUGIN_MR_INDEX_FN, (void*)ss_index_entry) &&
					!slapi_pblock_set (pb, SLAPI_PLUGIN_DESTROY_FN, (void*)ss_indexer_destroy)) {
						mrOBJECT = ss;
						rc = 0; /* success */
					} else {
						ss_indexer_free (ss);
					}
				}
				slapi_ch_free((void**)&or_oid);
			}
		}
	}
	slapi_log_err(SLAPI_LOG_FILTER, COLLATE_PLUGIN_SUBSYSTEM,
		"or_indexer_create - (%p) %i\n", mrOBJECT, rc);
	return rc;
}
Esempio n. 8
0
struct node_fanout *
ipa_topo_connection_fanout_extend (struct node_fanout *fanout_in, char *from, char *to)
{
    struct node_fanout *cursor;
    if (fanout_in == NULL) {
        /* init fanout */
        return ipa_topo_connection_fanout_new(from,to);
    }
    /* extend existing fanout struct */
    cursor = fanout_in;
    while (cursor) {
        if (strcasecmp(cursor->node, from) == 0) break;
        cursor = cursor->next;
    }
    if (cursor) {
        struct node_list *target = (struct node_list *)
                                   slapi_ch_malloc(sizeof(struct node_list));
        target->next = cursor->targets;
        target->node = slapi_ch_strdup(to);
        cursor->targets = target;
        return fanout_in;
    } else {
        cursor = ipa_topo_connection_fanout_new(from,to);
        cursor->next = fanout_in;
        return cursor;
    }
}
Esempio n. 9
0
/*
 * Invoked when the task instance is added by the client (step 5 of the comment)
 * Get the necessary attributes from the task entry, and spawns a thread to do
 * the task.
 */
static int
task_sampletask_add(Slapi_PBlock *pb, Slapi_Entry *e,
                    Slapi_Entry *eAfter, int *returncode, char *returntext,
                    void *arg)
{
    PRThread *thread = NULL;
    const char *cn;
    int rv = SLAPI_DSE_CALLBACK_OK;
    Slapi_PBlock *mypb = NULL;
    Slapi_Task *task = NULL;
    const char *myarg;

    *returncode = LDAP_SUCCESS;
    if ((cn = fetch_attr(e, "cn", NULL)) == NULL) {
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
        rv = SLAPI_DSE_CALLBACK_ERROR;
        goto out;
    }

    /* get arg(s) */
    if ((myarg = fetch_attr(e, "myarg", NULL)) == NULL) {
        *returncode = LDAP_OBJECT_CLASS_VIOLATION;
        rv = SLAPI_DSE_CALLBACK_ERROR;
        goto out;
    }

    /* allocate new task now */
    task = slapi_new_task(slapi_entry_get_ndn(e));
    if (task == NULL) {
        slapi_log_err(SLAPI_LOG_ERR, "sampletask", "unable to allocate new task!\n");
        *returncode = LDAP_OPERATIONS_ERROR;
        rv = SLAPI_DSE_CALLBACK_ERROR;
        goto out;
    }

    /* set a destructor that will clean up myarg for us when the task is complete */
    slapi_task_set_destructor_fn(task, task_sampletask_destructor);

    /* Stash our argument in the task for use by the task thread */
    slapi_task_set_data(task, slapi_ch_strdup(myarg));

    /* start the sample task as a separate thread */
    thread = PR_CreateThread(PR_USER_THREAD, task_sampletask_thread,
                             (void *)task, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
                             PR_UNJOINABLE_THREAD, SLAPD_DEFAULT_THREAD_STACKSIZE);
    if (thread == NULL) {
        slapi_log_err(SLAPI_LOG_ERR, "sampletask",
                  "unable to create sample task thread!\n");
        *returncode = LDAP_OPERATIONS_ERROR;
        rv = SLAPI_DSE_CALLBACK_ERROR;
        slapi_task_finish(task, *returncode);
    } else {
        /* thread successful */
        rv = SLAPI_DSE_CALLBACK_OK;
    }

out:
    return rv;
}
Esempio n. 10
0
int
slapi_register_supported_feature( char *featureoid )
{
    slapi_rwlock_wrlock(supported_features_lock);
    charray_add( &supported_features, slapi_ch_strdup( featureoid ));
    slapi_rwlock_unlock(supported_features_lock);
    return LDAP_SUCCESS;
}
Esempio n. 11
0
static int
ldbm_instance_config_instance_dir_set(void *arg, void *value, char *errorbuf, int phase, int apply)
{
    ldbm_instance *inst = (ldbm_instance *)arg;

    if (!apply) {
        return LDAP_SUCCESS;
    }

    if ((value == NULL) || (strlen(value) == 0))
    {
        inst->inst_dir_name = NULL;
        inst->inst_parent_dir_name = NULL;
    }
    else
    {
        char *dir = (char *)value;
        if (is_fullpath(dir))
        {
            char sep = get_sep(dir);
            char *p = strrchr(dir, sep);
            if (NULL == p)    /* should not happens, tho */
            {
                inst->inst_parent_dir_name = NULL;
                inst->inst_dir_name = rel2abspath(dir); /* normalize dir;
                                                           strdup'ed in 
                                                           rel2abspath */
            }
            else
            {
                *p = '\0';
                inst->inst_parent_dir_name = rel2abspath(dir); /* normalize dir;
                                                                  strdup'ed in
                                                                  rel2abspath */
                inst->inst_dir_name = slapi_ch_strdup(p+1);
                *p = sep;
            }
        }
        else
        {
            inst->inst_parent_dir_name = NULL;
            inst->inst_dir_name = slapi_ch_strdup(dir);
        }
    }
    return LDAP_SUCCESS;
}
Esempio n. 12
0
/*
  The type and val pointers are assumed to have sufficient lifetime -
  we don't have to copy them - they are usually just pointers into
  the SLAPI_PLUGIN_MR_TYPE and SLAPI_PLUGIN_MR_VALUE fields of the
  operation pblock, whose lifetime should encompass the creation
  and destruction of the bitwise_match_cb object.
*/
static struct bitwise_match_cb *
new_bitwise_match_cb(char *type, struct berval *val)
{
    struct bitwise_match_cb *bmc = (struct bitwise_match_cb *)slapi_ch_calloc(1, sizeof(struct bitwise_match_cb));
    bmc->type = slapi_ch_strdup(type);
    bmc->val = val;

    return bmc;
}
Esempio n. 13
0
/* Function which wraps a filter with (AND !(objectclass=ldapsubentry)) */
void subentry_create_filter(Slapi_Filter** filter)
{
	Slapi_Filter *sub_filter = NULL;
	Slapi_Filter *new_filter = NULL;
    char *buf = slapi_ch_strdup("(!(objectclass=ldapsubentry))");
    sub_filter = slapi_str2filter( buf );
    new_filter = slapi_filter_join( LDAP_FILTER_AND, *filter, sub_filter );
	*filter = new_filter;
	slapi_ch_free((void **)&buf);
}
Esempio n. 14
0
static char *
sasl_map_str_concat(char *s1, char *s2)
{
	if (NULL == s2) {
		return (slapi_ch_strdup(s1));
	} else {
		char *newstr = slapi_ch_smprintf("%s@%s",s1,s2);
		return newstr;
	}
}
Esempio n. 15
0
int snmp_collator_start()
{

  int err;
  char *statspath = config_get_rundir();
  char *instdir = config_get_configdir();
  char *instname = NULL;

  /*
   * Get directory for our stats file
   */
  if (NULL == statspath) {
     statspath = slapi_ch_strdup("/tmp");
  }

  instname = PL_strrstr(instdir, "slapd-");
  if (!instname) {
      instname = PL_strrstr(instdir, "/");
      if (instname) {
          instname++;
      }
  }
  PR_snprintf(szStatsFile, sizeof(szStatsFile), "%s/%s%s",
              statspath, instname, AGT_STATS_EXTENSION);
  PR_snprintf(stats_sem_name, sizeof(stats_sem_name), "/%s%s",
              instname, AGT_STATS_EXTENSION);
  tmpstatsfile = szStatsFile;
  slapi_ch_free_string(&statspath);
  slapi_ch_free_string(&instdir);

  /* open the memory map */
  if ((err = agt_mopen_stats(tmpstatsfile, O_RDWR,  &hdl) != 0))
  {
    if (err != EEXIST)      /* Ignore if file already exists */
    {
      slapi_log_error(SLAPI_LOG_FATAL, "snmp collator", "Failed to open stats file (%s) "
                      "(error %d): %s.\n", szStatsFile, err, slapd_system_strerror(err));
      exit(1);
    }
  }

  /* Create semaphore for stats file access */
  snmp_collator_create_semaphore();

  /* point stats struct at mmap data */
  stats = (struct agt_stats_t *) mmap_tbl [hdl].fp;

  /* initialize stats data */
  snmp_collator_init();

  /* Arrange to be called back periodically to update the mmap'd stats file. */
  snmp_eq_ctx = slapi_eq_repeat(snmp_collator_update, NULL, (time_t)0,
                                SLAPD_SNMP_UPDATE_INTERVAL);
  return 0;
}
Esempio n. 16
0
/*
 * This is the conversation function passed into pam_start().  This is what sets the password
 * that PAM uses to authenticate.  This function is sort of stupid - it assumes all echo off
 * or binary prompts are for the password, and other prompts are for the username.  Time will
 * tell if this is actually the case.
 */
static int
pam_conv_func(int num_msg, const struct pam_message **msg, struct pam_response **resp, void *mydata)
{
	int ii;
	struct berval *creds;
	struct my_pam_conv_str *my_data = (struct my_pam_conv_str *)mydata;
    struct pam_response *reply;
	int ret = PAM_SUCCESS;

    if (num_msg <= 0) {
		return PAM_CONV_ERR;
	}

	/* empty reply structure */
    reply = (struct pam_response *)slapi_ch_calloc(num_msg,
										  sizeof(struct pam_response));
	slapi_pblock_get( my_data->pb, SLAPI_BIND_CREDENTIALS, &creds ); /* the password */
	for (ii = 0; ii < num_msg; ++ii) {
		slapi_log_error(SLAPI_LOG_PLUGIN, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
						"pam msg [%d] = %d %s\n", ii, msg[ii]->msg_style,
						msg[ii]->msg);
		/* hard to tell what prompt is for . . . */
		/* assume prompts for password are either BINARY or ECHO_OFF */
		if (msg[ii]->msg_style == PAM_PROMPT_ECHO_OFF) {
			reply[ii].resp = strdupbv(creds);
#ifdef LINUX
		} else if (msg[ii]->msg_style == PAM_BINARY_PROMPT) {
			reply[ii].resp = strdupbv(creds);
#endif
		} else if (msg[ii]->msg_style == PAM_PROMPT_ECHO_ON) { /* assume username */
			reply[ii].resp = slapi_ch_strdup(my_data->pam_identity);
		} else if (msg[ii]->msg_style == PAM_ERROR_MSG) {
			slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
							"pam msg [%d] error [%s]\n", ii, msg[ii]->msg);
		} else if (msg[ii]->msg_style == PAM_TEXT_INFO) {
			slapi_log_error(SLAPI_LOG_PLUGIN, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
							"pam msg [%d] text info [%s]\n", ii, msg[ii]->msg);
		} else {
			slapi_log_error(SLAPI_LOG_FATAL, PAM_PASSTHRU_PLUGIN_SUBSYSTEM,
							"Error: unknown pam message type (%d: %s)\n",
							msg[ii]->msg_style, msg[ii]->msg);
			ret = PAM_CONV_ERR;
		}
	}

	if (ret == PAM_CONV_ERR) {
		free_pam_response(num_msg, reply);
		reply = NULL;
	}

	*resp = reply;

	return ret;
}
Esempio n. 17
0
void
db_put_dn(char *data_dn)
{
    int ret;
    DBT key = {0};
    DBT data = {0};

	if(db_lock == NULL){
		db_lock = PR_NewLock();
	}
	PR_Lock(db_lock);
    create_db();
    
    if ((ret = DB_OPEN(dbp, NULL, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
        dbp->err(dbp, ret, "%s", DATABASE);
    } 
    memset(&key, 0, sizeof(key));
    memset(&data, 0, sizeof(data));
    

    key.data = (char *)malloc(key_buffer_size);
    /* make_key will set up the key and the data */ 
    make_key(&key);

    data.data = slapi_ch_strdup(data_dn);
    data.size = strlen(data_dn);


    switch (ret =
		dbp->put(dbp, NULL, &key, &data, DB_NOOVERWRITE)) {
	case 0: 
	   	slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: %s: key stored.\n", (char *)key.data);
	break;
	case DB_KEYEXIST:
		slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: %s: key previously stored.\n",
			(char *)key.data);
	break;
	default:
	   	dbp->err(dbp, ret, "DB->put");
	goto err;
    }

    err:
    if(ret){
		slapi_log_error(SLAPI_LOG_PLUGIN, DB_PLUGIN_NAME, "db: Error detected in db_put \n");
    }
	free(key.data);
	if (dbp){
		dbp->close(dbp,0);
		dbp=NULL;
	}
	PR_Unlock(db_lock);

}
Esempio n. 18
0
static struct factory_type*
new_factory_type(const char *name, size_t offset)
{
    struct factory_type* ft= (struct factory_type*)slapi_ch_calloc(1, sizeof(struct factory_type));
	ft->name= slapi_ch_strdup(name);
    ft->extension_lock = PR_NewLock();
	ft->extension_count= 0;
	ft->extension_offset= offset;
	ft->existence_count= 0;
	return ft;
}
Esempio n. 19
0
static void *
ldbm_instance_config_instance_dir_get(void *arg)
{
    ldbm_instance *inst = (ldbm_instance *)arg;

    if (inst->inst_dir_name == NULL)
        return slapi_ch_strdup("");
    else if (inst->inst_parent_dir_name)
    {
        int len = strlen(inst->inst_parent_dir_name) +
                  strlen(inst->inst_dir_name) + 2;
        char *full_inst_dir = (char *)slapi_ch_malloc(len);
        PR_snprintf(full_inst_dir, len, "%s%c%s",
            inst->inst_parent_dir_name, get_sep(inst->inst_parent_dir_name),
            inst->inst_dir_name);
        return full_inst_dir;
    }
    else 
        return slapi_ch_strdup(inst->inst_dir_name);
}
Esempio n. 20
0
LDAPMod *
ldapmod_new_longlong(int op, const char *attr, long long value)
{
    LDAPMod *mod;

    mod = (LDAPMod*) slapi_ch_malloc(sizeof(LDAPMod));
    mod->mod_op = op | LDAP_MOD_BVALUES;
    mod->mod_type = slapi_ch_strdup(attr);
    mod->mod_bvalues = bervals_new_longlong(value);

    return mod;
}
Esempio n. 21
0
void retrocl_create_cle (void)
{
    Slapi_PBlock *pb = NULL;
    Slapi_Entry *e;
    int rc;
    struct berval *vals[2];
    struct berval val;

    vals[0] = &val;
    vals[1] = NULL;

    e = slapi_entry_alloc();
    slapi_entry_set_dn(e,slapi_ch_strdup(RETROCL_CHANGELOG_DN));
    
    /* Set the objectclass attribute */
    val.bv_val = "top";
    val.bv_len = strlen(val.bv_val);
    slapi_entry_add_values( e, "objectclass", vals );

    
    /* Set the objectclass attribute */
    val.bv_val = "nsContainer";
    val.bv_len = strlen(val.bv_val);
    slapi_entry_add_values( e, "objectclass", vals );
    

    /* Set the objectclass attribute */
    val.bv_val = "changelog";
    val.bv_len = strlen(val.bv_val);
    slapi_entry_add_values( e, "cn", vals );  
    
    val.bv_val = RETROCL_ACL;
    val.bv_len = strlen(val.bv_val);
    slapi_entry_add_values( e, "aci", vals );  

    pb = slapi_pblock_new ();
    slapi_add_entry_internal_set_pb( pb, e, NULL /* controls */, 
				     g_plg_identity[PLUGIN_RETROCL], 
				     0 /* actions */ );
    slapi_add_internal_pb (pb);
    slapi_pblock_get( pb, SLAPI_PLUGIN_INTOP_RESULT, &rc );
    slapi_pblock_destroy(pb);
    
    if (rc == 0) {
        slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
			 "created cn=changelog\n");
    } else if (rc == LDAP_ALREADY_EXISTS) {
        slapi_log_error (SLAPI_LOG_PLUGIN, RETROCL_PLUGIN_NAME,
			 "cn=changelog already existed\n");
    } else {
        slapi_log_error( SLAPI_LOG_FATAL, RETROCL_PLUGIN_NAME, "cn=changelog could not be created (%d)\n", rc);
    }
}
Esempio n. 22
0
/*
 * Read configuration and create a configuration data structure.
 * This is called after the server has configured itself so we can check
 * schema and whatnot.
 * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
 */
int
ipa_winsync_config(Slapi_Entry *config_e)
{
    int returncode = LDAP_SUCCESS;
    char returntext[SLAPI_DSE_RETURNTEXT_SIZE];

    if ( inited ) {
        LOG_FATAL("Error: IPA WinSync plug-in already configured.  "
                  "Please remove the plugin config entry [%s]\n",
                  slapi_entry_get_dn_const(config_e));
        return( LDAP_PARAM_ERROR );
    }

    /* initialize fields */
    if ((theConfig.lock = slapi_new_mutex()) == NULL) {
        return( LDAP_LOCAL_ERROR );
    }

    /* init defaults */
    theConfig.config_e = slapi_entry_alloc();
    slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
    theConfig.flatten = PR_TRUE;

    if (SLAPI_DSE_CALLBACK_OK == ipa_winsync_validate_config(NULL, NULL, config_e,
                                                             &returncode, returntext, NULL)) {
        ipa_winsync_apply_config(NULL, NULL, config_e,
                                 &returncode, returntext, NULL);
    }

    /* config DSE must be initialized before we get here */
    if (returncode == LDAP_SUCCESS) {
        const char *config_dn = slapi_entry_get_dn_const(config_e);
        slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_validate_config,NULL);
        slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_apply_config,NULL);
        slapi_config_register_callback(SLAPI_OPERATION_MODRDN, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, dont_allow_that, NULL);
        slapi_config_register_callback(SLAPI_OPERATION_DELETE, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, dont_allow_that, NULL);
        slapi_config_register_callback(SLAPI_OPERATION_SEARCH, DSE_FLAG_PREOP, config_dn, LDAP_SCOPE_BASE,
                                       IPA_WINSYNC_CONFIG_FILTER, ipa_winsync_search,NULL);
    }

    inited = 1;

    if (returncode != LDAP_SUCCESS) {
        LOG_FATAL("Error %d: %s\n", returncode, returntext);
    }

    return returncode;
}
Esempio n. 23
0
static void
plugin_mr_bind (char* oid, struct slapdplugin* plugin)
{
	oid_item_t* i = (oid_item_t*) slapi_ch_malloc (sizeof (oid_item_t));
    slapi_log_err(SLAPI_LOG_FILTER, "plugin_mr_bind", "=> (%s)\n", oid);
	init_global_mr_lock();
	i->oi_oid = slapi_ch_strdup (oid);
	i->oi_plugin = plugin;
	PR_Lock (global_mr_oids_lock);
	i->oi_next = global_mr_oids;
	global_mr_oids = i;
	PR_Unlock (global_mr_oids_lock);        
	slapi_log_err(SLAPI_LOG_FILTER, "plugin_mr_bind", "<=\n");
}
Esempio n. 24
0
static char *
init_my_str_buf(MyStrBuf *buf, const char *s)
{
	PR_ASSERT(buf);
	if (s && (strlen(s) < sizeof(buf->fixbuf))) {
		strcpy(buf->fixbuf, s);
		buf->str = buf->fixbuf;
	} else {
		buf->str = slapi_ch_strdup(s);
		buf->fixbuf[0] = 0;
	}

	return buf->str;
}
Esempio n. 25
0
/*
 * Create an LDAPv3 "Entry Change Notification" control.  They look like this:
 *
 *	EntryChangeNotification ::= SEQUENCE {
 *	    changeType		ENUMERATED {
 *		add	(1),	-- LDAP_CHANGETYPE_ADD
 *		delete	(2),    -- LDAP_CHANGETYPE_DELETE
 *		modify	(4),    -- LDAP_CHANGETYPE_MODIFY
 *		moddn	(8),    -- LDAP_CHANGETYPE_MODDN
 *	    },
 *	    previousDN	 LDAPDN OPTIONAL,   -- included for MODDN ops. only
 *	    changeNumber INTEGER OPTIONAL,  -- included if supported by DSA
 *	}
 *
 * This function returns an LDAP error code (LDAP_SUCCESS if all goes well).
 * The value returned in *ctrlp should be free'd use ldap_control_free().
 * If chgnum is 0 we omit it from the control.
 */
static int
create_entrychange_control( ber_int_t chgtype, ber_int_t chgnum, const char *dn,
	LDAPControl **ctrlp )
{
    int			rc;
    BerElement		*ber;
    struct berval	*bvp;
	const char *prevdn= dn;

    if ( prevdn == NULL ) {
	prevdn = "";
    }

    if ( ctrlp == NULL || ( ber = der_alloc()) == NULL ) {
	return( LDAP_OPERATIONS_ERROR );
    }

    *ctrlp = NULL;

    if (( rc = ber_printf( ber, "{e", chgtype )) != -1 ) {
	if ( chgtype == LDAP_CHANGETYPE_MODDN ) {
	    rc = ber_printf( ber, "s", prevdn );
	}
	if ( rc != -1 && chgnum != 0 ) {
	    rc = ber_printf( ber, "i", chgnum );
	}
	if ( rc != -1 ) {
	    rc = ber_printf( ber, "}" );
	}
    }

    if ( rc != -1 ) {
	rc = ber_flatten( ber, &bvp );
    }
    ber_free( ber, 1 );

    if ( rc == -1 ) {
	return( LDAP_OPERATIONS_ERROR );
    }

    *ctrlp = (LDAPControl *)slapi_ch_malloc( sizeof( LDAPControl ));
    (*ctrlp)->ldctl_iscritical = 0;
    (*ctrlp)->ldctl_oid = slapi_ch_strdup( LDAP_CONTROL_ENTRYCHANGE );
    (*ctrlp)->ldctl_value = *bvp;	/* struct copy */

	bvp->bv_val = NULL;
	ber_bvfree( bvp );

    return( LDAP_SUCCESS );
}
Esempio n. 26
0
static struct factory_extension*
new_factory_extension(
    const char *pluginname,
    slapi_extension_constructor_fnptr constructor, 
    slapi_extension_destructor_fnptr destructor)
{
	struct factory_extension* fe = (struct factory_extension*)slapi_ch_calloc(1, sizeof(struct factory_extension));

	fe->pluginname= slapi_ch_strdup(pluginname);
	fe->constructor= constructor;
	fe->destructor= destructor;

	return fe;
}
Esempio n. 27
0
File: value.c Progetto: Firstyear/ds
int
slapi_value_set_int(Slapi_Value *value, int intVal)
{
    int rc= -1;
    if(NULL != value)
    {
        char valueBuf[80];
        ber_bvdone(&value->bv);
        sprintf(valueBuf,"%d",intVal);
        value->bv.bv_val = slapi_ch_strdup(valueBuf);
        value->bv.bv_len = strlen(value->bv.bv_val);
        rc= 0;
    }
    return rc;
}
Esempio n. 28
0
Slapi_DN *slapi_sdn_set_ndn_byval( Slapi_DN *sdn, const char *ndn )
{
	if ( sdn == NULL ) {
		return NULL;
	}

	slapi_sdn_done( sdn );
	if ( ndn != NULL ) {
		sdn->ndn.bv_val = slapi_ch_strdup( ndn );
		sdn->ndn.bv_len = strlen( ndn );
	}
	sdn->flag |= FLAG_NDN;

	return sdn;
}
Esempio n. 29
0
char *
word_dup( char *w )
{
        char        *s, *ret;
        char        save;

        for ( s = w; !iswordbreak( s ); LDAP_UTF8INC( s ))
                ;        /* NULL */
        save = *s;
        *s = '\0';
        ret = slapi_ch_strdup( w );
        *s = save;

        return( ret );
}
Esempio n. 30
0
static struct mr_private *
mr_private_new(const struct slapdplugin *pi, const char *oid, const char *type, const struct berval *value, int ftype, int op)
{
	struct mr_private *mrpriv;

	mrpriv = (struct mr_private *)slapi_ch_calloc(1, sizeof(struct mr_private));
	mrpriv->pi = pi;
	mrpriv->oid = oid; /* should be consistent for lifetime of usage - no copy necessary */
	mrpriv->type = slapi_ch_strdup(type); /* should be consistent for lifetime of usage - copy it since it could be normalized in filter_normalize_ext */
	mrpriv->value = value; /* should be consistent for lifetime of usage - no copy necessary */
	mrpriv->ftype = ftype;
	mrpriv->op = op;
	mrpriv->values[0] = mrpriv->value; /* for filter_index */

	return mrpriv;
}