Ejemplo n.º 1
0
LSQ_HandleT LSQ_CreateSequence(void)
{
  TreePtr tree = NULL;
  ALLOC_CHECK(tree = malloc(sizeof(Tree)));
  ALLOC_CHECK(tree->before_first = malloc(sizeof(Node)));
  ALLOC_CHECK(tree->past_rear = malloc(sizeof(Node)));
  
  tree->size = 0;
  
  tree->before_first->parent = NULL;
  tree->before_first->left = NULL;
  tree->before_first->right = tree->past_rear;
  tree->past_rear->parent = tree->before_first;
  tree->past_rear->left = NULL;
  tree->past_rear->right = NULL;
  
  tree->root = tree->before_first;
  return (LSQ_HandleT)tree;
  
RESCUE:
    if(tree != NULL)
    {
        free(tree->before_first);
        free(tree->past_rear);
        free(tree);
    }

    return LSQ_HandleInvalid;           
}
Ejemplo n.º 2
0
int AddDataStream(char *szFilename, char *szStreamName, DWORD dwStreamSize)
{
    int iRetCode = EXIT_SUCCESS;

    char *szFillData = NULL;
    char *szFullName = NULL;

    HANDLE *hFile = NULL;
    DWORD dwWritten;

    szFullName = ALLOC_CHECK(malloc(strlen(szFilename) + strlen(szStreamName)));
    sprintf(szFullName, "%s:%s", szFilename, szStreamName);

    WHANDLEOK(hFile = CreateFile(szFullName, GENERIC_WRITE, FILE_SHARE_WRITE,
        NULL, CREATE_ALWAYS, 0, NULL));

    printf("Writing %u megabytes to %s\n", dwStreamSize, szFullName);

    dwStreamSize *= 1024 * 1024; // mb to bytes
    szFillData = ALLOC_CHECK(malloc(dwStreamSize));
    memset(szFillData, 'X', dwStreamSize);
    szFillData[dwStreamSize - 1] = '\0';

    WNONZERO(WriteFile(hFile, szFillData, dwStreamSize, &dwWritten, NULL));

cleanup:
    CloseHandle(hFile);
    free(szFullName);
    free(szFillData);
    return iRetCode;
}
Ejemplo n.º 3
0
static int vfs_my_module_create_dir(vfs_handle_struct *handle, const char *dname, const struct smb_filename *smb_fname)
{
	size_t len;
	mode_t mode;
	char *new_dir = NULL;
	char *tmp_str = NULL;
	char *token;
	char *tok_str;
	bool ret = False;
	char *saveptr;
    int i = 0;
	mode = vfs_my_module_directory_mode(handle);

	tmp_str = SMB_STRDUP(dname);
	ALLOC_CHECK(tmp_str, done);
	tok_str = tmp_str;

	len = strlen(dname)+1;
	new_dir = (char *)SMB_MALLOC(len + 1);
	ALLOC_CHECK(new_dir, done);
	*new_dir = '\0';
	if (dname[0] == '/') {
		/* Absolute path. */
		safe_strcat(new_dir,"/",len);
	}

	/* Create directory tree if neccessary */
	for(token = strtok_r(tok_str, "/", &saveptr); token;
	    token = strtok_r(NULL, "/", &saveptr)) {
		safe_strcat(new_dir, token, len);
		if (vfs_my_module_directory_exist(handle, new_dir))
			DEBUG(10, ("CREATE DIR: dir %s already exists\n", new_dir));
		else {
			DEBUG(1, ("CREATE DIR: creating new dir %s\n", new_dir));
			if (SMB_VFS_NEXT_MKDIR(handle, new_dir,mode) != 0) {
				DEBUG(1,("CREATE DIR: failed for %s with error: %s\n", new_dir, strerror(errno)));
				ret = False;
			}

		}
		safe_strcat(new_dir, "/", len);
		mode = vfs_my_module_subdir_mode(handle);
	i++;
	DEBUG(1,("CREATE DIR COUNTER: %d\n", i));
	ret = True;
	}
done:
	SAFE_FREE(tmp_str);
	SAFE_FREE(new_dir);
	return i;
}
Ejemplo n.º 4
0
/**
 * Create directory tree
 * @param conn connection
 * @param dname Directory tree to be created
 * @return Returns True for success
 **/
static BOOL recycle_create_dir(vfs_handle_struct *handle, const char *dname)
{
	size_t len;
	mode_t mode;
	char *new_dir = NULL;
	char *tmp_str = NULL;
	char *token;
	char *tok_str;
	BOOL ret = False;

	mode = recycle_directory_mode(handle);

	tmp_str = SMB_STRDUP(dname);
	ALLOC_CHECK(tmp_str, done);
	tok_str = tmp_str;

	len = strlen(dname)+1;
	new_dir = (char *)SMB_MALLOC(len + 1);
	ALLOC_CHECK(new_dir, done);
	*new_dir = '\0';
	if (dname[0] == '/') {
		/* Absolute path. */
		safe_strcat(new_dir,"/",len);
	}

	/* Create directory tree if neccessary */
	for(token = strtok(tok_str, "/"); token; token = strtok(NULL, "/")) {
		safe_strcat(new_dir, token, len);
		if (recycle_directory_exist(handle, new_dir))
			DEBUG(10, ("recycle: dir %s already exists\n", new_dir));
		else {
			DEBUG(5, ("recycle: creating new dir %s\n", new_dir));
			if (SMB_VFS_NEXT_MKDIR(handle, new_dir, mode) != 0) {
				DEBUG(1,("recycle: mkdir failed for %s with error: %s\n", new_dir, strerror(errno)));
				ret = False;
				goto done;
			}
		}
		safe_strcat(new_dir, "/", len);
		mode = recycle_subdir_mode(handle);
	}

	ret = True;
done:
	SAFE_FREE(tmp_str);
	SAFE_FREE(new_dir);
	return ret;
}
Ejemplo n.º 5
0
/****************************************************************************
 initialise a privilege list
 ****************************************************************************/
NTSTATUS init_privilege(PRIVILEGE_SET **priv_set)
{
	NTSTATUS ret;
	TALLOC_CTX *mem_ctx = talloc_init("privilege set");
	ALLOC_CHECK(mem_ctx, ret, done, "init_privilege");

	*priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET));
	ALLOC_CHECK(*priv_set, ret, done, "init_privilege");

	(*priv_set)->mem_ctx = mem_ctx;

	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 6
0
Archivo: rfc822.c Proyecto: chr15m/ccan
struct bytestring rfc822_header_unfolded_value(struct rfc822_msg *msg,
					       struct rfc822_header *hdr)
{
	struct bytestring raw = rfc822_header_raw_value(msg, hdr);
	struct bytestring next, rest;
	int lines = 0;
	size_t len = 0;

	if (!hdr->unfolded.ptr) {
		rest = raw;
		while (rest.ptr) {
			get_line(rest, &next, &rest);
			lines++;
			len += next.len;
		}

		if (lines <= 1) {
			hdr->unfolded = bytestring(raw.ptr, len);
		} else {
			char *unfold = tal_arr(msg, char, len);
			char *p = unfold;

			ALLOC_CHECK(unfold, bytestring_NULL);

			rest = raw;
			while (rest.ptr) {
				get_line(rest, &next, &rest);
				memcpy(p, next.ptr, next.len);
				p += next.len;
			}

			assert(p == (unfold + len));
			hdr->unfolded = bytestring(unfold, len);
		}
	}
Ejemplo n.º 7
0
/****************************************************************************
 add a privilege to a privilege array
 ****************************************************************************/
NTSTATUS add_privilege(PRIVILEGE_SET *priv_set, LUID_ATTR set)
{
	NTSTATUS ret;
	LUID_ATTR *new_set;

	/* check if the privilege is not already in the list */
	if (NT_STATUS_IS_OK(check_priv_in_privilege(priv_set, set)))
		return NT_STATUS_UNSUCCESSFUL;

	/* we can allocate memory to add the new privilege */

	new_set = (LUID_ATTR *)talloc_realloc(priv_set->mem_ctx, priv_set->set, (priv_set->count + 1) * (sizeof(LUID_ATTR)));
	ALLOC_CHECK(new_set, ret, done, "add_privilege");

	new_set[priv_set->count].luid.high = set.luid.high;
	new_set[priv_set->count].luid.low = set.luid.low;
	new_set[priv_set->count].attr = set.attr;

	priv_set->count++;
	priv_set->set = new_set;

	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 8
0
Archivo: rfc822.c Proyecto: chr15m/ccan
static struct rfc822_header *next_header_parse(struct rfc822_msg *msg)
{
	const char *h, *eh, *ev, *colon;
	struct rfc822_header *hi;

	CHECK(msg, ">next_header_parse");

	if (!msg->remainder)
		return NULL;

	if (msg->body && (msg->remainder >= msg->body))
		return NULL;

	h = msg->remainder;
	eh = next_line(h, msg->end);

	ev = eh;
	if ((ev > h) && (ev[-1] == '\n'))
		ev--;
	if ((ev > h) && (ev[-1] == '\r'))
		ev--;
	if (ev == h) {
		/* Found the end of the headers */

		assert(!msg->body || (msg->body == eh));

		if (eh < msg->end)
			msg->body = eh;
		return NULL;
	}

	while ((eh < msg->end) && rfc822_iswsp(*eh))
		eh = next_line(eh, msg->end);

	if (eh >= msg->end)
		msg->remainder = NULL;
	else
		msg->remainder = eh;


	hi = talz(msg, struct rfc822_header);
	ALLOC_CHECK(hi, NULL);

	hi->all = bytestring(h, eh - h);
	list_add_tail(&msg->headers, &hi->list);

	colon = memchr(h, ':', hi->all.len);
	if (colon) {
		hi->rawname = bytestring(h, colon - h);
		hi->rawvalue = bytestring(colon + 1, eh - colon - 1);
	} else {
		hi->rawname = bytestring_NULL;
		hi->rawvalue = bytestring_NULL;
	}

	CHECK(msg, "<next_header_parse");

	return index_header(msg, hi);
}
Ejemplo n.º 9
0
/****************************************************************************
 remove a privilege from a privilege array
 ****************************************************************************/
NTSTATUS remove_privilege(PRIVILEGE_SET *priv_set, LUID_ATTR set)
{
	NTSTATUS ret;
	LUID_ATTR *new_set;
	LUID_ATTR *old_set;
	int i,j;

	if (!priv_set)
		return NT_STATUS_INVALID_PARAMETER;

	/* check if the privilege is in the list */
	if (!NT_STATUS_IS_OK(check_priv_in_privilege(priv_set, set)))
		return NT_STATUS_UNSUCCESSFUL;

	/* special case if it's the only privilege in the list */
	if (priv_set->count == 1) {
		reset_privilege(priv_set);	
		return NT_STATUS_OK;
	}

	/* 
	 * the privilege is there, create a new list,
	 * and copy the other privileges
	 */

	old_set = priv_set->set;

	new_set = (LUID_ATTR *)talloc(priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR)));
	ALLOC_CHECK(new_set, ret, done, "remove_privilege");

	for (i=0, j=0; i < priv_set->count; i++) {
		if (	(old_set[i].luid.low == set.luid.low) && 
			(old_set[i].luid.high == set.luid.high)	) {
		    	continue;
		}
		
		new_set[j].luid.low = old_set[i].luid.low;
		new_set[j].luid.high = old_set[i].luid.high;
		new_set[j].attr = old_set[i].attr;

		j++;
	}
	
	if (j != priv_set->count - 1) {
		DEBUG(0,("remove_privilege: mismatch ! difference is not -1\n"));
		DEBUGADD(0,("old count:%d, new count:%d\n", priv_set->count, j));
		return NT_STATUS_INTERNAL_ERROR;
	}
		
	/* ok everything is fine */
	
	priv_set->count--;
	priv_set->set = new_set;
	
	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 10
0
LSQ_HandleT LSQ_CreateSequence(void)
{
   _container *c = NULL;
   ALLOC_CHECK(c = malloc(sizeof(_container)));
   c->data = NULL;
   c->size = 0;
   return (LSQ_HandleT)c;
RESCUE:
   return LSQ_HandleInvalid;
}
Ejemplo n.º 11
0
LSQ_IteratorT LSQ_GetFrontElement(LSQ_HandleT handle)
{
    IteratorPtr iter = NULL;
    TreePtr tree = handle;
    if (tree == LSQ_HandleInvalid) return NULL;
    ALLOC_CHECK(iter = malloc(sizeof(Iterator)));
    
    iter->tree = tree;
    iter->node = tree->before_first;
    LSQ_AdvanceOneElement(iter);
    return iter;
RESCUE:
    return NULL;
}
Ejemplo n.º 12
0
LSQ_IteratorT LSQ_GetPastRearElement(LSQ_HandleT handle)
{
    IteratorPtr iter = NULL;
    TreePtr tree = handle;
    if (tree == LSQ_HandleInvalid) return NULL;
    ALLOC_CHECK(iter = malloc(sizeof(Iterator)));
    
    iter->tree = tree;
    iter->node = tree->past_rear;
    return iter;

RESCUE:
    return NULL;
}
C_RESULT video_stage_decoder_open (video_decoder_config_t *cfg)
{
  // Allocate internal datas
  ALLOC_CHECK (cfg->vlibConf, sizeof (vlib_stage_decoding_config_t));
  ALLOC_CHECK (cfg->vlibOut, sizeof (vp_api_io_data_t));
  ALLOC_CHECK (cfg->mp4h264Conf, sizeof (mp4h264_config_t));
  ALLOC_CHECK (cfg->mp4h264Out, sizeof (vp_api_io_data_t));

  // Fill alloc'd structs with data from cfg
  // --> MPEG4 / H264
  cfg->mp4h264Conf->dst_picture.format = cfg->dst_picture->format;
  // --> VLIB
  cfg->vlibConf->width = cfg->dst_picture->width;
  cfg->vlibConf->height = cfg->dst_picture->height;
  cfg->vlibConf->picture = cfg->dst_picture;
  cfg->vlibConf->luma_only = FALSE;
  cfg->vlibConf->block_mode_enable = TRUE;

  switch (cfg->dst_picture->format)
    {
    case PIX_FMT_RGB565:
      cfg->bpp=2;
      break;
    case PIX_FMT_RGB24:
      cfg->bpp=3;
      break;
    default:
      cfg->bpp=0;
      break;
    }
      
       
  vlib_stage_decoding_open (cfg->vlibConf);
  mp4h264_open (cfg->mp4h264Conf);

  return C_OK;
}
Ejemplo n.º 14
0
NTSTATUS init_priv_with_ctx(TALLOC_CTX *mem_ctx, PRIVILEGE_SET **priv_set)
{
	NTSTATUS ret;

	*priv_set = talloc_zero(mem_ctx, sizeof(PRIVILEGE_SET));
	ALLOC_CHECK(*priv_set, ret, done, "init_privilege");

	(*priv_set)->mem_ctx = mem_ctx;
	(*priv_set)->ext_ctx = True;

	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 15
0
LSQ_IteratorT LSQ_GetElementByIndex(LSQ_HandleT handle, LSQ_IntegerIndexT index)
{
    _iterator *iter = NULL;
    _container *c = handle;
    if(c != LSQ_HandleInvalid)
    {
        ALLOC_CHECK(iter = malloc(sizeof(_iterator)));
        iter->container = c;
        if(index < -1) index = -1;
        else
        if(index > LSQ_GetSize(c)) index = LSQ_GetSize(c);
        iter->index = index;
        return (LSQ_IteratorT *)iter;
    }
RESCUE:
    return NULL;
}
Ejemplo n.º 16
0
LSQ_IteratorT LSQ_GetElementByIndex(LSQ_HandleT handle, LSQ_IntegerIndexT index)
{
    IteratorPtr iter = NULL;
    TreePtr tree = handle;
    if (tree == LSQ_HandleInvalid) return NULL;
    ALLOC_CHECK(iter = malloc(sizeof(Iterator)));
    
    iter->tree = tree;
    iter->node = tree->root;
    
    while (LSQ_IsIteratorDereferencable(iter))
    {
        if (iter->node->key == index) return iter;
        if (index > iter->node->key) iter->node = iter->node->right;
        else iter->node = iter->node->left;
    }
    return iter;
RESCUE:
    return NULL;
}
Ejemplo n.º 17
0
/****************************************************************************
 duplicates a privilege array
 the new privilege set must be passed inited
 (use init_privilege or init_priv_with_ctx)
 ****************************************************************************/
NTSTATUS dup_priv_set(PRIVILEGE_SET *new_priv_set, PRIVILEGE_SET *priv_set)
{
	NTSTATUS ret;
	LUID_ATTR *new_set;
	LUID_ATTR *old_set;
	int i;

	if (!new_priv_set || !priv_set)
		return NT_STATUS_INVALID_PARAMETER;

	/* special case if there are no privileges in the list */
	if (priv_set->count == 0) {
		return NT_STATUS_OK;
	}

	/* 
	 * create a new list,
	 * and copy the other privileges
	 */

	old_set = priv_set->set;

	new_set = (LUID_ATTR *)talloc(new_priv_set->mem_ctx, (priv_set->count - 1) * (sizeof(LUID_ATTR)));
	ALLOC_CHECK(new_set, ret, done, "dup_priv_set");

	for (i=0; i < priv_set->count; i++) {
		
		new_set[i].luid.low = old_set[i].luid.low;
		new_set[i].luid.high = old_set[i].luid.high;
		new_set[i].attr = old_set[i].attr;
	}
			
	new_priv_set->count = priv_set->count;
	new_priv_set->control = priv_set->control;
	new_priv_set->set = new_set;
	
	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 18
0
/****************************************************************************
 duplicate alloc luid_attr
 ****************************************************************************/
NTSTATUS dupalloc_luid_attr(TALLOC_CTX *mem_ctx, LUID_ATTR **new_la, LUID_ATTR *old_la)
{
	NTSTATUS ret;

	/* don't crash if the source pointer is NULL (since we don't
	   do priviledges now anyways) */

	if ( !old_la )
		return NT_STATUS_OK;

	*new_la = (LUID_ATTR *)talloc(mem_ctx, sizeof(LUID_ATTR));
	ALLOC_CHECK(new_la, ret, done, "dupalloc_luid_attr");

	(*new_la)->luid.high = old_la->luid.high;
	(*new_la)->luid.low = old_la->luid.low;
	(*new_la)->attr = old_la->attr;
	
	ret = NT_STATUS_OK;

done:
	return ret;
}
Ejemplo n.º 19
0
Archivo: rfc822.c Proyecto: chr15m/ccan
struct rfc822_msg *rfc822_start(const void *ctx, const char *p, size_t len)
{
	struct rfc822_msg *msg;
	int i;

	msg = tal(ctx, struct rfc822_msg);
	ALLOC_CHECK(msg, NULL);

	msg->data = p;
	msg->end = p + len;

	msg->remainder = msg->data;
	msg->body = NULL;

	list_head_init(&msg->headers);

	for (i = 0; i < INDEX_HASH_SIZE; i++)
		list_head_init(&msg->header_index[i]);

	CHECK(msg, "<rfc22_start");

	return msg;
}
Ejemplo n.º 20
0
static ssize_t vfs_my_module_pwrite(vfs_handle_struct *handle, files_struct *fsp,
			    const void *data, size_t n,
			    off_t offset)
{		connection_struct *conn = handle->conn;
	char *path_name = NULL;
       	char *temp_name = NULL;
	char *final_name = NULL;
	const struct smb_filename *smb_fname = fsp->fsp_name;
	struct smb_filename *smb_fname_final = NULL;
	const char *base;
	char *repository,*repositoryTemp = NULL;
	int i = 1;
	SMB_OFF_T maxsize, minsize;
	SMB_OFF_T file_size; /* space_avail;	*/
	bool exist;
	NTSTATUS status;
	ssize_t rc = -1;
    int count = 0;
    const char *share = "/mnt/share";
	repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
					conn->session_info->unix_name,
					conn->connectpath,
					conn->session_info->utok.gid,
					conn->session_info->sanitized_username,
					conn->session_info->info3->base.domain.string,
					sharevolume(handle));
	ALLOC_CHECK(repository, done);

	trim_char(repository, '\0', '/');

	if(!repository || *(repository) == '\0') {
		rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
		goto done;
	}

    file_size = vfs_my_module_get_file_size(handle, smb_fname);
    maxsize = vfs_my_module_maxsize(handle);

    if(maxsize > 0 && file_size > maxsize){
    repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
					conn->session_info->unix_name,
					conn->connectpath,
					conn->session_info->utok.gid,
					conn->session_info->sanitized_username,
					conn->session_info->info3->base.domain.string,
					stripevolume(handle));
	ALLOC_CHECK(repository, done);

	trim_char(repository, '\0', '/');

	if(!repository || *(repository) == '\0') {
		rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
		goto done;
	}
    }

	if (strncmp(smb_fname->base_name, repository,
		    strlen(repository)) == 0) {
		rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
		goto done;
	}

	base = strrchr(smb_fname->base_name, '/');
	if (base == NULL) {
		base = smb_fname->base_name;
		path_name = SMB_STRDUP("/");
		ALLOC_CHECK(path_name, done);
	}
	else {
		path_name = SMB_STRDUP(smb_fname->base_name);
		ALLOC_CHECK(path_name, done);
		path_name[base - smb_fname->base_name] = '\0';
		base++;
	}

	/* original filename with path */
	DEBUG(10, ("file transaction: fname = %s\n", smb_fname_str_dbg(smb_fname)));
	/* original path */
	DEBUG(10, ("file transaction: fpath = %s\n", path_name));
	/* filename without path */
	DEBUG(10, ("file transaction: base = %s\n", base));

    if (vfs_my_module_keep_dir_tree(handle) == True) {
		if (asprintf(&temp_name, "%s/%s", repository, path_name) == -1) {
			ALLOC_CHECK(temp_name, done);
		}
	} else {
		temp_name = SMB_STRDUP(repository);
	}

	ALLOC_CHECK(temp_name, done);
	exist = vfs_my_module_directory_exist(handle, temp_name);
	if (exist) {
		DEBUG(10, ("file transaction: Directory already exists\n"));
	} else {
		DEBUG(10, ("file transaction: Creating directory %s\n", temp_name));
		count = vfs_my_module_create_dir(handle, temp_name, smb_fname);
	}
	if (asprintf(&final_name, "%s/%s", temp_name, base) == -1) {
		ALLOC_CHECK(final_name, done);
	}

	/* Create smb_fname with final base name and orig stream name. */
	status = create_synthetic_smb_fname(talloc_tos(), final_name,
					    smb_fname->stream_name, NULL,
					    &smb_fname_final);
	if (!NT_STATUS_IS_OK(status)) {
		rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
		goto done;
	}

		TALLOC_FREE(smb_fname_final->base_name);
		smb_fname_final->base_name = talloc_strdup(smb_fname_final,
							   final_name);
		if (smb_fname_final->base_name == NULL) {
			rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
			goto done;
		}

	SMB_VFS_NEXT_RENAME(handle, smb_fname, smb_fname_final);
	rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);

	if (rc != 0) {
		rc = SMB_VFS_NEXT_PWRITE(handle, fsp,data,n,offset);
		goto done;
	}

done:
    vfs_my_module_delete_dir(handle,path_name,smb_fname);
    while(count !=0){
    vfs_my_module_delete_dir(handle,path_name,smb_fname);
    SMB_VFS_NEXT_RMDIR(handle, path_name);
    count--;
    }
	SAFE_FREE(path_name);
	SAFE_FREE(temp_name);
	SAFE_FREE(final_name);
	TALLOC_FREE(smb_fname_final);
	TALLOC_FREE(repository);
	return rc;
}
Ejemplo n.º 21
0
static int net_idmap_restore(struct net_context *c, int argc, const char **argv)
{
	TALLOC_CTX *ctx;
	FILE *input;

	if (c->display_usage) {
		d_printf(_("Usage:\n"
			   "net idmap restore [inputfile]\n"
			   "  Restore ID mappings from file\n"
			   "    inputfile\tFile to load ID mappings from. If "
			   "not given, load data from stdin.\n"));
		return 0;
	}

	if (! winbind_ping()) {
		d_fprintf(stderr,
			  _("To use net idmap Winbindd must be running.\n"));
		return -1;
	}

	ctx = talloc_new(NULL);
	ALLOC_CHECK(ctx);

	if (argc == 1) {
		input = fopen(argv[0], "r");
	} else {
		input = stdin;
	}

	while (!feof(input)) {
		char line[128], sid_string[128];
		int len;
		struct wbcDomainSid sid;
		enum id_type type = ID_TYPE_NOT_SPECIFIED;
		unsigned long idval;
		wbcErr wbc_status;

		if (fgets(line, 127, input) == NULL)
			break;

		len = strlen(line);

		if ( (len > 0) && (line[len-1] == '\n') )
			line[len-1] = '\0';

		if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2) {
			type = ID_TYPE_GID;
		} else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2) {
			type = ID_TYPE_UID;
		} else if (sscanf(line, "USER HWM %lu", &idval) == 1) {
			/* set uid hwm */
			wbc_status = wbcSetUidHwm(idval);
			if (!WBC_ERROR_IS_OK(wbc_status)) {
				d_fprintf(stderr,
					  _("Could not set USER HWM: %s\n"),
					  wbcErrorString(wbc_status));
			}
			continue;
		} else if (sscanf(line, "GROUP HWM %lu", &idval) == 1) {
			/* set gid hwm */
			wbc_status = wbcSetGidHwm(idval);
			if (!WBC_ERROR_IS_OK(wbc_status)) {
				d_fprintf(stderr,
					  _("Could not set GROUP HWM: %s\n"),
					  wbcErrorString(wbc_status));
			}
			continue;
		} else {
			d_fprintf(stderr, _("ignoring invalid line [%s]\n"),
				  line);
			continue;
		}

		wbc_status = wbcStringToSid(sid_string, &sid);
		if (!WBC_ERROR_IS_OK(wbc_status)) {
			d_fprintf(stderr, _("ignoring invalid sid [%s]: %s\n"),
				  sid_string, wbcErrorString(wbc_status));
			continue;
		}

		if (type == ID_TYPE_UID) {
			wbc_status = wbcSetUidMapping(idval, &sid);
		} else {
			wbc_status = wbcSetGidMapping(idval, &sid);
		}
		if (!WBC_ERROR_IS_OK(wbc_status)) {
			d_fprintf(stderr,
				  _("Could not set mapping of %s %lu to sid %s: %s\n"),
				 (type == ID_TYPE_GID) ? "GID" : "UID",
				 idval, sid_string,
				 wbcErrorString(wbc_status));
			continue;
		}
	}

	if (input != stdin) {
		fclose(input);
	}

	talloc_free(ctx);
	return 0;
}
Ejemplo n.º 22
0
void *l_calloc(size_t count, size_t size)
{
    void *ptr = calloc(count, size);
    ALLOC_CHECK(ptr);
    return ptr;
}
Ejemplo n.º 23
0
void *l_malloc(size_t size)
{
    void *ptr = malloc(size);
    ALLOC_CHECK(ptr);
    return ptr;
}
Ejemplo n.º 24
0
static int net_idmap_secret(struct net_context *c, int argc, const char **argv)
{
	TALLOC_CTX *ctx;
	const char *secret;
	const char *dn;
	char *domain;
	char *backend;
	char *opt = NULL;
	bool ret;

	if (argc != 2 || c->display_usage) {
		d_printf(_("Usage:\n"
			   "net idmap secret {<DOMAIN>|alloc} <secret>\n"
			   "  Set the secret for the specified domain "
			   "(or alloc module)\n"
			   "    DOMAIN\tDomain to set secret for.\n"
			   "    alloc\tSet secret for the alloc module\n"
			   "    secret\tNew secret to set.\n"));
		return c->display_usage?0:-1;
	}

	secret = argv[1];

	ctx = talloc_new(NULL);
	ALLOC_CHECK(ctx);

	if (strcmp(argv[0], "alloc") == 0) {
		domain = NULL;
		backend = lp_idmap_alloc_backend();
	} else {
		domain = talloc_strdup(ctx, argv[0]);
		ALLOC_CHECK(domain);

		opt = talloc_asprintf(ctx, "idmap config %s", domain);
		ALLOC_CHECK(opt);

		backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
		ALLOC_CHECK(backend);
	}

	if ( ( ! backend) || ( ! strequal(backend, "ldap"))) {
		d_fprintf(stderr,
			  _("The only currently supported backend is LDAP\n"));
		talloc_free(ctx);
		return -1;
	}

	if (domain) {

		dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
		if ( ! dn) {
			d_fprintf(stderr,
				  _("Missing ldap_user_dn option for domain "
				    "%s\n"), domain);
			talloc_free(ctx);
			return -1;
		}

		ret = idmap_store_secret("ldap", false, domain, dn, secret);
	} else {
		dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL);
		if ( ! dn) {
			d_fprintf(stderr,
				  _("Missing ldap_user_dn option for alloc "
				    "backend\n"));
			talloc_free(ctx);
			return -1;
		}

		ret = idmap_store_secret("ldap", true, NULL, dn, secret);
	}

	if ( ! ret) {
		d_fprintf(stderr, _("Failed to store secret\n"));
		talloc_free(ctx);
		return -1;
	}

	d_printf(_("Secret stored\n"));
	return 0;
}
Ejemplo n.º 25
0
/**
 * Check if file should be recycled
 **/
static int recycle_unlink(vfs_handle_struct *handle,
    const struct smb_filename *smb_fname)
{
	connection_struct *conn = handle->conn;
	char *path_name = NULL;
       	char *temp_name = NULL;
	char *final_name = NULL;
	struct smb_filename *smb_fname_final = NULL;
	const char *base;
	char *repository = NULL;
	int i = 1;
	SMB_OFF_T maxsize, minsize;
	SMB_OFF_T file_size; /* space_avail;	*/
	bool exist;
	NTSTATUS status;
	int rc = -1;

	repository = talloc_sub_advanced(NULL, lp_servicename(SNUM(conn)),
					conn->session_info->unix_name,
					conn->connectpath,
					conn->session_info->utok.gid,
					conn->session_info->sanitized_username,
					conn->session_info->info3->base.domain.string,
					recycle_repository(handle));
	ALLOC_CHECK(repository, done);
	/* shouldn't we allow absolute path names here? --metze */
	/* Yes :-). JRA. */
	trim_char(repository, '\0', '/');

	if(!repository || *(repository) == '\0') {
		DEBUG(3, ("recycle: repository path not set, purging %s...\n",
			  smb_fname_str_dbg(smb_fname)));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	/* we don't recycle the recycle bin... */
	if (strncmp(smb_fname->base_name, repository,
		    strlen(repository)) == 0) {
		DEBUG(3, ("recycle: File is within recycling bin, unlinking ...\n"));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	file_size = recycle_get_file_size(handle, smb_fname);
	/* it is wrong to purge filenames only because they are empty imho
	 *   --- simo
	 *
	if(fsize == 0) {
		DEBUG(3, ("recycle: File %s is empty, purging...\n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle,file_name);
		goto done;
	}
	 */

	/* FIXME: this is wrong, we should check the whole size of the recycle bin is
	 * not greater then maxsize, not the size of the single file, also it is better
	 * to remove older files
	 */
	maxsize = recycle_maxsize(handle);
	if(maxsize > 0 && file_size > maxsize) {
		DEBUG(3, ("recycle: File %s exceeds maximum recycle size, "
			  "purging... \n", smb_fname_str_dbg(smb_fname)));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}
	minsize = recycle_minsize(handle);
	if(minsize > 0 && file_size < minsize) {
		DEBUG(3, ("recycle: File %s lowers minimum recycle size, "
			  "purging... \n", smb_fname_str_dbg(smb_fname)));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	/* FIXME: this is wrong: moving files with rename does not change the disk space
	 * allocation
	 *
	space_avail = SMB_VFS_NEXT_DISK_FREE(handle, ".", True, &bsize, &dfree, &dsize) * 1024L;
	DEBUG(5, ("space_avail = %Lu, file_size = %Lu\n", space_avail, file_size));
	if(space_avail < file_size) {
		DEBUG(3, ("recycle: Not enough diskspace, purging file %s\n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, file_name);
		goto done;
	}
	 */

	/* extract filename and path */
	base = strrchr(smb_fname->base_name, '/');
	if (base == NULL) {
		base = smb_fname->base_name;
		path_name = SMB_STRDUP("/");
		ALLOC_CHECK(path_name, done);
	}
	else {
		path_name = SMB_STRDUP(smb_fname->base_name);
		ALLOC_CHECK(path_name, done);
		path_name[base - smb_fname->base_name] = '\0';
		base++;
	}

	/* original filename with path */
	DEBUG(10, ("recycle: fname = %s\n", smb_fname_str_dbg(smb_fname)));
	/* original path */
	DEBUG(10, ("recycle: fpath = %s\n", path_name));
	/* filename without path */
	DEBUG(10, ("recycle: base = %s\n", base));

	if (matchparam(recycle_exclude(handle), base)) {
		DEBUG(3, ("recycle: file %s is excluded \n", base));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	if (matchdirparam(recycle_exclude_dir(handle), path_name)) {
		DEBUG(3, ("recycle: directory %s is excluded \n", path_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	if (recycle_keep_dir_tree(handle) == True) {
		if (asprintf(&temp_name, "%s/%s", repository, path_name) == -1) {
			ALLOC_CHECK(temp_name, done);
		}
	} else {
		temp_name = SMB_STRDUP(repository);
	}
	ALLOC_CHECK(temp_name, done);

	exist = recycle_directory_exist(handle, temp_name);
	if (exist) {
		DEBUG(10, ("recycle: Directory already exists\n"));
	} else {
		DEBUG(10, ("recycle: Creating directory %s\n", temp_name));
		if (recycle_create_dir(handle, temp_name) == False) {
			DEBUG(3, ("recycle: Could not create directory, "
				  "purging %s...\n",
				  smb_fname_str_dbg(smb_fname)));
			rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
			goto done;
		}
	}

	if (asprintf(&final_name, "%s/%s", temp_name, base) == -1) {
		ALLOC_CHECK(final_name, done);
	}

	/* Create smb_fname with final base name and orig stream name. */
	status = create_synthetic_smb_fname(talloc_tos(), final_name,
					    smb_fname->stream_name, NULL,
					    &smb_fname_final);
	if (!NT_STATUS_IS_OK(status)) {
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	/* new filename with path */
	DEBUG(10, ("recycle: recycled file name: %s\n",
		   smb_fname_str_dbg(smb_fname_final)));

	/* check if we should delete file from recycle bin */
	if (recycle_file_exist(handle, smb_fname_final)) {
		if (recycle_versions(handle) == False || matchparam(recycle_noversions(handle), base) == True) {
			DEBUG(3, ("recycle: Removing old file %s from recycle "
				  "bin\n", smb_fname_str_dbg(smb_fname_final)));
			if (SMB_VFS_NEXT_UNLINK(handle,
						smb_fname_final) != 0) {
				DEBUG(1, ("recycle: Error deleting old file: %s\n", strerror(errno)));
			}
		}
	}

	/* rename file we move to recycle bin */
	i = 1;
	while (recycle_file_exist(handle, smb_fname_final)) {
		SAFE_FREE(final_name);
		if (asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base) == -1) {
			ALLOC_CHECK(final_name, done);
		}
		TALLOC_FREE(smb_fname_final->base_name);
		smb_fname_final->base_name = talloc_strdup(smb_fname_final,
							   final_name);
		if (smb_fname_final->base_name == NULL) {
			rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
			goto done;
		}
	}

	DEBUG(10, ("recycle: Moving %s to %s\n", smb_fname_str_dbg(smb_fname),
		smb_fname_str_dbg(smb_fname_final)));
	rc = SMB_VFS_NEXT_RENAME(handle, smb_fname, smb_fname_final);
	if (rc != 0) {
		DEBUG(3, ("recycle: Move error %d (%s), purging file %s "
			  "(%s)\n", errno, strerror(errno),
			  smb_fname_str_dbg(smb_fname),
			  smb_fname_str_dbg(smb_fname_final)));
		rc = SMB_VFS_NEXT_UNLINK(handle, smb_fname);
		goto done;
	}

	/* touch access date of moved file */
	if (recycle_touch(handle) == True || recycle_touch_mtime(handle))
		recycle_do_touch(handle, smb_fname_final,
				 recycle_touch_mtime(handle));

done:
	SAFE_FREE(path_name);
	SAFE_FREE(temp_name);
	SAFE_FREE(final_name);
	TALLOC_FREE(smb_fname_final);
	TALLOC_FREE(repository);
	return rc;
}
Ejemplo n.º 26
0
void npl_ScriptPlugin(MWContext *context, lo_DocState *state, PA_Tag *tag, size_t line_buf_len, char * mimebuf)
{
	char * suffix				= NULL;
    char * fname				= NULL;
	char * embedtagstr			= NULL;
	char * NET_suffix			= NULL;
	PA_Tag * newTag				= NULL;
	NET_StreamClass* viewstream = NULL;
    URL_Struct* urls			= NULL;
	int streamStatus			= 0;
	int id						= 0;

	if (!context || !state || !tag || (line_buf_len <= 0) || !mimebuf){
		XP_Trace("npl_ScriptPlugin:  Invalid input(s).");
		return; /* no need to goto clean_exit, since havn't alloc'd anything */
	}

	urls = NET_CreateURLStruct("internal_url.", NET_DONT_RELOAD);
			ALLOC_CHECK(urls,id,abnormal_exit);

	/* NETLib gives me a pointer here instead of a copy of the string, so I have to make
	   my own, make checks, etc. 
	 */
	NET_suffix = NET_cinfo_find_ext(mimebuf);
	if (!NET_suffix)
		goto abnormal_exit;

	suffix = PR_smprintf("internal_url.%s", NET_suffix);
			ALLOC_CHECK(suffix,id,abnormal_exit);

			XP_FREEIF(urls->address);
	StrAllocCopy(urls->address     , suffix);
			ALLOC_CHECK(urls->address,id,abnormal_exit);

			XP_FREEIF(urls->content_name);
	StrAllocCopy(urls->content_name, suffix);
			ALLOC_CHECK(urls->content_name,id,abnormal_exit);

			XP_FREEIF(urls->content_type);
	StrAllocCopy(urls->content_type, mimebuf);
			ALLOC_CHECK(urls->content_type,id,abnormal_exit);

	urls->must_cache = 1;  	/* ugly flag for mailto and saveas */

	viewstream = NET_StreamBuilder(FO_CACHE_ONLY, urls, context);
			ALLOC_CHECK(viewstream,id,abnormal_exit);

	streamStatus =
		(*viewstream->put_block)(viewstream,(CONST char*)state->line_buf, line_buf_len);
	if (streamStatus <= 0)
		goto abnormal_exit;
	(*viewstream->complete)(viewstream);

	/* Now build internal embed tag pointing to this source:  */
    fname = WH_FileName(urls->cache_file, xpCache);
			ALLOC_CHECK(fname,id,abnormal_exit);
	embedtagstr = PR_smprintf("<EMBED SRC=file:///%s HIDDEN=TRUE>", fname);
			ALLOC_CHECK(embedtagstr,id,abnormal_exit);

	newTag = LO_CreateHiddenEmbedTag(tag,embedtagstr);
			ALLOC_CHECK(newTag,id,abnormal_exit);

	lo_FormatEmbed(context,state,newTag);	 
	goto normal_exit;

abnormal_exit:
	XP_Trace("npl_ScriptPlugin:  Abnormal termination, id = %d",id);
	if (urls) {
		XP_FREEIF(urls->content_type);
		XP_FREEIF(urls->content_name);
		XP_FREEIF(urls->address);
		XP_FREE(  urls);
	}

normal_exit:
	XP_FREEIF(newTag);
	XP_FREEIF(embedtagstr);
	XP_FREEIF(fname);
	XP_FREEIF(viewstream);
	XP_FREEIF(suffix);
	return;

}
Ejemplo n.º 27
0
/**
 * Check if file should be recycled
 **/
static int recycle_unlink(vfs_handle_struct *handle, connection_struct *conn, const char *file_name)
{
	char *path_name = NULL;
       	char *temp_name = NULL;
	char *final_name = NULL;
	const char *base;
	char *repository = NULL;
	int i = 1;
	int maxsize;
	SMB_OFF_T file_size; /* space_avail;	*/
	BOOL exist;
	int rc = -1;

	repository = alloc_sub_conn(conn, recycle_repository(handle));
	ALLOC_CHECK(repository, done);
	/* shouldn't we allow absolute path names here? --metze */
	trim_char(repository, '/', '/');
	
	if(!repository || *(repository) == '\0') {
		DEBUG(3, ("recycle: repository path not set, purging %s...\n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	/* we don't recycle the recycle bin... */
	if (strncmp(file_name, repository, strlen(repository)) == 0) {
		DEBUG(3, ("recycle: File is within recycling bin, unlinking ...\n"));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	file_size = recycle_get_file_size(handle, file_name);
	/* it is wrong to purge filenames only because they are empty imho
	 *   --- simo
	 *
	if(fsize == 0) {
		DEBUG(3, ("recycle: File %s is empty, purging...\n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle,conn,file_name);
		goto done;
	}
	 */

	/* FIXME: this is wrong, we should check the hole size of the recycle bin is
	 * not greater then maxsize, not the size of the single file, also it is better
	 * to remove older files
	 */
	maxsize = recycle_maxsize(handle);
	if(maxsize > 0 && file_size > maxsize) {
		DEBUG(3, ("recycle: File %s exceeds maximum recycle size, purging... \n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	/* FIXME: this is wrong: moving files with rename does not change the disk space
	 * allocation
	 *
	space_avail = SMB_VFS_NEXT_DISK_FREE(handle, conn, ".", True, &bsize, &dfree, &dsize) * 1024L;
	DEBUG(5, ("space_avail = %Lu, file_size = %Lu\n", space_avail, file_size));
	if(space_avail < file_size) {
		DEBUG(3, ("recycle: Not enough diskspace, purging file %s\n", file_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}
	 */

	/* extract filename and path */
	base = strrchr(file_name, '/');
	if (base == NULL) {
		base = file_name;
		path_name = SMB_STRDUP("/");
		ALLOC_CHECK(path_name, done);
	}
	else {
		path_name = SMB_STRDUP(file_name);
		ALLOC_CHECK(path_name, done);
		path_name[base - file_name] = '\0';
		base++;
	}

	DEBUG(10, ("recycle: fname = %s\n", file_name));	/* original filename with path */
	DEBUG(10, ("recycle: fpath = %s\n", path_name));	/* original path */
	DEBUG(10, ("recycle: base = %s\n", base));		/* filename without path */

	if (matchparam(recycle_exclude(handle), base)) {
		DEBUG(3, ("recycle: file %s is excluded \n", base));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	/* FIXME: this check will fail if we have more than one level of directories,
	 * we shoud check for every level 1, 1/2, 1/2/3, 1/2/3/4 .... 
	 * 	---simo
	 */
	if (checkparam(recycle_exclude_dir(handle), path_name)) {
		DEBUG(3, ("recycle: directory %s is excluded \n", path_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	if (recycle_keep_dir_tree(handle) == True) {
		asprintf(&temp_name, "%s/%s", repository, path_name);
	} else {
		temp_name = SMB_STRDUP(repository);
	}
	ALLOC_CHECK(temp_name, done);

	exist = recycle_directory_exist(handle, temp_name);
	if (exist) {
		DEBUG(10, ("recycle: Directory already exists\n"));
	} else {
		DEBUG(10, ("recycle: Creating directory %s\n", temp_name));
		if (recycle_create_dir(handle, temp_name) == False) {
			DEBUG(3, ("recycle: Could not create directory, purging %s...\n", file_name));
			rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
			goto done;
		}
	}

	asprintf(&final_name, "%s/%s", temp_name, base);
	ALLOC_CHECK(final_name, done);
	DEBUG(10, ("recycle: recycled file name: %s\n", final_name));		/* new filename with path */

	/* check if we should delete file from recycle bin */
	if (recycle_file_exist(handle, final_name)) {
		if (recycle_versions(handle) == False || matchparam(recycle_noversions(handle), base) == True) {
			DEBUG(3, ("recycle: Removing old file %s from recycle bin\n", final_name));
			if (SMB_VFS_NEXT_UNLINK(handle, conn, final_name) != 0) {
				DEBUG(1, ("recycle: Error deleting old file: %s\n", strerror(errno)));
			}
		}
	}

	/* rename file we move to recycle bin */
	i = 1;
	while (recycle_file_exist(handle, final_name)) {
		SAFE_FREE(final_name);
		asprintf(&final_name, "%s/Copy #%d of %s", temp_name, i++, base);
	}

	DEBUG(10, ("recycle: Moving %s to %s\n", file_name, final_name));
	rc = SMB_VFS_NEXT_RENAME(handle, conn, file_name, final_name);
	if (rc != 0) {
		DEBUG(3, ("recycle: Move error %d (%s), purging file %s (%s)\n", errno, strerror(errno), file_name, final_name));
		rc = SMB_VFS_NEXT_UNLINK(handle, conn, file_name);
		goto done;
	}

	/* touch access date of moved file */
	if (recycle_touch(handle) == True )
		recycle_do_touch(handle, final_name);

done:
	SAFE_FREE(path_name);
	SAFE_FREE(temp_name);
	SAFE_FREE(final_name);
	SAFE_FREE(repository);
	return rc;
}
Ejemplo n.º 28
0
static int net_idmap_secret(int argc, const char **argv)
{
	TALLOC_CTX *ctx;
	const char *secret;
	const char *dn;
	char *domain;
	char *backend;
	char *opt = NULL;
	bool ret;

	if (argc != 2) {
		return net_help_idmap(argc, argv);
	}

	secret = argv[1];

	ctx = talloc_new(NULL);
	ALLOC_CHECK(ctx);

	if (strcmp(argv[0], "alloc") == 0) {
		domain = NULL;
		backend = lp_idmap_alloc_backend();
	} else {
		domain = talloc_strdup(ctx, argv[0]);
		ALLOC_CHECK(domain);

		opt = talloc_asprintf(ctx, "idmap config %s", domain);
		ALLOC_CHECK(opt);

		backend = talloc_strdup(ctx, lp_parm_const_string(-1, opt, "backend", "tdb"));
		ALLOC_CHECK(backend);
	}

	if ( ( ! backend) || ( ! strequal(backend, "ldap"))) {
		d_fprintf(stderr, "The only currently supported backend is LDAP\n");
		talloc_free(ctx);
		return -1;
	}

	if (domain) {

		dn = lp_parm_const_string(-1, opt, "ldap_user_dn", NULL);
		if ( ! dn) {
			d_fprintf(stderr, "Missing ldap_user_dn option for domain %s\n", domain);
			talloc_free(ctx);
			return -1;
		}

		ret = idmap_store_secret("ldap", false, domain, dn, secret);
	} else {
		dn = lp_parm_const_string(-1, "idmap alloc config", "ldap_user_dn", NULL);
		if ( ! dn) {
			d_fprintf(stderr, "Missing ldap_user_dn option for alloc backend\n");
			talloc_free(ctx);
			return -1;
		}

		ret = idmap_store_secret("ldap", true, NULL, dn, secret);
	}

	if ( ! ret) {
		d_fprintf(stderr, "Failed to store secret\n");
		talloc_free(ctx);
		return -1;
	}

	d_printf("Secret stored\n");
	return 0;
}