Ejemplo n.º 1
0
WERROR dsdb_subSchema_attributeTypes(const struct dsdb_schema *schema,
				     TALLOC_CTX *mem_ctx)
{
	struct ldb_message_element *e;
	struct dsdb_attribute *a;

	e = talloc_zero(mem_ctx, struct ldb_message_element);
	W_ERROR_HAVE_NO_MEMORY(e);

	for (a = schema->attributes; a; a = a->next) {
		char *v;

		v = talloc_asprintf(e, "( %s NAME '%s' SYNTAX '%s' ",
				    a->attributeID_oid, a->lDAPDisplayName,
				    a->syntax->ldap_oid);
		W_ERROR_HAVE_NO_MEMORY(v);

		if (a->isSingleValued) {
			v = talloc_asprintf_append(v, "SINGLE-VALUE ");
			W_ERROR_HAVE_NO_MEMORY(v);
		}

		if (a->systemOnly) {
			v = talloc_asprintf_append(v, "NO-USER-MODIFICATION ");
			W_ERROR_HAVE_NO_MEMORY(v);
		}

		v = talloc_asprintf_append(v, ")");
		W_ERROR_HAVE_NO_MEMORY(v);

		DEBUG(0,("%s\n", v));
	}

	return WERR_FOOBAR;
}
Ejemplo n.º 2
0
static char *dsdb_subSchema_list_append(char *v, const char *list_name)
{
	bool first = true;
	uint32_t i;
	const char *attrs[] = {
		"attr1",
		"attr2",
		"attr3",
		NULL
	};

	if (!attrs) {
		return v;
	}

	v = talloc_asprintf_append(v, "%s ( ", list_name);
	if (!v) return NULL;

	for (i=0; attrs[i]; i++) {
		v = talloc_asprintf_append(v, "%s%s ",
					   (!first ? "$ " : ""),
					   attrs[i]);
		if (!v) return NULL;
		first = false;
	}

	v = talloc_asprintf_append(v, ") ");
	if (!v) return NULL;

	return v;
}
Ejemplo n.º 3
0
static char *wbinfo_prompt_pass(const char *prefix,
				const char *username)
{
	char *prompt;
	const char *ret = NULL;

	prompt = talloc_asprintf(talloc_tos(), "Enter %s's ", username);
	if (!prompt) {
		return NULL;
	}
	if (prefix) {
		prompt = talloc_asprintf_append(prompt, "%s ", prefix);
		if (!prompt) {
			return NULL;
		}
	}
	prompt = talloc_asprintf_append(prompt, "password: ");
	if (!prompt) {
		return NULL;
	}

	ret = getpass(prompt);
	TALLOC_FREE(prompt);

	return SMB_STRDUP(ret);
}
Ejemplo n.º 4
0
/**
 * Return a human-readable description of all talloc memory usage.
 * The result is allocated from @p t.
 **/
char *talloc_describe_all(TALLOC_CTX *rt)
{
	int n_pools = 0, total_chunks = 0;
	size_t total_bytes = 0;
	TALLOC_CTX *it;
	char *s;

	if (!rt) return NULL;

	s = talloc_asprintf(rt, "global talloc allocations in pid: %u\n",
			    (unsigned) sys_getpid());
	s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
				   "name", "chunks", "bytes");
	s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
				   "----------------------------------------",
				   "--------",
				   "--------");	
	
	for (it = list_head; it; it = it->next_ctx) {
		size_t bytes;
		int n_chunks;
		fstring what;
		
		n_pools++;
		
		talloc_get_allocation(it, &bytes, &n_chunks);

		if (it->name)
			fstrcpy(what, it->name);
		else
			slprintf(what, sizeof what, "@%p", it);
		
		s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
					   what,
					   (unsigned) n_chunks,
					   (unsigned) bytes);
		total_bytes += bytes;
		total_chunks += n_chunks;
	}

	s = talloc_asprintf_append(rt, s, "%-40s %8s %8s\n",
				   "----------------------------------------",
				   "--------",
				   "--------");	

	s = talloc_asprintf_append(rt, s, "%-40s %8u %8u\n",
				   "TOTAL",
				   (unsigned) total_chunks, (unsigned) total_bytes);

	return s;
}
/*************************************************************************
 *
 *	Function: sql_create_socket
 *
 *	Purpose: Establish connection to the db
 *
 *************************************************************************/
static int sql_init_socket(rlm_sql_handle_t *handle, rlm_sql_config_t *config) {
	char *dbstring;
	rlm_sql_postgres_conn_t *conn;

#ifdef HAVE_OPENSSL_CRYPTO_H
	static bool ssl_init = false;

	if (!ssl_init) {
		PQinitOpenSSL(0, 0);
		ssl_init = true;
	}
#endif

	MEM(conn = handle->conn = talloc_zero(handle, rlm_sql_postgres_conn_t));
	talloc_set_destructor(conn, _sql_socket_destructor);

	dbstring = strchr(config->sql_db, '=') ?
		talloc_strdup(conn, config->sql_db) :
		talloc_asprintf(conn, "dbname='%s'", config->sql_db);

	if (config->sql_server[0] != '\0') {
		dbstring = talloc_asprintf_append(dbstring, " host='%s'", config->sql_server);
	}

	if (config->sql_port[0] != '\0') {
		dbstring = talloc_asprintf_append(dbstring, " port=%s", config->sql_port);
	}

	if (config->sql_login[0] != '\0') {
		dbstring = talloc_asprintf_append(dbstring, " user='******'", config->sql_login);
	}

	if (config->sql_password[0] != '\0') {
		dbstring = talloc_asprintf_append(dbstring, " password='******'", config->sql_password);
	}

	conn->dbstring = dbstring;
	conn->db = PQconnectdb(dbstring);
	DEBUG2("rlm_sql_postgresql: Connecting using parameters: %s", dbstring);
	if (!conn->db || (PQstatus(conn->db) != CONNECTION_OK)) {
		ERROR("rlm_sql_postgresql: Connection failed: %s", PQerrorMessage(conn->db));
		return -1;
	}
	DEBUG2("Connected to database '%s' on '%s' server version %i, protocol version %i, backend PID %i ",
	       PQdb(conn->db), PQhost(conn->db), PQserverVersion(conn->db), PQprotocolVersion(conn->db),
	       PQbackendPID(conn->db));

	return 0;
}
Ejemplo n.º 6
0
/**
  \details Get FMID by mapistore URI.

  \param ictx valid pointer to indexing context
  \param username samAccountName for current user
  \param uri mapistore URI or pattern to search for
  \param partia if true, uri is pattern to search for
  \param fmidp pointer to valid location to store found FMID
  \param soft_deletedp Pointer to bool var to return Soft Deleted state

  \return MAPISTORE_SUCCESS on success
	  MAPISTORE_ERR_NOT_FOUND if uri does not exists in DB
	  MAPISTORE_ERR_NOT_INITIALIZED if ictx pointer is invalid (NULL)
	  MAPISTORE_ERR_INVALID_PARAMETER in case other parameters are not valid
	  MAPISTORE_ERR_DATABASE_OPS in case of MySQL error
 */
static enum mapistore_error mysql_record_get_fmid(struct indexing_context *ictx,
						  const char *username,
						  const char *uri,
						  bool partial,
						  uint64_t *fmidp,
						  bool *soft_deletedp)
{
	enum MYSQLRESULT	ret;
	char			*sql, *uri_like;
	MYSQL_RES		*res;
	MYSQL_ROW		row;
	TALLOC_CTX		*mem_ctx;

	// Sanity checks
	MAPISTORE_RETVAL_IF(!ictx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
	MAPISTORE_RETVAL_IF(!username, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!uri, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!fmidp, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!soft_deletedp, MAPISTORE_ERR_INVALID_PARAMETER, NULL);

	mem_ctx = talloc_named(NULL, 0, "mysql_record_get_fmid");

	sql = talloc_asprintf(mem_ctx,
		"SELECT fmid, soft_deleted FROM "INDEXING_TABLE" "
		"WHERE username = '******'", _sql(mem_ctx, username));
	if (partial) {
		uri_like = talloc_strdup(mem_ctx, uri);
		string_replace(uri_like, '*', '%');
		sql = talloc_asprintf_append(sql, " AND url LIKE '%s'",
					     _sql(mem_ctx, uri_like));
	} else {
		sql = talloc_asprintf_append(sql, " AND url = '%s'",
					     _sql(mem_ctx, uri));
	}

	ret = select_without_fetch(MYSQL(ictx), sql, &res);
	MAPISTORE_RETVAL_IF(ret == MYSQL_NOT_FOUND, MAPISTORE_ERR_NOT_FOUND, mem_ctx);
	MAPISTORE_RETVAL_IF(ret != MYSQL_SUCCESS, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);

	row = mysql_fetch_row(res);

	*fmidp = strtoull(row[0], NULL, 0);
	*soft_deletedp = strtoull(row[1], NULL, 0) == 1;

	mysql_free_result(res);
	talloc_free(mem_ctx);

	return MAPISTORE_SUCCESS;
}
Ejemplo n.º 7
0
static char *start_main(char *ret, const char *why)
{
	return talloc_asprintf_append(ret,
	      "/* The example %s, so fake function wrapper inserted */\n"
	      "int main(int argc, char *argv[])\n"
	      "{\n", why);
}
Ejemplo n.º 8
0
/**
   \details Build the binding string and flags given profile and
   global options.

   \param mapi_ctx pointer to the MAPI context
   \param mem_ctx pointer to the memory allocation context
   \param server string representing the server FQDN or IP address
   \param profile pointer to the MAPI profile structure

   \return valid allocated string on success, otherwise NULL
 */
static char *build_binding_string(struct mapi_context *mapi_ctx,
                                  TALLOC_CTX *mem_ctx,
                                  const char *server,
                                  struct mapi_profile *profile)
{
    char	*binding;

    /* Sanity Checks */
    if (!profile) return NULL;
    if (!server) return NULL;
    if (!mapi_ctx) return NULL;

    binding = talloc_asprintf(mem_ctx, "ncacn_ip_tcp:%s[", server);

    /* If dump-data option is enabled */
    if (mapi_ctx->dumpdata == true) {
        binding = talloc_strdup_append(binding, "print,");
    }
    /* If seal option is enabled in the profile */
    if (profile->seal == true) {
        binding = talloc_strdup_append(binding, "seal,");
    }
    /* If localaddress parameter is available in the profile */
    if (profile->localaddr) {
        binding = talloc_asprintf_append(binding, "localaddress=%s,", profile->localaddr);
    }

    binding = talloc_strdup_append(binding, "]");

    return binding;
}
Ejemplo n.º 9
0
/*
  encode an ACL in SDDL format
*/
static char *sddl_encode_acl(TALLOC_CTX *mem_ctx, const struct security_acl *acl,
			     uint32_t flags, const struct dom_sid *domain_sid)
{
	char *sddl;
	int i;

	/* add any ACL flags */
	sddl = sddl_flags_to_string(mem_ctx, acl_flags, flags, False);
	if (sddl == NULL) goto failed;

	/* now the ACEs, encoded in braces */
	for (i=0;i<acl->num_aces;i++) {
		char *ace = sddl_encode_ace(sddl, &acl->aces[i], domain_sid);
		if (ace == NULL) goto failed;
		sddl = talloc_asprintf_append(sddl, "(%s)", ace);
		if (sddl == NULL) goto failed;
		talloc_free(ace);
	}

	return sddl;

failed:
	talloc_free(sddl);
	return NULL;
}
Ejemplo n.º 10
0
static const char *
_get_tags_as_string (const void *ctx, notmuch_message_t *message)
{
    notmuch_tags_t *tags;
    int first = 1;
    const char *tag;
    char *result;

    result = talloc_strdup (ctx, "");
    if (result == NULL)
        return NULL;

    for (tags = notmuch_message_get_tags (message);
            notmuch_tags_valid (tags);
            notmuch_tags_move_to_next (tags))
    {
        tag = notmuch_tags_get (tags);

        result = talloc_asprintf_append (result, "%s%s",
                                         first ? "" : " ", tag);
        first = 0;
    }

    return result;
}
Ejemplo n.º 11
0
static char *example_obj_list(struct manifest *m, struct ccan_file *f)
{
	struct manifest **deps = talloc_array(f, struct manifest *, 0);
	char **lines, *list;
	unsigned int i;

	/* This one for a start. */
	add_dep(&deps, m->basename);

	/* Other modules implied by includes. */
	for (lines = get_ccan_file_lines(f); *lines; lines++) {
		unsigned preflen = strspn(*lines, " \t");
		if (strstarts(*lines + preflen, "#include <ccan/")) {
			char *modname;

			modname = talloc_strdup(f, *lines + preflen
						+ strlen("#include <ccan/"));
			modname[strcspn(modname, "/")] = '\0';
			if (!have_mod(deps, modname))
				add_dep(&deps, modname);
		}
	}

	list = talloc_strdup(f, "");
	for (i = 0; i < talloc_get_size(deps) / sizeof(*deps); i++) {
		if (deps[i]->compiled[COMPILE_NORMAL])
			list = talloc_asprintf_append(list, " %s",
						      deps[i]->compiled
						      [COMPILE_NORMAL]);
	}
	return list;
}
Ejemplo n.º 12
0
/* add this to the list, called by the callback */
void listdent_add_dent(TSK_FS_DENT *fs_dent, TSK_FS_DATA *fs_data, struct dentwalk *dentlist) {
    struct dentwalk *p = talloc(dentlist, struct dentwalk);

    p->path = talloc_strndup(p, fs_dent->name, fs_dent->name_max - 1);

    p->type = p->id = 0;
    if(fs_data) {
        p->type = fs_data->type;
        p->id = fs_data->id;
    }

    /* print the data stream name if it exists and is not the default NTFS */
    if ((fs_data) && (((fs_data->type == NTFS_ATYPE_DATA) &&
                       (strcmp(fs_data->name, "$Data") != 0)) ||
                      ((fs_data->type == NTFS_ATYPE_IDXROOT) &&
                       (strcmp(fs_data->name, "$I30") != 0)))) {
        p->path = talloc_asprintf_append(p->path, ":%s", fs_data->name);
    }

    p->alloc = 1; // allocated
    if(fs_dent->flags & TSK_FS_DENT_FLAG_UNALLOC) {
        if((fs_dent->fsi) && (fs_dent->fsi->flags & TSK_FS_INODE_FLAG_ALLOC))
            p->alloc = 2; // realloc
        else
            p->alloc = 0; // unalloc
    }

    p->inode = fs_dent->inode;
    p->ent_type = fs_dent->ent_type;

    list_add_tail(&p->list, &dentlist->list);
}
Ejemplo n.º 13
0
/* Tallocs *output off ctx; return false if command fails. */
bool run_command(const void *ctx, unsigned int *time_ms, char **output,
		 const char *fmt, ...)
{
	va_list ap;
	char *cmd;
	bool ok;
	unsigned int default_time = default_timeout_ms;

	if (!time_ms)
		time_ms = &default_time;
	else if (*time_ms == 0) {
		*output = talloc_strdup(ctx, "\n== TIMED OUT ==\n");
		return false;
	}

	va_start(ap, fmt);
	cmd = talloc_vasprintf(ctx, fmt, ap);
	va_end(ap);

	*output = run_with_timeout(ctx, cmd, &ok, time_ms);
	if (ok)
		return true;
	if (!*output)
		err(1, "Problem running child");
	if (*time_ms == 0)
		*output = talloc_asprintf_append(*output,
						 "\n== TIMED OUT ==\n");
	return false;
}
Ejemplo n.º 14
0
Archivo: osd.c Proyecto: Velvetine/mpv
static char *join_lines(void *ta_ctx, char **parts, int num_parts)
{
    char *res = talloc_strdup(ta_ctx, "");
    for (int n = 0; n < num_parts; n++)
        res = talloc_asprintf_append(res, "%s%s", n ? "\n" : "", parts[n]);
    return res;
}
Ejemplo n.º 15
0
/*
  turn a set of flags into a string
*/
static char *sddl_flags_to_string(TALLOC_CTX *mem_ctx, const struct flag_map *map,
				  uint32_t flags, BOOL check_all)
{
	int i;
	char *s;

	/* try to find an exact match */
	for (i=0;map[i].name;i++) {
		if (map[i].flag == flags) {
			return talloc_strdup(mem_ctx, map[i].name);
		}
	}

	s = talloc_strdup(mem_ctx, "");

	/* now by bits */
	for (i=0;map[i].name;i++) {
		if ((flags & map[i].flag) != 0) {
			s = talloc_asprintf_append(s, "%s", map[i].name);
			if (s == NULL) goto failed;
			flags &= ~map[i].flag;
		}
	}

	if (check_all && flags != 0) {
		goto failed;
	}

	return s;

failed:
	talloc_free(s);
	return NULL;
}
Ejemplo n.º 16
0
static char *connection_string_from_parameters(TALLOC_CTX *mem_ctx, struct namedprops_mysql_params *parms)
{
	char *connection_string;

	connection_string = talloc_asprintf(mem_ctx, "mysql://%s", parms->user);
	if (!connection_string) return NULL;
	if (parms->pass && parms->pass[0]) {
		connection_string = talloc_asprintf_append(connection_string, ":%s", parms->pass);
		if (!connection_string) return NULL;
	}
	connection_string = talloc_asprintf_append(connection_string, "@%s", parms->host);
	if (!connection_string) return NULL;
	if (parms->port) {
		connection_string = talloc_asprintf_append(connection_string, ":%d", parms->port);
		if (!connection_string) return NULL;
	}
	return talloc_asprintf_append(connection_string, "/%s", parms->db);
}
Ejemplo n.º 17
0
WERROR dsdb_subSchema_objectClasses(const struct dsdb_schema *schema,
				    TALLOC_CTX *mem_ctx)
{
	struct ldb_message_element *e;
	struct dsdb_class *c;

	e = talloc_zero(mem_ctx, struct ldb_message_element);
	W_ERROR_HAVE_NO_MEMORY(e);

	for (c = schema->classes; c; c = c->next) {
		const char *class_type;
		char *v;

		switch (c->objectClassCategory) {
		case 0:
			/*
			 * NOTE: this is an type 88 class
			 *       e.g. 2.5.6.6 NAME 'person'
			 *	 but w2k3 gives STRUCTURAL here!
			 */
			class_type = "STRUCTURAL";
			break;
		case 1:
			class_type = "STRUCTURAL";
			break;
		case 2:
			class_type = "ABSTRACT";
			break;
		case 3:
			class_type = "AUXILIARY";
			break;
		default:
			class_type = "UNKNOWN";
			break;
		}

		v = talloc_asprintf(e, "( %s NAME '%s' SUB %s %s ",
				    c->governsID_oid, c->lDAPDisplayName,
				    c->subClassOf, class_type);
		W_ERROR_HAVE_NO_MEMORY(v);

		v = dsdb_subSchema_list_append(v, "MUST");
		W_ERROR_HAVE_NO_MEMORY(v);

		v = dsdb_subSchema_list_append(v, "MAY");
		W_ERROR_HAVE_NO_MEMORY(v);

		v = talloc_asprintf_append(v, ")");
		W_ERROR_HAVE_NO_MEMORY(v);

		DEBUG(0,("%s\n", v));
	}

	return WERR_FOOBAR;
}
Ejemplo n.º 18
0
/*
  turn a node status flags field into a string
*/
static char *node_status_flags(TALLOC_CTX *mem_ctx, uint16_t flags)
{
	char *ret;
	const char *group = "       ";
	const char *type = "B";

	if (flags & NBT_NM_GROUP) {
		group = "<GROUP>";
	}

	switch (flags & NBT_NM_OWNER_TYPE) {
	case NBT_NODE_B: 
		type = "B";
		break;
	case NBT_NODE_P: 
		type = "P";
		break;
	case NBT_NODE_M: 
		type = "M";
		break;
	case NBT_NODE_H: 
		type = "H";
		break;
	}

	ret = talloc_asprintf(mem_ctx, "%s %s", group, type);

	if (flags & NBT_NM_DEREGISTER) {
		ret = talloc_asprintf_append(ret, " <DEREGISTERING>");
	}
	if (flags & NBT_NM_CONFLICT) {
		ret = talloc_asprintf_append(ret, " <CONFLICT>");
	}
	if (flags & NBT_NM_ACTIVE) {
		ret = talloc_asprintf_append(ret, " <ACTIVE>");
	}
	if (flags & NBT_NM_PERMANENT) {
		ret = talloc_asprintf_append(ret, " <PERMANENT>");
	}
	
	return ret;
}
Ejemplo n.º 19
0
static char *obj_list(const struct manifest *m)
{
	char *list = talloc_strdup(m, "");
	struct ccan_file *i;

	/* Objects from all the C files. */
	list_for_each(&m->c_files, i, list)
		list = talloc_asprintf_append(list, "%s ", i->compiled);

	return list;
}
Ejemplo n.º 20
0
/*
  form a binding string from a binding structure
*/
const char *dcerpc_binding_string(TALLOC_CTX *mem_ctx, const struct dcerpc_binding *b)
{
	char *s = talloc_strdup(mem_ctx, "");
	int i;
	const char *t_name=NULL;

	for (i=0;i<ARRAY_SIZE(transports);i++) {
		if (transports[i].transport == b->transport) {
			t_name = transports[i].name;
		}
	}
	if (!t_name) {
		return NULL;
	}

	if (!GUID_all_zero(&b->object.uuid)) { 
		s = talloc_asprintf(s, "%s@",
				    GUID_string(mem_ctx, &b->object.uuid));
	}

	s = talloc_asprintf_append(s, "%s:", t_name);
	if (!s) return NULL;

	if (b->host) {
		s = talloc_asprintf_append(s, "%s", b->host);
	}

	if (!b->endpoint && !b->options && !b->flags) {
		return s;
	}

	s = talloc_asprintf_append(s, "[");

	if (b->endpoint) {
		s = talloc_asprintf_append(s, "%s", b->endpoint);
	}

	/* this is a *really* inefficent way of dealing with strings,
	   but this is rarely called and the strings are always short,
	   so I don't care */
	for (i=0;b->options && b->options[i];i++) {
		s = talloc_asprintf_append(s, ",%s", b->options[i]);
		if (!s) return NULL;
	}

	for (i=0;i<ARRAY_SIZE(ncacn_options);i++) {
		if (b->flags & ncacn_options[i].flag) {
			s = talloc_asprintf_append(s, ",%s", ncacn_options[i].name);
			if (!s) return NULL;
		}
	}

	s = talloc_asprintf_append(s, "]");

	return s;
}
Ejemplo n.º 21
0
/* FIXME: Test with reduced features! */
static char *lib_list(const struct manifest *m)
{
	unsigned int i, num;
	char **libs;
	char *ret = talloc_strdup(m, "");

	libs = get_libs(m, m->dir, &num,
			&m->info_file->compiled[COMPILE_NORMAL]);
	for (i = 0; i < num; i++)
		ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
	return ret;
}
Ejemplo n.º 22
0
/** join a list back to one (shell-like) string; entries
 * seperated by spaces, using quotes where necessary */
_PUBLIC_ char *str_list_join_shell(TALLOC_CTX *mem_ctx, const char **list, char sep)
{
    char *ret = NULL;
    int i;

    if (list[0] == NULL)
        return talloc_strdup(mem_ctx, "");

    if (strchr(list[0], ' ') || strlen(list[0]) == 0)
        ret = talloc_asprintf(mem_ctx, "\"%s\"", list[0]);
    else
        ret = talloc_strdup(mem_ctx, list[0]);

    for (i = 1; list[i]; i++) {
        if (strchr(list[i], ' ') || strlen(list[i]) == 0)
            ret = talloc_asprintf_append(ret, "%c\"%s\"", sep, list[i]);
        else
            ret = talloc_asprintf_append(ret, "%c%s", sep, list[i]);
    }

    return ret;
}
Ejemplo n.º 23
0
/*
  encode a security descriptor to SDDL format
*/
char *sddl_encode(TALLOC_CTX *mem_ctx, const struct security_descriptor *sd,
		  const struct dom_sid *domain_sid)
{
	char *sddl;
	TALLOC_CTX *tmp_ctx;

	/* start with a blank string */
	sddl = talloc_strdup(mem_ctx, "");
	if (sddl == NULL) goto failed;

	tmp_ctx = talloc_new(mem_ctx);

	if (sd->owner_sid != NULL) {
		char *sid = sddl_encode_sid(tmp_ctx, sd->owner_sid, domain_sid);
		if (sid == NULL) goto failed;
		sddl = talloc_asprintf_append(sddl, "O:%s", sid);
		if (sddl == NULL) goto failed;
	}

	if (sd->group_sid != NULL) {
		char *sid = sddl_encode_sid(tmp_ctx, sd->group_sid, domain_sid);
		if (sid == NULL) goto failed;
		sddl = talloc_asprintf_append(sddl, "G:%s", sid);
		if (sddl == NULL) goto failed;
	}

	if ((sd->type & SEC_DESC_DACL_PRESENT) && sd->dacl != NULL) {
		char *acl = sddl_encode_acl(tmp_ctx, sd->dacl, sd->type, domain_sid);
		if (acl == NULL) goto failed;
		sddl = talloc_asprintf_append(sddl, "D:%s", acl);
		if (sddl == NULL) goto failed;
	}

	if ((sd->type & SEC_DESC_SACL_PRESENT) && sd->sacl != NULL) {
		char *acl = sddl_encode_acl(tmp_ctx, sd->sacl, sd->type>>1, domain_sid);
		if (acl == NULL) goto failed;
		sddl = talloc_asprintf_append(sddl, "S:%s", acl);
		if (sddl == NULL) goto failed;
	}
Ejemplo n.º 24
0
Archivo: sub.c Proyecto: hroncok/mpv
static void set_dvdsub_fake_extradata(struct dec_sub *dec_sub, struct stream *st,
                                      int width, int height)
{
    if (!st)
        return;

    struct stream_dvd_info_req info;
    if (stream_control(st, STREAM_CTRL_GET_DVD_INFO, &info) < 0)
        return;

    struct mp_csp_params csp = MP_CSP_PARAMS_DEFAULTS;
    csp.int_bits_in = 8;
    csp.int_bits_out = 8;
    float cmatrix[3][4];
    mp_get_yuv2rgb_coeffs(&csp, cmatrix);

    if (width == 0 || height == 0) {
        width = 720;
        height = 480;
    }

    char *s = NULL;
    s = talloc_asprintf_append(s, "size: %dx%d\n", width, height);
    s = talloc_asprintf_append(s, "palette: ");
    for (int i = 0; i < 16; i++) {
        int color = info.palette[i];
        int c[3] = {(color >> 16) & 0xff, (color >> 8) & 0xff, color & 0xff};
        mp_map_int_color(cmatrix, 8, c);
        color = (c[2] << 16) | (c[1] << 8) | c[0];

        if (i != 0)
            talloc_asprintf_append(s, ", ");
        s = talloc_asprintf_append(s, "%06x", color);
    }
    s = talloc_asprintf_append(s, "\n");

    sub_set_extradata(dec_sub, s, strlen(s));
    talloc_free(s);
}
Ejemplo n.º 25
0
static char *mp_get_playback_resume_config_filename(struct MPContext *mpctx,
                                                    const char *fname)
{
    struct MPOpts *opts = mpctx->opts;
    char *res = NULL;
    void *tmp = talloc_new(NULL);
    const char *realpath = fname;
    bstr bfname = bstr0(fname);
    if (!mp_is_url(bfname)) {
        if (opts->ignore_path_in_watch_later_config) {
            realpath = mp_basename(fname);
        } else {
            char *cwd = mp_getcwd(tmp);
            if (!cwd)
                goto exit;
            realpath = mp_path_join(tmp, cwd, fname);
        }
    }
    if (bstr_startswith0(bfname, "dvd://") && opts->dvd_opts && opts->dvd_opts->device)
        realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->dvd_opts->device);
    if ((bstr_startswith0(bfname, "br://") || bstr_startswith0(bfname, "bd://") ||
         bstr_startswith0(bfname, "bluray://")) && opts->bluray_device)
        realpath = talloc_asprintf(tmp, "%s - %s", realpath, opts->bluray_device);
    uint8_t md5[16];
    av_md5_sum(md5, realpath, strlen(realpath));
    char *conf = talloc_strdup(tmp, "");
    for (int i = 0; i < 16; i++)
        conf = talloc_asprintf_append(conf, "%02X", md5[i]);

    if (!mpctx->cached_watch_later_configdir) {
        char *wl_dir = mpctx->opts->watch_later_directory;
        if (wl_dir && wl_dir[0]) {
            mpctx->cached_watch_later_configdir =
                mp_get_user_path(mpctx, mpctx->global, wl_dir);
        }
    }

    if (!mpctx->cached_watch_later_configdir) {
        mpctx->cached_watch_later_configdir =
            mp_find_user_config_file(mpctx, mpctx->global, MP_WATCH_LATER_CONF);
    }

    if (mpctx->cached_watch_later_configdir)
        res = mp_path_join(NULL, mpctx->cached_watch_later_configdir, conf);

exit:
    talloc_free(tmp);
    return res;
}
Ejemplo n.º 26
0
/**
 * join a list back to one string
 */
_PUBLIC_ char *str_list_join(TALLOC_CTX *mem_ctx, const char **list, char seperator)
{
    char *ret = NULL;
    int i;

    if (list[0] == NULL)
        return talloc_strdup(mem_ctx, "");

    ret = talloc_strdup(mem_ctx, list[0]);

    for (i = 1; list[i]; i++) {
        ret = talloc_asprintf_append(ret, "%c%s", seperator, list[i]);
    }

    return ret;
}
Ejemplo n.º 27
0
static char *openchangedb_table_build_filter(TALLOC_CTX *mem_ctx, struct openchangedb_table *table, uint64_t row_fmid, struct mapi_SRestriction *restrictions)
{
	char		*filter = NULL;
	const char	*PidTagAttr = NULL;

	switch (table->table_type) {
	case 0x3 /* EMSMDBP_TABLE_FAI_TYPE */:
		filter = talloc_asprintf(mem_ctx, "(&(objectClass=faiMessage)(PidTagParentFolderId=%"PRIu64")(PidTagMessageId=", table->folderID);
		break;
	case 0x2 /* EMSMDBP_TABLE_MESSAGE_TYPE */:
		filter = talloc_asprintf(mem_ctx, "(&(objectClass=systemMessage)(PidTagParentFolderId=%"PRIu64")(PidTagMessageId=", table->folderID);
		break;
	case 0x1 /* EMSMDBP_TABLE_FOLDER_TYPE */:
		filter = talloc_asprintf(mem_ctx, "(&(PidTagParentFolderId=%"PRIu64")(PidTagFolderId=", table->folderID);
		break;
	}

	if (row_fmid == 0) {
		filter = talloc_asprintf_append(filter, "*)");
	}
	else {
		filter = talloc_asprintf_append(filter, "%"PRIu64")", row_fmid);
	}

	if (restrictions) {
		switch (restrictions->rt) {
		case RES_PROPERTY:
			/* Retrieve PidTagName */
			PidTagAttr = openchangedb_property_get_attribute(restrictions->res.resProperty.ulPropTag);
			if (!PidTagAttr) {
				talloc_free(filter);
				return NULL;
			}
			filter = talloc_asprintf_append(filter, "(%s=", PidTagAttr);
			switch (restrictions->res.resProperty.ulPropTag & 0xFFFF) {
			case PT_STRING8:
				filter = talloc_asprintf_append(filter, "%s)", restrictions->res.resProperty.lpProp.value.lpszA);
				break;
			case PT_UNICODE:
				filter = talloc_asprintf_append(filter, "%s)", restrictions->res.resProperty.lpProp.value.lpszW);
				break;
			default:
				DEBUG(0, ("Unsupported RES_PROPERTY property type: 0x%.4x\n", (restrictions->res.resProperty.ulPropTag & 0xFFFF)));
				talloc_free(filter);
				return NULL;
			}
		}
	}

	/* Close filter */
	filter = talloc_asprintf_append(filter, ")");

	return filter;
}
Ejemplo n.º 28
0
_PUBLIC_ enum ndr_err_code ndr_pull_ipv6address(struct ndr_pull *ndr, int ndr_flags, const char **address)
{
	uint8_t addr[IPV6_BYTES];
	char *addr_str = talloc_strdup(ndr->current_mem_ctx, "");
	int i;
	NDR_CHECK(ndr_pull_array_uint8(ndr, ndr_flags, addr, IPV6_BYTES));
	for (i = 0; i < IPV6_BYTES; ++i) {
		addr_str = talloc_asprintf_append(addr_str, "%02x", addr[i]);
		/* We need a ':' every second byte but the last one */
		if (i%2 == 1 && i != (IPV6_BYTES - 1)) {
			addr_str = talloc_strdup_append(addr_str, ":");
		}
	}
	*address = addr_str;
	NDR_ERR_HAVE_NO_MEMORY(*address);
	return NDR_ERR_SUCCESS;
}
Ejemplo n.º 29
0
/* We only handle simple function definitions here. */
static char *add_func(char *others, const char *line)
{
	const char *p, *end = strchr(line, '(') - 1;
	while (cisspace(*end)) {
		end--;
		if (end == line)
			return others;
	}

	for (p = end; cisalnum(*p) || *p == '_'; p--) {
		if (p == line)
			return others;
	}

	return talloc_asprintf_append(others, "printf(\"%%p\", %.*s);\n",
				      (unsigned)(end - p), p+1);
}
Ejemplo n.º 30
0
static errno_t
sss_config_set_list(struct sss_config_ctx *ctx,
                    const char *section,
                    const char *option,
                    char **list)
{
    TALLOC_CTX *tmp_ctx = NULL;
    char *value = NULL;
    errno_t ret;
    int i;

    if (list == NULL) {
        return EINVAL;
    }

    tmp_ctx = talloc_new(NULL);
    if (tmp_ctx == NULL) {
        return ENOMEM;
    }

    if (list[0] == NULL) {
        ret = sss_config_rm_option(ctx, section, option);
        goto done;
    }

    value = talloc_strdup(tmp_ctx, list[0]);
    if (value == NULL) {
        ret = ENOMEM;
        goto done;
    }

    for (i = 1; list[i] != NULL; i++) {
        value = talloc_asprintf_append(value, ", %s", list[i]);
        if (value == NULL) {
            ret = ENOMEM;
            goto done;
        }
    }

    ret = sss_config_set_option(ctx, section, option, value);

done:
    talloc_free(tmp_ctx);
    return ret;
}