Exemplo n.º 1
0
enum rpc_service_mode_e rpc_service_mode(const char *name)
{
	const char *rpcsrv_type;
	enum rpc_service_mode_e state;
	const char *def;
	int i;

	def = "embedded";
	for (i = 0; rpc_service_defaults[i].name; i++) {
		if (strcasecmp_m(name, rpc_service_defaults[i].name) == 0) {
			def = rpc_service_defaults[i].def_mode;
		}
	}

	rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
					   "rpc_server", name, def);

	if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
		state = RPC_SERVICE_MODE_EMBEDDED;
	} else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
		state = RPC_SERVICE_MODE_EXTERNAL;
	} else {
		state = RPC_SERVICE_MODE_DISABLED;
	}

	return state;
}
Exemplo n.º 2
0
enum rpc_daemon_type_e rpc_daemon_type(const char *name)
{
	const char *rpcsrv_type;
	enum rpc_daemon_type_e type;
	const char *def;
	int i;

	def = "embedded";
	for (i = 0; rpc_daemon_defaults[i].name; i++) {
		if (strcasecmp_m(name, rpc_daemon_defaults[i].name) == 0) {
			def = rpc_daemon_defaults[i].def_type;
		}
	}

	rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
					   "rpc_daemon", name, def);

	if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
		type = RPC_DAEMON_EMBEDDED;
	} else if (strcasecmp_m(rpcsrv_type, "fork") == 0) {
		type = RPC_DAEMON_FORK;
	} else {
		type = RPC_DAEMON_DISABLED;
	}

	return type;
}
Exemplo n.º 3
0
static NTSTATUS lookup_well_known_names(TALLOC_CTX *mem_ctx, const char *domain,
                                        const char *name, const char **authority_name,
                                        struct dom_sid **sid, uint32_t *rtype)
{
    int i;
    for (i=0; well_known[i].sid; i++) {
        if (domain) {
            if (strcasecmp_m(domain, well_known[i].domain) == 0
                    && strcasecmp_m(name, well_known[i].name) == 0) {
                *authority_name = well_known[i].domain;
                *sid = dom_sid_parse_talloc(mem_ctx, well_known[i].sid);
                *rtype = well_known[i].rtype;
                return NT_STATUS_OK;
            }
        } else {
            if (strcasecmp_m(name, well_known[i].name) == 0) {
                *authority_name = well_known[i].domain;
                *sid = dom_sid_parse_talloc(mem_ctx, well_known[i].sid);
                *rtype = well_known[i].rtype;
                return NT_STATUS_OK;
            }
        }
    }
    return NT_STATUS_NOT_FOUND;
}
Exemplo n.º 4
0
/*
  seek to the given name
*/
NTSTATUS pvfs_list_seek(struct pvfs_dir *dir, const char *name, off_t *ofs)
{
	struct dirent *de;
	int i;

	dir->end_of_search = False;

	if (ISDOT(name)) {
		dir->offset = DIR_OFFSET_DOTDOT;
		*ofs = dir->offset;
		return NT_STATUS_OK;
	}

	if (ISDOTDOT(name)) {
		dir->offset = DIR_OFFSET_BASE;
		*ofs = dir->offset;
		return NT_STATUS_OK;
	}

	for (i=dir->name_cache_index;i>=0;i--) {
		struct name_cache_entry *e = &dir->name_cache[i];
		if (e->name && strcasecmp_m(name, e->name) == 0) {
			*ofs = e->offset;
			return NT_STATUS_OK;
		}
	}
	for (i=NAME_CACHE_SIZE-1;i>dir->name_cache_index;i--) {
		struct name_cache_entry *e = &dir->name_cache[i];
		if (e->name && strcasecmp_m(name, e->name) == 0) {
			*ofs = e->offset;
			return NT_STATUS_OK;
		}
	}

	rewinddir(dir->dir);

	while ((de = readdir(dir->dir))) {
		if (strcasecmp_m(name, de->d_name) == 0) {
			dir->offset = telldir(dir->dir) + DIR_OFFSET_BASE;
			*ofs = dir->offset;
			return NT_STATUS_OK;
		}
	}

	dir->end_of_search = True;

	return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
Exemplo n.º 5
0
/* lookup hosts or IP addresses using internal samba lookup fns */
int net_lookup(struct net_context *c, int argc, const char **argv)
{
	int i;

	struct functable table[] = {
		{"HOST", net_lookup_host},
		{"LDAP", net_lookup_ldap},
		{"DC", net_lookup_dc},
		{"PDC", net_lookup_pdc},
		{"MASTER", net_lookup_master},
		{"KDC", net_lookup_kdc},
		{"NAME", net_lookup_name},
		{"SID", net_lookup_sid},
		{"DSGETDCNAME", net_lookup_dsgetdcname},
		{NULL, NULL}
	};

	if (argc < 1) {
		d_printf(_("\nUsage: \n"));
		return net_lookup_usage(c, argc, argv);
	}
	for (i=0; table[i].funcname; i++) {
		if (strcasecmp_m(argv[0], table[i].funcname) == 0)
			return table[i].fn(c, argc-1, argv+1);
	}

	/* Default to lookup a hostname so 'net lookup foo#1b' can be
	   used instead of 'net lookup host foo#1b'.  The host syntax
	   is a bit confusing as non #00 names can't really be
	   considered hosts as such. */

	return net_lookup_host(c, argc, argv);
}
Exemplo n.º 6
0
/*
  reply to a RAW_FILEINFO_EA_LIST call
*/
NTSTATUS pvfs_query_ea_list(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx, 
			    struct pvfs_filename *name, int fd, 
			    unsigned int num_names,
			    struct ea_name *names,
			    struct smb_ea_list *eas)
{
	NTSTATUS status;
	int i;
	struct xattr_DosEAs *ealist = talloc(mem_ctx, struct xattr_DosEAs);

	ZERO_STRUCTP(eas);
	status = pvfs_doseas_load(pvfs, name, fd, ealist);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}
	eas->eas = talloc_array(mem_ctx, struct ea_struct, num_names);
	if (eas->eas == NULL) {
		return NT_STATUS_NO_MEMORY;
	}
	eas->num_eas = num_names;
	for (i=0;i<num_names;i++) {
		int j;
		eas->eas[i].flags = 0;
		eas->eas[i].name.s = names[i].name.s;
		eas->eas[i].value = data_blob(NULL, 0);
		for (j=0;j<ealist->num_eas;j++) {
			if (strcasecmp_m(eas->eas[i].name.s, 
				       ealist->eas[j].name) == 0) {
				eas->eas[i].value = ealist->eas[j].value;
				break;
			}
		}
	}
	return NT_STATUS_OK;
}
Exemplo n.º 7
0
static NTSTATUS check_privilege_for_user(struct rpc_pipe_client *pipe_hnd,
					TALLOC_CTX *ctx,
					struct policy_handle *pol,
					struct dom_sid *sid,
					const char *right)
{
	NTSTATUS status, result;
	struct lsa_RightSet rights;
	int i;
	struct dcerpc_binding_handle *b = pipe_hnd->binding_handle;

	status = dcerpc_lsa_EnumAccountRights(b, ctx,
					      pol,
					      sid,
					      &rights,
					      &result);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}
	if (!NT_STATUS_IS_OK(result)) {
		return result;
	}

	if (rights.count == 0) {
		return NT_STATUS_OBJECT_NAME_NOT_FOUND;
	}

	for (i = 0; i < rights.count; i++) {
		if (strcasecmp_m(rights.names[i].string, right) == 0) {
			return NT_STATUS_OK;
		}
	}

	return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
Exemplo n.º 8
0
static bool find_returned_ea(union smb_fileinfo *finfo2,
				const char *eaname,
				const char *eavalue)
{
	unsigned int i;
	unsigned int num_eas = finfo2->all_eas.out.num_eas;
	struct ea_struct *eas = finfo2->all_eas.out.eas;

	for (i = 0; i < num_eas; i++) {
		if (eas[i].name.s == NULL) {
			continue;
		}
		/* Windows capitalizes returned EA names. */
		if (strcasecmp_m(eas[i].name.s, eaname)) {
			continue;
		}
		if (eavalue == NULL && eas[i].value.length == 0) {
			/* Null value, found it ! */
			return true;
		}
		if (eas[i].value.length == strlen(eavalue) &&
				memcmp(eas[i].value.data,
					eavalue,
					strlen(eavalue)) == 0) {
			return true;
		}
	}
	return false;
}
Exemplo n.º 9
0
/**
 * This imitates net_run_function but calls the main functions
 * through the wrapper net_conf_wrap_function().
 */
static int net_conf_run_function(struct net_context *c, int argc,
				 const char **argv, const char *whoami,
				 struct conf_functable *table)
{
	int i;

	if (argc != 0) {
		for (i=0; table[i].funcname; i++) {
			if (strcasecmp_m(argv[0], table[i].funcname) == 0)
				return net_conf_wrap_function(c, table[i].fn,
							      argc-1,
							      argv+1);
		}
	}

	d_printf(_("Usage:\n"));
	for (i=0; table[i].funcname; i++) {
		if (c->display_usage == false)
			d_printf("%s %-15s %s\n", whoami, table[i].funcname,
				 table[i].description);
		else
			d_printf("%s\n", table[i].usage);
	}

	return c->display_usage?0:-1;
}
/****************************************************************************
 Returns true if the filename's stream == "::$DATA"
 ***************************************************************************/
bool is_ntfs_default_stream_smb_fname(const struct smb_filename *smb_fname)
{
	if (!is_ntfs_stream_smb_fname(smb_fname)) {
		return false;
	}

	return strcasecmp_m(smb_fname->stream_name, "::$DATA") == 0;
}
Exemplo n.º 11
0
static void set_visible(struct clilist_file_info *i, const char *mask,
			void *priv)
{
	struct list_state *state = (struct list_state *)priv;

	if (strcasecmp_m(state->fname, i->name) == 0)
		state->visible = true;
}
Exemplo n.º 12
0
NTSTATUS libnet_SamDump(struct libnet_context *ctx, TALLOC_CTX *mem_ctx, 
			struct libnet_SamDump *r)
{
	NTSTATUS nt_status;
	struct libnet_SamSync r2;
	struct samdump_state *samdump_state = talloc(mem_ctx, struct samdump_state);

	struct samdump_trusted_domain *t;
	struct samdump_secret *s;

	if (!samdump_state) {
		return NT_STATUS_NO_MEMORY;
	}

	samdump_state->secrets         = NULL;
	samdump_state->trusted_domains = NULL;

	r2.out.error_string            = NULL;
	r2.in.binding_string           = r->in.binding_string;
	r2.in.init_fn                  = NULL;
	r2.in.delta_fn                 = libnet_samdump_fn;
	r2.in.fn_ctx                   = samdump_state;
	r2.in.machine_account          = r->in.machine_account;
	nt_status                      = libnet_SamSync_netlogon(ctx, samdump_state, &r2);
	r->out.error_string            = r2.out.error_string;
	talloc_steal(mem_ctx, r->out.error_string);

	if (!NT_STATUS_IS_OK(nt_status)) {
		talloc_free(samdump_state);
		return nt_status;
	}

	printf("Trusted domains, sids and secrets:\n");
	for (t=samdump_state->trusted_domains; t; t=t->next) {
		char *secret_name = talloc_asprintf(mem_ctx, "G$$%s", t->name);
		for (s=samdump_state->secrets; s; s=s->next) {
			size_t converted_size = 0;
			char *secret_string;
			if (strcasecmp_m(s->name, secret_name) != 0) {
				continue;
			}
			if (!convert_string_talloc_handle(mem_ctx, lpcfg_iconv_handle(ctx->lp_ctx), CH_UTF16, CH_UNIX,
						  s->secret.data, s->secret.length, 
						  (void **)&secret_string, &converted_size)) {
				r->out.error_string = talloc_asprintf(mem_ctx, 
								      "Could not convert secret for domain %s to a string",
								      t->name);
				talloc_free(samdump_state);
				return NT_STATUS_INVALID_PARAMETER;
			}
			printf("%s\t%s\t%s\n", 
			       t->name, dom_sid_string(mem_ctx, t->sid), 
			       secret_string);
		}
	}
	talloc_free(samdump_state);
	return nt_status;
}
Exemplo n.º 13
0
Arquivo: util.c Projeto: amitay/samba
/**
  see if a string matches either our primary or one of our secondary 
  netbios aliases. do a case insensitive match
*/
bool lpcfg_is_myname(struct loadparm_context *lp_ctx, const char *name)
{
	const char **aliases;
	int i;

	if (strcasecmp_m(name, lpcfg_netbios_name(lp_ctx)) == 0) {
		return true;
	}

	aliases = lpcfg_netbios_aliases(lp_ctx);
	for (i=0; aliases && aliases[i]; i++) {
		if (strcasecmp_m(name, aliases[i]) == 0) {
			return true;
		}
	}

	return false;
}
Exemplo n.º 14
0
/**
 * Compare 2 strings.
 *
 * @note The comparison is case-insensitive.
 **/
_PUBLIC_ bool strequal(const char *s1, const char *s2)
{
	if (s1 == s2)
		return true;
	if (!s1 || !s2)
		return false;
  
	return strcasecmp_m(s1,s2) == 0;
}
Exemplo n.º 15
0
static PyObject *py_strcasecmp_m(PyObject *self, PyObject *args)
{
	char *s1, *s2;

	if (!PyArg_ParseTuple(args, "ss", &s1, &s2))
		return NULL;

	return PyInt_FromLong(strcasecmp_m(s1, s2));
}
Exemplo n.º 16
0
enum rpc_service_mode_e rpc_service_mode(const char *name)
{
	const char *pipe_name = name;
	const char *rpcsrv_type;
	enum rpc_service_mode_e state;
	const char *def;
	int i;

	/* Handle pipes with multiple names */
	if (strcmp(pipe_name, "lsass") == 0) {
		pipe_name = "lsarpc";
	} else if (strcmp(pipe_name, "plugplay") == 0) {
		pipe_name = "ntsvcs";
	}

	def = lp_parm_const_string(GLOBAL_SECTION_SNUM,
				   "rpc_server", "default", NULL);
	if (def == NULL) {
		for (i = 0; rpc_service_defaults[i].name; i++) {
			if (strcasecmp_m(pipe_name, rpc_service_defaults[i].name) == 0) {
				def = rpc_service_defaults[i].def_mode;
				break;
			}
		}
		/* if the default is unspecified then use 'embedded' */
		if (def == NULL) {
			def = "embedded";
		}
	}

	rpcsrv_type = lp_parm_const_string(GLOBAL_SECTION_SNUM,
					   "rpc_server", pipe_name, def);

	if (strcasecmp_m(rpcsrv_type, "embedded") == 0) {
		state = RPC_SERVICE_MODE_EMBEDDED;
	} else if (strcasecmp_m(rpcsrv_type, "external") == 0) {
		state = RPC_SERVICE_MODE_EXTERNAL;
	} else {
		state = RPC_SERVICE_MODE_DISABLED;
	}

	return state;
}
Exemplo n.º 17
0
NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
				     const struct smb_filename *smb_fname_in,
				     struct smb_filename **smb_fname_out)
{
	char *stream_name = NULL;
	NTSTATUS status;

	/*
	 * Only attempt to strip off the trailing :$DATA if there is an actual
	 * stream there.  If it is the default stream, the smb_fname_out will
	 * just have a NULL stream so the base file is opened.
	 */
	if (smb_fname_in->stream_name &&
	    !is_ntfs_default_stream_smb_fname(smb_fname_in)) {
		char *str_tmp = smb_fname_in->stream_name;

		/* First strip off the leading ':' */
		if (str_tmp[0] == ':') {
			str_tmp++;
		}

		/* Create a new copy of the stream_name. */
		stream_name = talloc_strdup(ctx, str_tmp);
		if (stream_name == NULL) {
			return NT_STATUS_NO_MEMORY;
		}

		/* Strip off the :$DATA if one exists. */
		str_tmp = strrchr_m(stream_name, ':');
		if (str_tmp) {
			if (strcasecmp_m(str_tmp, ":$DATA") != 0) {
				return NT_STATUS_INVALID_PARAMETER;
			}
			str_tmp[0] = '\0';
		}
	}

	/*
	 * If there was a stream that wasn't the default stream the leading
	 * colon and trailing :$DATA has now been stripped off.  Create a new
	 * smb_filename to pass back.
	 */
	status = create_synthetic_smb_fname(ctx, smb_fname_in->base_name,
					    stream_name, &smb_fname_in->st,
					    smb_fname_out);
	TALLOC_FREE(stream_name);

	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(5, ("Failed to prep stream name for %s: %s\n",
			  *smb_fname_out ?
			  smb_fname_str_dbg(*smb_fname_out) : "NULL",
			  nt_errstr(status)));
	}
	return status;
}
Exemplo n.º 18
0
struct param *param_section_get (struct param_section *section, const char *name)
{
	struct param *p;

	for (p = section->parameters; p; p = p->next) {
		if (strcasecmp_m(p->name, name) == 0) 
			return p;
	}

	return NULL;
}
Exemplo n.º 19
0
/* lookup is case-insensitive */
static struct fss_sc_smap *sc_smap_lookup(struct fss_sc_smap *smaps_head,
					  const char *share)
{
	struct fss_sc_smap *sc_smap;
	for (sc_smap = smaps_head; sc_smap; sc_smap = sc_smap->next) {
		if (!strcasecmp_m(sc_smap->share_name, share)) {
			return sc_smap;
		}
	}
	DEBUG(4, ("shadow copy share mapping for %s not found\n", share));
	return NULL;
}
Exemplo n.º 20
0
struct param_section *param_get_section(struct param_context *ctx, const char *name)
{
	struct param_section *sect;

	if (name == NULL) 
		name = GLOBAL_NAME;

	for (sect = ctx->sections; sect; sect = sect->next) {
		if (!strcasecmp_m(sect->name, name)) 
			return sect;
	}

	return NULL;
}
Exemplo n.º 21
0
/*
  reply to a GETDC request
 */
static void nbtd_netlogon_getdc(struct dgram_mailslot_handler *dgmslot, 
				struct nbtd_interface *iface,
				struct nbt_dgram_packet *packet, 
				const struct socket_address *src,
				struct nbt_netlogon_packet *netlogon)
{
	struct nbt_name *name = &packet->data.msg.dest_name;
	struct nbtd_interface *reply_iface = nbtd_find_reply_iface(iface, src->addr, false);
	struct nbt_netlogon_response_from_pdc *pdc;
	struct ldb_context *samctx;
	struct nbt_netlogon_response netlogon_response;

	/* only answer getdc requests on the PDC or LOGON names */
	if (name->type != NBT_NAME_PDC && name->type != NBT_NAME_LOGON) {
		return;
	}

	samctx = iface->nbtsrv->sam_ctx;

	if (lpcfg_server_role(iface->nbtsrv->task->lp_ctx) != ROLE_DOMAIN_CONTROLLER
	    || !samdb_is_pdc(samctx)) {
		DEBUG(2, ("Not a PDC, so not processing LOGON_PRIMARY_QUERY\n"));
		return;		
	}

	if (strcasecmp_m(name->name, lpcfg_workgroup(iface->nbtsrv->task->lp_ctx)) != 0) {
		DEBUG(5,("GetDC requested for a domian %s that we don't host\n", name->name));
		return;
	}

	/* setup a GETDC reply */
	ZERO_STRUCT(netlogon_response);
	netlogon_response.response_type = NETLOGON_GET_PDC;
	pdc = &netlogon_response.data.get_pdc;

	pdc->command = NETLOGON_RESPONSE_FROM_PDC;
	pdc->pdc_name         = lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx);
	pdc->unicode_pdc_name = pdc->pdc_name;
	pdc->domain_name      = lpcfg_workgroup(iface->nbtsrv->task->lp_ctx);
	pdc->nt_version       = 1;
	pdc->lmnt_token       = 0xFFFF;
	pdc->lm20_token       = 0xFFFF;

	dgram_mailslot_netlogon_reply(reply_iface->dgmsock, 
				      packet, 
				      lpcfg_netbios_name(iface->nbtsrv->task->lp_ctx),
				      netlogon->req.pdc.mailslot_name,
				      &netlogon_response);
}
Exemplo n.º 22
0
static NTSTATUS lookup_well_known_sids(TALLOC_CTX *mem_ctx,
                                       const char *sid_str, const char **authority_name,
                                       const char **name, uint32_t *rtype)
{
    int i;
    for (i=0; well_known[i].sid; i++) {
        if (strcasecmp_m(sid_str, well_known[i].sid) == 0) {
            *authority_name = well_known[i].domain;
            *name = well_known[i].name;
            *rtype = well_known[i].rtype;
            return NT_STATUS_OK;
        }
    }
    return NT_STATUS_NOT_FOUND;
}
Exemplo n.º 23
0
int net_group(struct net_context *c, int argc, const char **argv)
{
	if (argc < 1)
		return net_group_usage(c, argc, argv);

	if (strcasecmp_m(argv[0], "HELP") == 0) {
		net_group_usage(c, argc, argv);
		return 0;
	}

	if (net_ads_check(c) == 0)
		return net_ads_group(c, argc, argv);

	return net_rap_group(c, argc, argv);
}
Exemplo n.º 24
0
/*
  add a single DOS EA
*/
NTSTATUS pvfs_setfileinfo_ea_set(struct pvfs_state *pvfs, 
				 struct pvfs_filename *name,
				 int fd, uint16_t num_eas,
				 struct ea_struct *eas)
{
	struct xattr_DosEAs *ealist;
	int i, j;
	NTSTATUS status;

	if (num_eas == 0) {
		return NT_STATUS_OK;
	}

	if (!(pvfs->flags & PVFS_FLAG_XATTR_ENABLE)) {
		return NT_STATUS_NOT_SUPPORTED;
	}

	ealist = talloc(name, struct xattr_DosEAs);

	/* load the current list */
	status = pvfs_doseas_load(pvfs, name, fd, ealist);
	if (!NT_STATUS_IS_OK(status)) {
		return status;
	}

	for (j=0;j<num_eas;j++) {
		struct ea_struct *ea = &eas[j];
		/* see if its already there */
		for (i=0;i<ealist->num_eas;i++) {
			if (strcasecmp_m(ealist->eas[i].name, ea->name.s) == 0) {
				ealist->eas[i].value = ea->value;
				break;
			}
		}

		if (i==ealist->num_eas) {
			/* add it */
			ealist->eas = talloc_realloc(ealist, ealist->eas, 
						       struct xattr_EA, 
						       ealist->num_eas+1);
			if (ealist->eas == NULL) {
				return NT_STATUS_NO_MEMORY;
			}
			ealist->eas[i].name = ea->name.s;
			ealist->eas[i].value = ea->value;
			ealist->num_eas++;
		}
	}
Exemplo n.º 25
0
static bool test_strcasecmp_m(struct torture_context *tctx)
{
	/* file.{accented e} in iso8859-1 */
	const char file_iso8859_1[7] = { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xe9, 0 };
	/* file.{accented e} in utf8 */
	const char file_utf8[8] =      { 0x66, 0x69, 0x6c, 0x65, 0x2d, 0xc3, 0xa9, 0 };
	torture_assert(tctx, strcasecmp_m("foo", "bar") != 0, "different strings");
	torture_assert(tctx, strcasecmp_m("foo", "foo") == 0, "same case strings");
	torture_assert(tctx, strcasecmp_m("foo", "Foo") == 0, "different case strings");
	torture_assert(tctx, strcasecmp_m(NULL, "Foo") != 0, "one NULL");
	torture_assert(tctx, strcasecmp_m("foo", NULL) != 0, "other NULL");
	torture_assert(tctx, strcasecmp_m(NULL, NULL) == 0, "both NULL");
	torture_assert(tctx, strcasecmp_m(file_iso8859_1, file_utf8) != 0,
		"file.{accented e} should differ");
	return true;
}
Exemplo n.º 26
0
/*
  add to the lsa_RefDomainList for LookupSids and LookupNames
*/
static NTSTATUS dcesrv_lsa_authority_list(struct lsa_policy_state *state, TALLOC_CTX *mem_ctx,
        enum lsa_SidType rtype,
        const char *authority_name,
        struct dom_sid *sid,
        struct lsa_RefDomainList *domains,
        uint32_t *sid_index)
{
    struct dom_sid *authority_sid;
    int i;

    if (rtype != SID_NAME_DOMAIN) {
        authority_sid = dom_sid_dup(mem_ctx, sid);
        if (authority_sid == NULL) {
            return NT_STATUS_NO_MEMORY;
        }
        authority_sid->num_auths--;
    } else {
        authority_sid = sid;
    }

    /* see if we've already done this authority name */
    for (i=0; i<domains->count; i++) {
        if (strcasecmp_m(authority_name, domains->domains[i].name.string) == 0) {
            *sid_index = i;
            return NT_STATUS_OK;
        }
    }

    domains->domains = talloc_realloc(domains,
                                      domains->domains,
                                      struct lsa_DomainInfo,
                                      domains->count+1);
    if (domains->domains == NULL) {
        return NT_STATUS_NO_MEMORY;
    }
    domains->domains[i].name.string = authority_name;
    domains->domains[i].sid         = authority_sid;
    domains->count++;
    domains->max_size = LSA_REF_DOMAIN_LIST_MULTIPLIER * domains->count;
    *sid_index = i;

    return NT_STATUS_OK;
}
Exemplo n.º 27
0
int write_bom(FILE* file, const char* charset, charset_t ctype)
{
	int i;
	if ( charset == NULL ) {
		for (i=0; BOM[i].name; i++) {
			if (BOM[i].ctype == ctype) {
				return fwrite(BOM[i].seq, 1, BOM[i].len, file);
			}
		}
		DEBUG(0, ("No Byte Order Mark for charset_t: %u\n", (unsigned)ctype));
	} else {
		for (i=0; BOM[i].name; i++) {
			if (strcasecmp_m(BOM[i].name, charset) == 0) {
				return fwrite(BOM[i].seq, 1, BOM[i].len, file);
			}
		}
		DEBUG(0, ("No Byte Order Mark for charset_t: %s\n", charset));
	}
	return 0;
}
Exemplo n.º 28
0
static int compare_dirent (const SMB_STRUCT_DIRENT *da, const SMB_STRUCT_DIRENT *db)
{
	return strcasecmp_m(da->d_name, db->d_name);
}
Exemplo n.º 29
0
static int compare_dirent (const struct dirent *da, const struct dirent *db)
{
	return strcasecmp_m(da->d_name, db->d_name);
}
Exemplo n.º 30
0
static int streams_xattr_rename(vfs_handle_struct *handle,
				const struct smb_filename *smb_fname_src,
				const struct smb_filename *smb_fname_dst)
{
	NTSTATUS status;
	int ret = -1;
	char *src_xattr_name = NULL;
	char *dst_xattr_name = NULL;
	bool src_is_stream, dst_is_stream;
	ssize_t oret;
	ssize_t nret;
	struct ea_struct ea;

	src_is_stream = is_ntfs_stream_smb_fname(smb_fname_src);
	dst_is_stream = is_ntfs_stream_smb_fname(smb_fname_dst);

	if (!src_is_stream && !dst_is_stream) {
		return SMB_VFS_NEXT_RENAME(handle, smb_fname_src,
					   smb_fname_dst);
	}

	/* For now don't allow renames from or to the default stream. */
	if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
	    is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
		errno = ENOSYS;
		goto done;
	}

	/* Don't rename if the streams are identical. */
	if (strcasecmp_m(smb_fname_src->stream_name,
		       smb_fname_dst->stream_name) == 0) {
		goto done;
	}

	/* Get the xattr names. */
	status = streams_xattr_get_name(handle, talloc_tos(),
					smb_fname_src->stream_name,
					&src_xattr_name);
	if (!NT_STATUS_IS_OK(status)) {
		errno = map_errno_from_nt_status(status);
		goto fail;
	}
	status = streams_xattr_get_name(handle, talloc_tos(),
					smb_fname_dst->stream_name,
					&dst_xattr_name);
	if (!NT_STATUS_IS_OK(status)) {
		errno = map_errno_from_nt_status(status);
		goto fail;
	}

	/* read the old stream */
	status = get_ea_value(talloc_tos(), handle->conn, NULL,
			      smb_fname_src, src_xattr_name, &ea);
	if (!NT_STATUS_IS_OK(status)) {
		errno = ENOENT;
		goto fail;
	}

	/* (over)write the new stream */
	nret = SMB_VFS_SETXATTR(handle->conn, smb_fname_src,
				dst_xattr_name, ea.value.data, ea.value.length,
				0);
	if (nret < 0) {
		if (errno == ENOATTR) {
			errno = ENOENT;
		}
		goto fail;
	}

	/* remove the old stream */
	oret = SMB_VFS_REMOVEXATTR(handle->conn, smb_fname_src,
				   src_xattr_name);
	if (oret < 0) {
		if (errno == ENOATTR) {
			errno = ENOENT;
		}
		goto fail;
	}

 done:
	errno = 0;
	ret = 0;
 fail:
	TALLOC_FREE(src_xattr_name);
	TALLOC_FREE(dst_xattr_name);
	return ret;
}