コード例 #1
0
ファイル: smbcontrol.c プロジェクト: gojdic/samba
static bool do_winbind_online(struct messaging_context *msg_ctx,
			      const struct server_id pid,
			     const int argc, const char **argv)
{
	TDB_CONTEXT *tdb;

	if (argc != 1) {
		fprintf(stderr, "Usage: smbcontrol winbindd online\n");
		return False;
	}

	/* Remove the entry in the winbindd_cache tdb to tell a later
	   starting winbindd that we're online. */

	tdb = tdb_open_log(cache_path("winbindd_cache.tdb"), 0, TDB_DEFAULT, O_RDWR, 0600);
	if (!tdb) {
		fprintf(stderr, "Cannot open the tdb %s for writing.\n",
			cache_path("winbindd_cache.tdb"));
		return False;
	}

	tdb_delete_bystring(tdb, "WINBINDD_OFFLINE");
	tdb_close(tdb);

	return send_message(msg_ctx, pid, MSG_WINBIND_ONLINE, NULL, 0);
}
コード例 #2
0
ファイル: login_cache.c プロジェクト: Alexander--/samba
bool login_cache_init(void)
{
	char* cache_fname = NULL;

	/* skip file open if it's already opened */
	if (cache) return True;

	cache_fname = cache_path(LOGIN_CACHE_FILE);
	if (cache_fname == NULL) {
		DEBUG(0, ("Filename allocation failed.\n"));
		return False;
	}

	DEBUG(5, ("Opening cache file at %s\n", cache_fname));

	cache = tdb_open_log(cache_fname, 0, TDB_DEFAULT,
	                     O_RDWR|O_CREAT, 0644);

	if (!cache)
		DEBUG(5, ("Attempt to open %s failed.\n", cache_fname));

	TALLOC_FREE(cache_fname);

	return (cache ? True : False);
}
コード例 #3
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static bool
cache_file_valid(struct file *f)
{
  char *cp;
  int result;
  struct stat st;

  if(!cache_valid(f))
    return false;

  if(!cache_file_exists(f))
    return false;

  cp = cache_path(f);
  result = stat(cp, &st);
  free(cp);

  if(result != 0)
    return false;

  if(f->st->st_mtime > st.st_mtime)
    return false;

  return true;
}
コード例 #4
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
stormfs_truncate(const char *path, off_t size)
{
  int fd;
  int result;
  struct stat st;
  struct file *f;

  DEBUG("truncate: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if((result = stormfs_getattr(path, &st)) != 0)
    return -result;

  f = cache_get(path);
  if(cache_file_valid(f)) {
    char *cp = cache_path(f);
    if((result = truncate(cp, size)) != 0)
      perror("truncate");
    free(cp);
  } else {
    fd = cache_create_file(f);
    close(fd);
  }

  pthread_mutex_lock(&f->lock);
  f->st->st_size = get_blocks(size);
  cache_touch(f);
  pthread_mutex_unlock(&f->lock);

  return 0;
}
コード例 #5
0
void file_finder::add_path (const bf::path& path)
{
    m_paths.push_back (path);
    if (m_cache_auto)
	cache_path (path);
    else
	m_cache_updated = false;
}
コード例 #6
0
void file_finder::build_cache (bool autoupdate)
{
    if (!m_cache_updated) {
	m_cache_updated = true;
	m_cache_auto = autoupdate;
	for (path_list::iterator it = m_paths.begin(); it != m_paths.end(); ++it)
	    cache_path (*it);
    }
}
コード例 #7
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static bool
cache_file_exists(struct file *f)
{
  int result;
  struct stat st;
  char *cp = cache_path(f);

  result = stat(cp, &st);
  free(cp);

  return (result == 0) ? true : false;
}
コード例 #8
0
ファイル: environment.cpp プロジェクト: sodabrew/rubinius
  void Environment::set_codedb_paths() {
    if(config.codedb_core_path.value.size() == 0) {
      config.codedb_core_path.value.assign(system_prefix() + RBX_CODEDB_PATH);
    }

    std::string cache_path(config.codedb_cache_path.value);

    expand_config_value(cache_path, "$TMPDIR", config.tmp_path);
    expand_config_value(cache_path, "$PROGRAM_NAME", RBX_PROGRAM_NAME);
    expand_config_value(cache_path, "$USER", shared->username.c_str());

    config.codedb_cache_path.value.assign(cache_path);
  }
コード例 #9
0
ファイル: samlogon_cache.c プロジェクト: samba-team/samba
bool netsamlogon_cache_init(void)
{
    bool first_try = true;
    char *path = NULL;
    int ret;
    struct tdb_context *tdb;

    if (netsamlogon_tdb) {
        return true;
    }

    path = cache_path(NETSAMLOGON_TDB);
    if (path == NULL) {
        return false;
    }
again:
    tdb = tdb_open_log(path, 0, TDB_DEFAULT|TDB_INCOMPATIBLE_HASH,
                       O_RDWR | O_CREAT, 0600);
    if (tdb == NULL) {
        DEBUG(0,("tdb_open_log('%s') - failed\n", path));
        goto clear;
    }

    ret = tdb_check(tdb, NULL, NULL);
    if (ret != 0) {
        tdb_close(tdb);
        DEBUG(0,("tdb_check('%s') - failed\n", path));
        goto clear;
    }

    netsamlogon_tdb = tdb;
    talloc_free(path);
    return true;

clear:
    if (!first_try) {
        talloc_free(path);
        return false;
    }
    first_try = false;

    DEBUG(0,("retry after truncate for '%s'\n", path));
    ret = truncate(path, 0);
    if (ret == -1) {
        DBG_ERR("truncate failed: %s\n", strerror(errno));
        talloc_free(path);
        return false;
    }

    goto again;
}
コード例 #10
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
stormfs_open(const char *path, struct fuse_file_info *fi)
{
  FILE *fp;
  int fd;
  int result;
  struct file *f;

  DEBUG("open: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if(fi->flags & O_TRUNC)
    if((result = stormfs_truncate(path, 0)) != 0)
      return result;

  f = cache_get(path);
  if(cache_file_valid(f)) {
    char *cp = cache_path(f);

    fp = fopen(cp, "a+");
    free(cp);

    if(fp == NULL)
      return -errno;
    if((fd = fileno(fp)) == -1)
      return -errno;

    fi->fh = fd;

    return 0;
  }

  // file not available in cache, download it.
  if((fd = cache_create_file(f)) == -1)
    return -1; // FIXME: need to return proper errors here.
  if((fp = fdopen(fd, "a+")) == NULL)
    return -errno;

  if((result = proxy_open(path, fp)) != 0) {
    fclose(fp);
    return result;
  }

  fi->fh = fd;

  return result;
}
コード例 #11
0
ファイル: registry.c プロジェクト: Arkhont/samba
static NTSTATUS registry_process_group_policy(ADS_STRUCT *ads,
					      TALLOC_CTX *mem_ctx,
					      uint32_t flags,
					      struct registry_key *root_key,
					      const struct security_token *token,
					      struct GROUP_POLICY_OBJECT *gpo,
					      const char *extension_guid,
					      const char *snapin_guid)
{
	NTSTATUS status;
	WERROR werr;
	struct gp_registry_entry *entries = NULL;
	size_t num_entries = 0;
	char *unix_path = NULL;

	debug_gpext_header(0, "registry_process_group_policy", flags, gpo,
			   extension_guid, snapin_guid);

	status = gpo_get_unix_path(mem_ctx, cache_path(GPO_CACHE_DIR), gpo, &unix_path);
	NT_STATUS_NOT_OK_RETURN(status);

	status = reg_parse_registry(mem_ctx,
				    flags,
				    unix_path,
				    &entries,
				    &num_entries);
	if (!NT_STATUS_IS_OK(status)) {
		DEBUG(0,("failed to parse registry: %s\n",
			nt_errstr(status)));
		return status;
	}

	dump_reg_entries(flags, "READ", entries, num_entries);

	werr = reg_apply_registry(mem_ctx, token, root_key, flags,
				  entries, num_entries);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0,("failed to apply registry: %s\n",
			win_errstr(werr)));
		return werror_to_ntstatus(werr);
	}

	return NT_STATUS_OK;
}
コード例 #12
0
ファイル: conflict.c プロジェクト: rmartinjak/discofs
int delete_or_backup(const char *path, int keep)
{
    int res;
    char *p, *confp;
    char *dest;

    /* get old path */
    p = (keep == CONFLICT_KEEP_REMOTE) ? cache_path(path) : remote_path(path);

    /* get new path (or NULL if no bprefix/bsuffix set) */
    dest = conflict_path(p);

    if (dest)
    {
        /* move to backup filename instead of deleting */
        /* rename */
        res = rename(p, dest);
        free(dest);

        /* schedule push/pull for new file */
        if (!res)
        {
            confp = conflict_path(path);
            if (keep == CONFLICT_KEEP_REMOTE)
                job_schedule_push(confp);
            else
                job_schedule_pull(confp);
            free(confp);
        }
    }
    /* no backup prefix or suffix set -> just delete */
    else
    {
        if (is_dir(path))
            res = rmdir_rec(p);
        else
            res = unlink(p);
    }

    free(p);
    return res;
}
コード例 #13
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
cache_mknod(struct file *f, mode_t mode, dev_t rdev)
{
  int result;
  char *cp;

  cp = cache_path(f);
  if((result = cache_mkpath(cp)) != 0)
    return result;

  unlink(cp);

  result = mknod(cp, mode, rdev);
  if(result == -1)
    perror("mknod");

  free(cp);

  return result;
}
コード例 #14
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
cache_create_file(struct file *f)
{
  int result;
  char *cp;

  cp = cache_path(f);
  if((result = cache_mkpath(cp)) != 0)
    return result;

  unlink(cp);

  result = open(cp, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
  if(result == -1)
    perror("open");

  free(cp);

  return result;
}
コード例 #15
0
ファイル: transfer.c プロジェクト: rmartinjak/discofs
static int transfer_pull_dir(const char *path)
{
    int res;
    char *pr, *pc;

    if (!strcmp(path, "/"))
        return -1;

    pr = remote_path(path);
    pc = cache_path(path);

    if (!pr || !pc)
    {
        free(pr);
        free(pc);
        return -1;
    }

    res = clone_dir(pr, pc);

    if (res && errno == ENOENT)
    {
        int res2;
        char *parent = dirname_r(path);

        if (parent)
        {
            res2 = transfer_pull_dir(parent);
            free(parent);

            if (!res2)
                res = clone_dir(pr, pc);
        }
    }

    free(pr);
    free(pc);

    return res;
}
コード例 #16
0
ファイル: util.c プロジェクト: wangd/dmapd
void
cache_store (const gchar *db_dir, const gchar *uri, GByteArray *blob)
{
        struct stat st;
        gchar *cachepath = NULL;
        GError *error = NULL;
        /* NOTE: g_stat seemed broken; would corrupt GError *error. */
        if (stat (db_dir, &st) != 0) {
                g_warning ("cache directory %s does not exist, will not cache", db_dir);
		goto _done;
        }
        if (! (st.st_mode & S_IFDIR)) {
                g_warning ("%s is not a directory, will not cache", db_dir);
		goto _done;
        }
        cachepath = cache_path (CACHE_TYPE_RECORD, db_dir, uri);
	if (NULL == cachepath) {
		goto _done;
	}

        g_file_set_contents (cachepath,
			    (gchar *) blob->data,
			     blob->len,
			     &error);
        if (error != NULL) {
                g_warning ("Error writing %s: %s", cachepath, error->message);
		goto _done;
        }

_done:
	if (NULL != cachepath) {
		g_free (cachepath);
	}

	return;
}
コード例 #17
0
ファイル: stormfs.c プロジェクト: JeremyOT/stormfs
static int
stormfs_readlink(const char *path, char *buf, size_t size)
{
  int fd;
  FILE *fp = NULL;
  int result;
  struct stat st;
  struct file *f;

  DEBUG("readlink: %s\n", path);

  if((result = valid_path(path)) != 0)
    return result;

  if(size <= 0)
    return 0;

  --size; // save the null byte

  f = cache_get(path);
  if(cache_file_valid(f)) {
    char *cp = cache_path(f);

    fp = fopen(cp, "a+");
    free(cp);

    if(fp == NULL)
      return -errno;
    if((fd = fileno(fp)) == -1)
      return -errno;
  } else {
    // file not available in cache, download it.
    if((fd = cache_create_file(f)) == -1)
      return -EIO;
    if((fp = fdopen(fd, "a+")) == NULL)
      return -errno;

    if((result = proxy_open(path, fp)) != 0) {
      fclose(fp);
      return result;
    }
  }

  if(fstat(fd, &st) != 0) {
    close(fd);
    return -errno;
  }

  if(st.st_size < (off_t) size)
    size = st.st_size;

  if(pread(fd, buf, size, 0) == -1) {
    close(fd);
    return -errno;
  }

  buf[size] = 0;
  if(close(fd) != 0)
    return -errno;

  return 0;
}
コード例 #18
0
ファイル: util-gst.c プロジェクト: wangd/dmapd
/* NOTE: This is here and not in the individual DMAPRecords because records
 * have no knowledge of the database, db_dir, etc.
 */
void
transcode_cache (gpointer id, DAAPRecord *record, db_dir_and_target_transcode_mimetype_t *df)
{
	struct stat statbuf;
	gboolean has_video = FALSE;
	gchar *location = NULL;
	gchar *format = NULL;
	gchar *cacheuri = NULL;
	gchar *cachepath = NULL;
	guint64 filesize;

	g_assert (df->db_dir);
	g_assert (df->target_transcode_mimetype);

	g_object_get (record,
		     "location",
		     &location,
		      "format",
		     &format,
		     "has-video",
		     &has_video,
		      NULL);

	if (! (location && format)) {
		g_warning ("Error reading record properties for transcoding");
		goto _return;
	}

	gchar *format2 = dmap_mime_to_format (df->target_transcode_mimetype);
	if (NULL == format2) {
		g_warning ("Cannot transcode %s\n", df->target_transcode_mimetype);
		goto _return;
	}

	if (! strcmp (format, format2)) {
		g_debug ("Transcoding not necessary %s", location);
		goto _return;
	}

	cachepath = cache_path (CACHE_TYPE_TRANSCODED_DATA, df->db_dir, location);
	if (NULL == cachepath) {
		g_warning ("Could not determine cache path.");
		goto _return;
	}

	if (! g_file_test (cachepath, G_FILE_TEST_EXISTS)) {
		/* FIXME: return value, not void: */
		g_debug ("Transcoding %s to %s", location, cachepath);
		do_transcode (record, cachepath, df->target_transcode_mimetype);
	} else {
		g_debug ("Found transcoded data at %s for %s", cachepath, location);
	}

	if (-1 == stat (cachepath, &statbuf)) {
		g_warning ("Could not determine size of transcoded file.");
		goto _return;
	}
	filesize = statbuf.st_size;

	/* Replace previous location with URI to transcoded file. */
	cacheuri = g_filename_to_uri(cachepath, NULL, NULL);
	if (NULL == cacheuri) {
		g_warning ("Could not convert %s to URI.\n", cachepath);
		goto _return;
	}

	g_object_set (record, "location", cacheuri,
	                      "format",   format2,
	                      "filesize", filesize,
	                       NULL);

_return:
	if (location) {
		g_free (location);
	}
	if (format) {
		g_free (format);
	}
	if (cacheuri) {
		g_free (cacheuri);
	}
	if (cachepath) {
		g_free (cachepath);
	}
	if (format2) {
		g_free (format2);
	}

	return;
}
コード例 #19
0
ファイル: profile.c プロジェクト: abartlet/samba-old
/*******************************************************************
  open the profiling shared memory area
  ******************************************************************/
bool profile_setup(struct messaging_context *msg_ctx, bool rdonly)
{
	unsigned char tmp[16] = {};
	MD5_CTX md5;
	char *db_name;

	if (smbprofile_state.internal.db != NULL) {
		return true;
	}

	db_name = cache_path("smbprofile.tdb");
	if (db_name == NULL) {
		return false;
	}

	smbprofile_state.internal.db = tdb_wrap_open(
		NULL, db_name, 0,
		rdonly ? 0 : TDB_CLEAR_IF_FIRST|TDB_MUTEX_LOCKING,
		O_CREAT | (rdonly ? O_RDONLY : O_RDWR), 0644);
	if (smbprofile_state.internal.db == NULL) {
		return false;
	}

	if (msg_ctx != NULL) {
		messaging_register(msg_ctx, NULL, MSG_PROFILE,
				   profile_message);
		messaging_register(msg_ctx, NULL, MSG_REQ_PROFILELEVEL,
				   reqprofile_message);
	}

	MD5Init(&md5);

	MD5Update(&md5,
		  (const uint8_t *)&smbprofile_state.stats.global,
		  sizeof(smbprofile_state.stats.global));

#define __UPDATE(str) do { \
	MD5Update(&md5, (const uint8_t *)str, strlen(str)); \
} while(0)
#define SMBPROFILE_STATS_START
#define SMBPROFILE_STATS_SECTION_START(name, display) do { \
	__UPDATE(#name "+" #display); \
} while(0);
#define SMBPROFILE_STATS_COUNT(name) do { \
	__UPDATE(#name "+count"); \
} while(0);
#define SMBPROFILE_STATS_TIME(name) do { \
	__UPDATE(#name "+time"); \
} while(0);
#define SMBPROFILE_STATS_BASIC(name) do { \
	__UPDATE(#name "+count"); \
	__UPDATE(#name "+time"); \
} while(0);
#define SMBPROFILE_STATS_BYTES(name) do { \
	__UPDATE(#name "+count"); \
	__UPDATE(#name "+time"); \
	__UPDATE(#name "+idle"); \
	__UPDATE(#name "+bytes"); \
} while(0);
#define SMBPROFILE_STATS_IOBYTES(name) do { \
	__UPDATE(#name "+count"); \
	__UPDATE(#name "+time"); \
	__UPDATE(#name "+idle"); \
	__UPDATE(#name "+inbytes"); \
	__UPDATE(#name "+outbytes"); \
} while(0);
#define SMBPROFILE_STATS_SECTION_END
#define SMBPROFILE_STATS_END
	SMBPROFILE_STATS_ALL_SECTIONS
#undef __UPDATE
#undef SMBPROFILE_STATS_START
#undef SMBPROFILE_STATS_SECTION_START
#undef SMBPROFILE_STATS_COUNT
#undef SMBPROFILE_STATS_TIME
#undef SMBPROFILE_STATS_BASIC
#undef SMBPROFILE_STATS_BYTES
#undef SMBPROFILE_STATS_IOBYTES
#undef SMBPROFILE_STATS_SECTION_END
#undef SMBPROFILE_STATS_END

	MD5Final(tmp, &md5);

	profile_p = &smbprofile_state.stats.global;

	profile_p->magic = BVAL(tmp, 0);
	if (profile_p->magic == 0) {
		profile_p->magic = BVAL(tmp, 8);
	}

	return True;
}
コード例 #20
0
ファイル: printing_db.c プロジェクト: Alexander--/samba
			p = print_db_head;
		}
	}

	if (!p)	{
		/* Create one. */
		p = SMB_MALLOC_P(struct tdb_print_db);
		if (!p) {
			DEBUG(0,("get_print_db: malloc fail !\n"));
			return NULL;
		}
		ZERO_STRUCTP(p);
		DLIST_ADD(print_db_head, p);
	}

	print_cache_path = cache_path("printing/");
	if (print_cache_path == NULL) {
		DLIST_REMOVE(print_db_head, p);
		SAFE_FREE(p);
		return NULL;
	}
	ret = asprintf(&printdb_path, "%s%s.tdb",
		       print_cache_path, printername);
	TALLOC_FREE(print_cache_path);
	if (ret < 0) {
		DLIST_REMOVE(print_db_head, p);
		SAFE_FREE(p);
		return NULL;
	}

	if (geteuid() != sec_initial_uid()) {
コード例 #21
0
ファイル: scripts.c プロジェクト: Arkhont/samba
static NTSTATUS scripts_process_group_policy(ADS_STRUCT *ads,
					     TALLOC_CTX *mem_ctx,
					     uint32_t flags,
					     struct registry_key *root_key,
					     const struct security_token *token,
					     struct GROUP_POLICY_OBJECT *gpo,
					     const char *extension_guid,
					     const char *snapin_guid)
{
	NTSTATUS status;
	WERROR werr;
	int i = 0;
	char *unix_path = NULL;
	struct gp_inifile_context *ini_ctx = NULL;
	struct gp_registry_entry *entries = NULL;
	size_t num_entries = 0;
	const char *list[] = {
		GP_SCRIPTS_INI_STARTUP,
		GP_SCRIPTS_INI_SHUTDOWN,
		GP_SCRIPTS_INI_LOGON,
		GP_SCRIPTS_INI_LOGOFF
	};

	debug_gpext_header(0, "scripts_process_group_policy", flags, gpo,
			   extension_guid, snapin_guid);

	status = gpo_get_unix_path(mem_ctx, cache_path(GPO_CACHE_DIR), gpo, &unix_path);
	NT_STATUS_NOT_OK_RETURN(status);

	status = gp_inifile_init_context(mem_ctx, flags, unix_path,
					 GP_SCRIPTS_INI, &ini_ctx);
	NT_STATUS_NOT_OK_RETURN(status);

	for (i = 0; i < ARRAY_SIZE(list); i++) {

		TALLOC_FREE(entries);
		num_entries = 0;

		status = scripts_parse_ini_section(ini_ctx, flags, list[i],
						   &entries, &num_entries);
		if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
			continue;
		}

		if (!NT_STATUS_IS_OK(status)) {
			return status;
		}

		dump_reg_entries(flags, "READ", entries, num_entries);

		werr = scripts_apply(ini_ctx->mem_ctx, token, root_key,
				     flags, list[i], gpo, entries, num_entries);
		if (!W_ERROR_IS_OK(werr)) {
			continue; /* FIXME: finally fix storing emtpy strings and REG_QWORD! */
			TALLOC_FREE(ini_ctx);
			return werror_to_ntstatus(werr);
		}
	}

	TALLOC_FREE(ini_ctx);
	return NT_STATUS_OK;
}
コード例 #22
0
ファイル: smbcontrol.c プロジェクト: gojdic/samba
static bool do_winbind_offline(struct messaging_context *msg_ctx,
			       const struct server_id pid,
			     const int argc, const char **argv)
{
	TDB_CONTEXT *tdb;
	bool ret = False;
	int retry = 0;

	if (argc != 1) {
		fprintf(stderr, "Usage: smbcontrol winbindd offline\n");
		return False;
	}

	/* Create an entry in the winbindd_cache tdb to tell a later
	   starting winbindd that we're offline. We may actually create
	   it here... */

	tdb = tdb_open_log(cache_path("winbindd_cache.tdb"),
				WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE,
				TDB_DEFAULT /* TDB_CLEAR_IF_FIRST */, O_RDWR|O_CREAT, 0600);

	if (!tdb) {
		fprintf(stderr, "Cannot open the tdb %s for writing.\n",
			cache_path("winbindd_cache.tdb"));
		return False;
	}

	/* There's a potential race condition that if a child
	   winbindd detects a domain is online at the same time
	   we're trying to tell it to go offline that it might 
	   delete the record we add between us adding it and
	   sending the message. Minimize this by retrying up to
	   5 times. */

	for (retry = 0; retry < 5; retry++) {
		TDB_DATA d;
		uint8 buf[4];

		ZERO_STRUCT(d);

		SIVAL(buf, 0, time(NULL));
		d.dptr = buf;
		d.dsize = 4;

		tdb_store_bystring(tdb, "WINBINDD_OFFLINE", d, TDB_INSERT);

		ret = send_message(msg_ctx, pid, MSG_WINBIND_OFFLINE,
				   NULL, 0);

		/* Check that the entry "WINBINDD_OFFLINE" still exists. */
		d = tdb_fetch_bystring( tdb, "WINBINDD_OFFLINE" );
	
		if (!d.dptr || d.dsize != 4) {
			SAFE_FREE(d.dptr);
			DEBUG(10,("do_winbind_offline: offline state not set - retrying.\n"));
		} else {
			SAFE_FREE(d.dptr);
			break;
		}
	}

	tdb_close(tdb);
	return ret;
}
コード例 #23
0
ファイル: scripts.c プロジェクト: samba-team/samba
static NTSTATUS scripts_process_group_policy(TALLOC_CTX *mem_ctx,
					     uint32_t flags,
					     struct registry_key *root_key,
					     const struct security_token *token,
					     const struct GROUP_POLICY_OBJECT *deleted_gpo_list,
					     const struct GROUP_POLICY_OBJECT *changed_gpo_list)
{
	NTSTATUS status;
	WERROR werr;
	int i = 0;
	char *unix_path = NULL;
	struct gp_inifile_context *ini_ctx = NULL;
	struct gp_registry_entry *entries = NULL;
	size_t num_entries = 0;
	const char *list[] = {
		GP_SCRIPTS_INI_STARTUP,
		GP_SCRIPTS_INI_SHUTDOWN,
		GP_SCRIPTS_INI_LOGON,
		GP_SCRIPTS_INI_LOGOFF
	};
	const struct GROUP_POLICY_OBJECT *gpo;
	char *gpo_cache_path = cache_path(GPO_CACHE_DIR);
	if (gpo_cache_path == NULL) {
		return NT_STATUS_NO_MEMORY;
	}

	/* implementation of the policy callback function, see
	 * http://msdn.microsoft.com/en-us/library/aa373494%28v=vs.85%29.aspx
	 * for details - gd */

	/* for now do not process the list of deleted group policies

	for (gpo = deleted_gpo_list; gpo; gpo = gpo->next) {
	}

	*/

	for (gpo = changed_gpo_list; gpo; gpo = gpo->next) {

		gpext_debug_header(0, "scripts_process_group_policy", flags,
				   gpo, GP_EXT_GUID_SCRIPTS, NULL);

		status = gpo_get_unix_path(mem_ctx, gpo_cache_path,
					   gpo, &unix_path);
		if (!NT_STATUS_IS_OK(status)) {
			goto err_cache_path_free;
		}

		status = gp_inifile_init_context(mem_ctx, flags, unix_path,
						 GP_SCRIPTS_INI, &ini_ctx);
		if (!NT_STATUS_IS_OK(status)) {
			goto err_cache_path_free;
		}

		for (i = 0; i < ARRAY_SIZE(list); i++) {

			TALLOC_FREE(entries);
			num_entries = 0;

			status = scripts_parse_ini_section(ini_ctx, flags, list[i],
							   &entries, &num_entries);
			if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
				continue;
			}

			if (!NT_STATUS_IS_OK(status)) {
				TALLOC_FREE(ini_ctx);
				goto err_cache_path_free;
			}

			dump_reg_entries(flags, "READ", entries, num_entries);

			werr = scripts_apply(ini_ctx->mem_ctx, token, root_key,
					     flags, list[i], gpo, entries, num_entries);
			if (!W_ERROR_IS_OK(werr)) {
				continue; /* FIXME: finally fix storing emtpy strings and REG_QWORD! */
			}
		}

		TALLOC_FREE(ini_ctx);
	}
	status = NT_STATUS_OK;

err_cache_path_free:
	talloc_free(gpo_cache_path);
	return status;
}