#include "migrate.h"
#include "../lib/tdb/include/tdb.h"
#include "../lib/tdb/common/tdb_private.h"
-#include "../lib/talloc/talloc.h"
#include "../lib/util/debug.h"
#include "popt.h"
if (asprintf(&cache_path, "%s/%s", ppath, CACHE_DIR_NAME) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc cache_path\n"));
- ret = -1;
+ ret = -ENOMEM;
goto finished;
}
}
-int lookup_attribute_in_parent(TALLOC_CTX *mem_ctx, const char *path, struct stat *st)
+int lookup_attribute_in_parent(const char *path, struct stat *st)
{
+ char *ppath = NULL;
int cache_fd = -1;
struct cached_dir_entry cache_dirent;
char *sptr;
int ret = 0;
- sptr = talloc_strdup(mem_ctx, path);
- if (sptr == NULL) {
+ ppath = strdup(path);
+ if (ppath == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " failed to strdup ppath\n"));
ret = -1;
goto finished;
}
- sptr = rindex(sptr, '/');
+ sptr = rindex(ppath, '/');
if (sptr == NULL) {
ret = -1;
goto finished;
if (cache_fd) {
close(cache_fd);
}
+ if (ppath != NULL) {
+ free(ppath);
+ }
errno = 0;
return ret;
}
char *cache_path = NULL;
struct stat old_st;
struct stat cache_st;
- int ret;
+ int ret = 0;
if (file_check_parent_mtime) {
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
/* try to get the attributes from the parents cache
(if the parents cache is "current"
*/
- ret = lookup_attribute_in_parent(mem_ctx, path, &old_st);
- talloc_free(mem_ctx);
+ ret = lookup_attribute_in_parent(path, &old_st);
if (ret != -1) {
- DEBUG(DEBUG_DEBUG, (__location__ " GETATTR:[%s] from parent cache\n", path));
+ DEBUG(DEBUG_DEBUG, (__location__ " GETATTR:[%s] from parent cache\n", path));
+ ret = 0;
goto finished;
}
}
*/
if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
goto finished;
}
if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
goto finished;
}
*/
if (asprintf(&cache_path, "%s/%s", cache, path) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc cache path\n"));
+ ret = -ENOMEM;
goto finished;
}
static int remote_cache_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
int ret;
char *new_path = NULL;
char *old_path = NULL;
struct flock lock;
struct statvfs vfs;
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
- cache_path = talloc_asprintf(mem_ctx, "%s/%s/%s", cache, path, CACHE_DIR_NAME);
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&cache_path, "%s/%s/%s", cache, path, CACHE_DIR_NAME) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc cache_path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+
DEBUG(DEBUG_DEBUG, (__location__ " READDIR %s\n", path));
errno = 0;
while ((dirent = readdir(dir)) != NULL) {
- talloc_free(obj_path);
- obj_path = NULL;
+ if (obj_path != NULL) {
+ free(obj_path);
+ obj_path = NULL;
+ }
if (strlen(dirent->d_name) > MAX_NAME_LEN) {
DEBUG(DEBUG_ERR, (__location__ " Too long name : %s. skipping entry for %s\n",
memcpy(&cache_dirent.filename[0],dirent->d_name, strlen(dirent->d_name)+1);
- obj_path = talloc_asprintf(mem_ctx, "%s/%s", old_path, dirent->d_name);
+ if (asprintf(&obj_path, "%s/%s", old_path, dirent->d_name) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc obj path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
ret = lstat(obj_path, &cache_dirent.st);
if (ret != 0) {
if (dir) {
closedir(dir);
}
-
- talloc_free(mem_ctx);
+ if (obj_path != NULL) {
+ free(obj_path);
+ }
+ if (cache_path != NULL) {
+ free(cache_path);
+ }
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_statfs(const char *path, struct statvfs *buf)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *old_path = NULL;
int ret;
-//qqq DEBUG(DEBUG_DEBUG, (__location__ " STATFS called\n"));
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ DEBUG(DEBUG_DEBUG, (__location__ " STATFS called\n"));
+
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old_path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
ret = statvfs(old_path, buf);
if (ret == -1) {
ret = -errno;
}
finished:
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
return ret;
}
static int remote_cache_readlink(const char *path, char *buf, size_t len)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *old_path = NULL;
ssize_t lsize;
int ret = 0;
DEBUG(DEBUG_DEBUG, (__location__ " READLINK %s len:%d\n", path, (int)len));
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old_path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
lsize = readlink(old_path, buf, len);
if (lsize == -1) {
ret = -errno;
}
finished:
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
return ret;
}
static int remote_cache_access(const char *path, int mask)
{
int ret;
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *old_path = NULL;
struct stat old_st;
gid_t my_gid;
}
}
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old_path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
bzero(&old_st, sizeof(old_st));
ret = lstat(old_path, &old_st);
}
finished:
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
return ret;
}
-int create_parent_directories(TALLOC_CTX *mem_ctx, char *old_path, char *new_path)
+int create_parent_directories(char *old_path, char *new_path)
{
- char *old_dir, *new_dir, *p;
+ char *old_dir = NULL;
+ char *new_dir = NULL;
+ char *p;
struct stat st;
int ret, len;
- old_dir = talloc_strdup(mem_ctx, old_path);
+ old_dir = strdup(old_path);
+ if (old_dir == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " failed to allocate old_dir\n"));
+ ret = -1;
+ goto finished;
+ }
p = rindex(old_dir, '/');
if (p == NULL) {
- return -1;
+ ret = -1;
+ goto finished;
}
*p = 0;
len = strlen(old_dir);
}
}
- new_dir = talloc_strdup(mem_ctx, new_path);
+ new_dir = strdup(new_path);
+ if (new_dir == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " failed to allocate new_dir\n"));
+ ret = -1;
+ goto finished;
+ }
p = rindex(new_dir, '/');
*p = 0;
len = strlen(new_dir);
bzero(&st, sizeof(st));
ret = lstat(new_dir, &st);
if ((ret == -1) && (errno == ENOENT)) {
- if (create_parent_directories(mem_ctx, old_dir, new_dir) != 0) {
- return -1;
+ if (create_parent_directories(old_dir, new_dir) != 0) {
+ ret = -1;
+ goto finished;
}
ret = lstat(old_dir, &st);
if (ret == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to stat remote directory %s\n", old_dir));
- return -1;
+ ret = -1;
+ goto finished;
}
DEBUG(DEBUG_DEBUG,("Must create parent directory %s\n", new_dir));
mkdir(new_dir, 0);
if (chown(new_dir, st.st_uid, st.st_gid) == -1) {
DEBUG(DEBUG_ERR, ("CHOWN for new directory %s failed with %s\n", new_dir, strerror(errno)));
- return -1;
+ ret = -1;
+ goto finished;
}
if (chmod(new_dir, st.st_mode) == -1) {
DEBUG(DEBUG_ERR, ("CHMOD for new directory %s failed with %s\n", new_dir, strerror(errno)));
- unlink(new_dir);
- return -1;
+ unlink(new_dir);
+ ret = -1;
+ goto finished;
}
}
- return 0;
+
+ ret = 0;
+
+finished:
+ if (old_dir != NULL) {
+ free(old_dir);
+ }
+ if (new_dir != NULL) {
+ free(new_dir);
+ }
+ return ret;
}
int mark_file_for_migration(const char *path)
{
- TALLOC_CTX *mem_ctx = NULL;
TDB_DATA hdrkey, pathkey, data;
- struct migrate_header *mh;
- struct migrate_entry *me;
+ struct migrate_header *mh = NULL;
+ struct migrate_entry *me = NULL;
int ret = 0;
DEBUG(DEBUG_DEBUG,("Marking file %s for migration\n", path));
}
}
- mem_ctx = talloc_new(NULL);
-
/* get the header */
hdrkey.dptr = (uint8_t *)discard_const(MIGRATE_HEADER_KEY);
hdrkey.dsize = strlen(MIGRATE_HEADER_KEY);
data = tdb_fetch(migrate_db, hdrkey);
if (data.dptr == NULL) {
- mh = talloc(mem_ctx, struct migrate_header);
+ mh = malloc(sizeof(struct migrate_header));
if (mh == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to allocate new mh structure\n"));
- ret = -1;
+ ret = -ENOMEM;
goto finished;
}
mh->first = 0;
mh->last = 0;
mh->max = MIGRATE_MAX;
} else {
- mh = talloc_memdup(mem_ctx, data.dptr, data.dsize);
- free(data.dptr);
+ mh = malloc(data.dsize);
if (mh == NULL) {
+ free(data.dptr);
DEBUG(DEBUG_ERR,(__location__ " Failed to allocate copy mh structure\n"));
- ret = -1;
+ ret = -ENOMEM;
goto finished;
}
+ memcpy(mh, data.dptr, data.dsize);
+ free(data.dptr);
}
mh->last = (mh->last + 1)%mh->max;
/* store the new path. we use the chainlock on the header record
as our lock to the database */
data.dsize = offsetof(struct migrate_entry, path) + strlen(path);
- me = talloc_size(mem_ctx, data.dsize);
+ me = malloc(data.dsize);
if (me == NULL) {
DEBUG(DEBUG_ERR,(__location__ " Failed to allocate path data\n"));
- ret = -1;
+ ret = -ENOMEM;
goto finished;
}
data.dptr = (uint8_t *)me;
finished:
tdb_unlockall(migrate_db);
- talloc_free(mem_ctx);
+ if (mh != NULL) {
+ free(mh);
+ }
+ if (me != NULL) {
+ free(me);
+ }
return ret;
}
-static int migrate_small_file_immed(TALLOC_CTX *mem_ctx, char *old_path, char *new_path, struct stat *st)
+static int migrate_small_file_immed(char *old_path, char *new_path, struct stat *st)
{
+ char *new_tmppath = NULL;
+ char *buf = NULL;
int ret = 0;
int ofd = -1;
int nfd = -1;
struct utimbuf times;
- char *buf;
- char *new_tmppath;
struct flock lock;
int has_lock = 0;
DEBUG(DEBUG_DEBUG,("MIGRATE_SMALL_FILE_IMMED(%s %s)\n", old_path, new_path));
- new_tmppath = talloc_asprintf(mem_ctx, "%s ... TMP_RC", new_path);
+ if (asprintf(&new_tmppath, "%s ... TMP_RC", new_path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new_tmppath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
if (st->st_size == 0) {
ret = -ENOMEM;
goto finished;
}
- buf = talloc_size(mem_ctx, st->st_size);
+ buf = malloc(st->st_size);
if (buf == NULL) {
- DEBUG(DEBUG_ERR,(__location__ " Failed to talloc %d bytes\n", (int)st->st_size));
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc %d bytes\n", (int)st->st_size));
ret = -ENOMEM;
goto finished;
}
if ((has_lock != 0) && (ret != 0)) {
unlink(new_tmppath);
}
+ if (new_tmppath != NULL) {
+ free(new_tmppath);
+ }
+ if (buf != NULL) {
+ free(buf);
+ }
return ret;
}
static int remote_cache_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi)
{
- TALLOC_CTX *mem_ctx;
char *new_path = NULL;
char *old_path = NULL;
struct stat cache_st;
if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
goto finished;
}
if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
goto finished;
}
* This can only be used when files are created/deleted but never
* modified.
*/
- mem_ctx = talloc_new(NULL);
- ret = lookup_attribute_in_parent(mem_ctx, path, &cache_st);
- talloc_free(mem_ctx);
+ ret = lookup_attribute_in_parent(path, &cache_st);
if (ret == -1) {
DEBUG(DEBUG_ERR, (__location__ " READ: %s not found in parent cache\n", path));
goto read_from_remote_site;
* in one go
*/
if (old_st.st_size <= file_migrate_small_file) {
- mem_ctx = talloc_new(NULL);
- ret = migrate_small_file_immed(mem_ctx, old_path, new_path, &old_st);
- talloc_free(mem_ctx);
+ ret = migrate_small_file_immed(old_path, new_path, &old_st);
if (ret == 0) {
DEBUG(DEBUG_DEBUG,("migrate_small_file_immed() successful reread from cache\n"));
goto read_from_local_cache;
static int remote_cache_mknod(const char *path, mode_t mode, dev_t rdev)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " MKNOD:%s mode:%o rdev:%x\n", path, (int)mode, (int)rdev));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_mkdir(const char *path, mode_t mode)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
+ }
+
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
DEBUG(DEBUG_DEBUG, (__location__ " MKDIR:%s mode:%o\n", path, (int)mode));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_rmdir(const char *path)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " RMDIR:%s\n", path));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_unlink(const char *path)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
char *old_ppath = NULL;
int perms;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- ppath = talloc_strdup(mem_ctx, path);
+ ppath = strdup(path);
+ if (ppath == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " failed to strdup ppath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
sptr = rindex(ppath, '/');
if (sptr == NULL) {
ret = -EACCES;
ret = -EACCES;
goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
- old_ppath = talloc_asprintf(mem_ctx, "%s/%s", remote, ppath);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_ppath, "%s/%s", remote, ppath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old ppath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " UNLINK:%s\n", path));
unlink_object(new_path);
unlink_parent_dir_cache(new_path);
finished:
- talloc_free(mem_ctx);
+ if (ppath != NULL) {
+ free(ppath);
+ }
+ if (old_ppath != NULL) {
+ free(old_ppath);
+ }
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_chmod(const char *path, mode_t mode)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " CHMOD:%s mode:%o\n", path, mode));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_chown(const char *path, uid_t uid, gid_t gid)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " CHOWN:%s uid %d gid %d\n", path, uid, gid));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_create(const char *path, mode_t mode, struct fuse_file_info *fi)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
char *old_ppath = NULL;
int perms;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- ppath = talloc_strdup(mem_ctx, path);
+ ppath = strdup(path);
+ if (ppath == NULL) {
+ DEBUG(DEBUG_ERR,(__location__ " failed to strdup ppath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
sptr = rindex(ppath, '/');
if (sptr == NULL) {
ret = -EACCES;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
- old_ppath = talloc_asprintf(mem_ctx, "%s/%s", remote, ppath);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_ppath, "%s/%s", remote, ppath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old ppath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " CREATE %s mode %o\n", path, mode));
#endif
finished:
- talloc_free(mem_ctx);
+ if (ppath != NULL) {
+ free(ppath);
+ }
+ if (old_ppath != NULL) {
+ free(old_ppath);
+ }
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_utime(const char *path, struct utimbuf *times)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " UTIME %s\n", path));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_write_internal(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *ffi)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int fd = -1;
gid_t gid = fuse_get_context()->gid;
struct group_list gl;
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
ret = get_group_list(uid, &gl);
if (ret != 0) {
if (fd != -1) {
close(fd);
}
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_truncate(const char *path, off_t offset)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " TRUNCATE %s offset %d\n", path, (int)offset));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_ftruncate(const char *path, off_t offset, struct fuse_file_info *fi)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " FTRUNCATE %s offset %d\n", path, (int)offset));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_link(const char *path, const char *newpath)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
char *new_newpath = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
- new_newpath= talloc_asprintf(mem_ctx, "%s/%s", cache, newpath);
- old_newpath= talloc_asprintf(mem_ctx, "%s/%s", remote, newpath);
-
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_newpath, "%s/%s", cache, newpath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new newpath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_newpath, "%s/%s", remote, newpath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old newpath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " LINK %s -> %s\n", path, newpath));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
+ if (old_newpath != NULL) {
+ free(old_newpath);
+ }
+ if (new_newpath != NULL) {
+ free(new_newpath);
+ }
return ret;
}
static int remote_cache_symlink(const char *linkname, const char *path)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
- char *new_newpath = NULL;
- char *old_newpath = NULL;
+ char *new_path = NULL;
+ char *old_path = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
}
- new_newpath= talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_newpath= talloc_asprintf(mem_ctx, "%s/%s", remote, path);
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
DEBUG(DEBUG_DEBUG, (__location__ " SYMLINK %s -> %s\n", linkname, path));
goto finished;
}
- ret = symlink(linkname, old_newpath);
+ ret = symlink(linkname, old_path);
if (ret != 0) {
- DEBUG(DEBUG_DEBUG,(__location__ " SYMLINK %s -> %s failed with errno:%u\n", linkname, old_newpath, errno));
+ DEBUG(DEBUG_DEBUG,(__location__ " SYMLINK %s -> %s failed with errno:%u\n", linkname, old_path, errno));
ret = -errno;
goto finished;
}
entries for this name
*/
switch_back_to_root();
- unlink_object(new_newpath);
- unlink_parent_dir_cache(new_newpath);
+ unlink_object(new_path);
+ unlink_parent_dir_cache(new_path);
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
return ret;
}
static int remote_cache_rename(const char *path, const char *newpath)
{
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
char *new_path = NULL;
char *old_path = NULL;
char *new_newpath = NULL;
int ret;
if (!read_write) {
- talloc_free(mem_ctx);
- return -EROFS;
+ ret = -EROFS;
+ goto finished;
+ }
+
+ if (asprintf(&new_path, "%s/%s", cache, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_path, "%s/%s", remote, path) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old path\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&new_newpath, "%s/%s", cache, newpath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc new newpath\n"));
+ ret = -ENOMEM;
+ goto finished;
+ }
+ if (asprintf(&old_newpath, "%s/%s", remote, newpath) == -1) {
+ DEBUG(DEBUG_ERR,(__location__ " Failed to malloc old newpath\n"));
+ ret = -ENOMEM;
+ goto finished;
}
- new_path = talloc_asprintf(mem_ctx, "%s/%s", cache, path);
- old_path = talloc_asprintf(mem_ctx, "%s/%s", remote, path);
- new_newpath= talloc_asprintf(mem_ctx, "%s/%s", cache, newpath);
- old_newpath= talloc_asprintf(mem_ctx, "%s/%s", remote, newpath);
DEBUG(DEBUG_DEBUG, (__location__ " RENAME %s -> %s\n", path, newpath));
finished:
switch_back_to_root();
- talloc_free(mem_ctx);
+ if (old_path != NULL) {
+ free(old_path);
+ }
+ if (new_path != NULL) {
+ free(new_path);
+ }
+ if (old_newpath != NULL) {
+ free(old_newpath);
+ }
+ if (new_newpath != NULL) {
+ free(new_newpath);
+ }
return ret;
}