Add Gnulib modules xstrndup and xvasprintf

This commit is contained in:
wbaumann 2012-01-28 22:38:15 +00:00
parent 6559f12463
commit f1b02bed97
7 changed files with 105 additions and 116 deletions

View File

@ -12,6 +12,7 @@ ChangeLog for davfs2
Check secrets file in check_dirs. Check secrets file in check_dirs.
* all: * all:
Add Gnulib module xalloc. Add Gnulib module xalloc.
Add Gnulib modules xstrndup and xvasprintf.


2012-01-25 Werner Baumann (werner.baumann@onlinehome.de) 2012-01-25 Werner Baumann (werner.baumann@onlinehome.de)
* mount_davfs.c, mount_davfs.h: * mount_davfs.c, mount_davfs.h:

View File

@ -15,7 +15,7 @@




# Specification in the form of a command-line invocation: # Specification in the form of a command-line invocation:
# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=config --po-base=glpo --doc-base=doc --tests-base=tests --aux-dir=config --no-libtool --macro-prefix=gl --po-domain=davfs2 canonicalize iconv_open rpmatch xalloc # gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=config --po-base=glpo --doc-base=doc --tests-base=tests --aux-dir=config --no-libtool --macro-prefix=gl --po-domain=davfs2 canonicalize iconv_open rpmatch xalloc xstrndup xvasprintf


# Specification in the form of a few gnulib-tool.m4 macro invocations: # Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([]) gl_LOCAL_DIR([])
@ -24,6 +24,8 @@ gl_MODULES([
iconv_open iconv_open
rpmatch rpmatch
xalloc xalloc
xstrndup
xvasprintf
]) ])
gl_AVOID([]) gl_AVOID([])
gl_SOURCE_BASE([gl]) gl_SOURCE_BASE([gl])

View File

@ -60,6 +60,8 @@
#include <sys/xattr.h> #include <sys/xattr.h>


#include "xalloc.h" #include "xalloc.h"
#include "xstrndup.h"
#include "xvasprintf.h"


#include <ne_alloc.h> #include <ne_alloc.h>
#include <ne_string.h> #include <ne_string.h>
@ -688,7 +690,7 @@ dav_close_cache(int got_sigterm)


clean_tree(root, !got_sigterm); clean_tree(root, !got_sigterm);


char *new_index = ne_concat(cache_dir, "/", DAV_INDEX, ".new", NULL); char *new_index = xasprintf("%s/%s.new",cache_dir, DAV_INDEX);
if (debug) if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Creating index %s.", syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Creating index %s.",
new_index); new_index);
@ -706,7 +708,7 @@ dav_close_cache(int got_sigterm)
if (debug) if (debug)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG),
"Replacing old index"); "Replacing old index");
char *old_index = ne_concat(cache_dir, "/", DAV_INDEX, NULL); char *old_index = xasprintf("%s/%s", cache_dir, DAV_INDEX);
if (rename(new_index, old_index) != 0) if (rename(new_index, old_index) != 0)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR),
_("can't replace %s with %s"), old_index, new_index); _("can't replace %s with %s"), old_index, new_index);
@ -925,7 +927,7 @@ dav_create(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
return EINVAL; return EINVAL;


char *name_conv = dav_conv_to_server_enc(name); char *name_conv = dav_conv_to_server_enc(name);
char *path = ne_concat(parent->path, name_conv, NULL); char *path = xasprintf("%s%s", parent->path, name_conv);
free(name_conv); free(name_conv);


*nodep = new_node(parent, mode | S_IFREG); *nodep = new_node(parent, mode | S_IFREG);
@ -1102,7 +1104,7 @@ dav_mkdir(dav_node **nodep, dav_node *parent, const char *name, uid_t uid,
return EINVAL; return EINVAL;


char *name_conv = dav_conv_to_server_enc(name); char *name_conv = dav_conv_to_server_enc(name);
char *path = ne_concat(parent->path, name_conv, "/", NULL); char *path = xasprintf("%s%s/", parent->path, name_conv);
free(name_conv); free(name_conv);
int ret = dav_make_collection(path); int ret = dav_make_collection(path);


@ -1859,7 +1861,7 @@ move_dir(dav_node *src, dav_node *dst, dav_node *dst_parent,
char *dst_path; char *dst_path;
if (!dst) { if (!dst) {
char *dst_conv = dav_conv_to_server_enc(dst_name); char *dst_conv = dav_conv_to_server_enc(dst_name);
dst_path = ne_concat(dst_parent->path, dst_conv, "/", NULL); dst_path = xasprintf("%s%s/", dst_parent->path, dst_conv);
free(dst_conv); free(dst_conv);
} else { } else {
dst_path = xstrdup(dst->path); dst_path = xstrdup(dst->path);
@ -1898,7 +1900,7 @@ move_no_remote(dav_node *src, dav_node *dst, dav_node *dst_parent,
char *dst_path; char *dst_path;
if (!dst) { if (!dst) {
char *dst_conv = dav_conv_to_server_enc(dst_name); char *dst_conv = dav_conv_to_server_enc(dst_name);
dst_path = ne_concat(dst_parent->path, dst_conv, NULL); dst_path = xasprintf("%s%s", dst_parent->path, dst_conv);
free(dst_conv); free(dst_conv);
} else { } else {
dst_path = xstrdup(dst->path); dst_path = xstrdup(dst->path);
@ -1968,7 +1970,7 @@ move_reg(dav_node *src, dav_node *dst, dav_node *dst_parent,
char *dst_path; char *dst_path;
if (!dst) { if (!dst) {
char *dst_conv = dav_conv_to_server_enc(dst_name); char *dst_conv = dav_conv_to_server_enc(dst_name);
dst_path = ne_concat(dst_parent->path, dst_conv, NULL); dst_path = xasprintf("%s%s", dst_parent->path, dst_conv);
free(dst_conv); free(dst_conv);
} else { } else {
dst_path = xstrdup(dst->path); dst_path = xstrdup(dst->path);
@ -2399,7 +2401,7 @@ update_path(dav_node *node, const char *src_path, const char *dst_path)
return; return;
} }


char *path = ne_concat(dst_path, node->path + strlen(src_path), NULL); char *path = xasprintf("%s%s", dst_path, node->path + strlen(src_path));
free(node->path); free(node->path);
node->path = path; node->path = path;
} }
@ -2556,7 +2558,7 @@ create_cache_file(dav_node *node)
} }
} }


node->cache_path = ne_concat(cache_dir, "/", node->name, "-XXXXXX", NULL); node->cache_path = xasprintf("%s/%s-XXXXXX", cache_dir, node->name);


int fd = mkstemp(node->cache_path); int fd = mkstemp(node->cache_path);
if (fd <= 0) { if (fd <= 0) {
@ -2590,8 +2592,7 @@ create_dir_cache_file(dav_node *dir)
} }
} }


dir->cache_path = ne_concat(cache_dir, "/dir-", dir->name, "-XXXXXX", dir->cache_path = xasprintf("%s/dir-%s-XXXXXX", cache_dir, dir->name);
NULL);
int fd = mkstemp(dir->cache_path); int fd = mkstemp(dir->cache_path);
if (fd <= 0) { if (fd <= 0) {
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR),
@ -2779,7 +2780,8 @@ check_cache_dir(const char *dir, const char *host, const char *path,
struct passwd *pw = getpwuid(default_uid); struct passwd *pw = getpwuid(default_uid);
if (!pw || !pw->pw_name) if (!pw || !pw->pw_name)
error(EXIT_FAILURE, 0, _("can't read user data base")); error(EXIT_FAILURE, 0, _("can't read user data base"));
char *dir_name = ne_concat(host, path, mpoint + 1, "+", pw->pw_name, NULL); char *dir_name = xasprintf("%s%s%s+%s", host, path, mpoint + 1,
pw->pw_name);
*(dir_name + strlen(host) + strlen(path) - 1) = '+'; *(dir_name + strlen(host) + strlen(path) - 1) = '+';
char *pos = strchr(dir_name, '/'); char *pos = strchr(dir_name, '/');
while (pos) { while (pos) {
@ -2794,7 +2796,7 @@ check_cache_dir(const char *dir, const char *host, const char *path,
struct dirent *de = readdir(tl_dir); struct dirent *de = readdir(tl_dir);
while (de && !cache_dir) { while (de && !cache_dir) {
if (strcmp(de->d_name, dir_name) == 0) { if (strcmp(de->d_name, dir_name) == 0) {
cache_dir = ne_concat(dir, "/", de->d_name, NULL); cache_dir = xasprintf("%s/%s", dir, de->d_name);
} }
de = readdir(tl_dir); de = readdir(tl_dir);
} }
@ -2802,7 +2804,7 @@ check_cache_dir(const char *dir, const char *host, const char *path,
closedir(tl_dir); closedir(tl_dir);


if (!cache_dir) { if (!cache_dir) {
cache_dir = ne_concat(dir, "/", dir_name, NULL); cache_dir = xasprintf("%s/%s", dir, dir_name);
if (mkdir(cache_dir, S_IRWXU) != 0) if (mkdir(cache_dir, S_IRWXU) != 0)
error(EXIT_FAILURE, 0, _("can't create cache directory %s"), error(EXIT_FAILURE, 0, _("can't create cache directory %s"),
cache_dir); cache_dir);
@ -2835,7 +2837,7 @@ clean_cache(void)


if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0 if (strcmp(de->d_name, ".") != 0 && strcmp(de->d_name, "..") != 0
&& strcmp(de->d_name, DAV_INDEX) != 0) { && strcmp(de->d_name, DAV_INDEX) != 0) {
char *path = ne_concat(cache_dir, "/", de->d_name, NULL); char *path = xasprintf("%s/%s", cache_dir, de->d_name);
int i = 0; int i = 0;
dav_node *node = NULL; dav_node *node = NULL;
while (!node && i < table_size) { while (!node && i < table_size) {
@ -2876,7 +2878,7 @@ clean_cache(void)
static void static void
parse_index(void) parse_index(void)
{ {
char *index = ne_concat(cache_dir, "/", DAV_INDEX, NULL); char *index = xasprintf("%s/%s", cache_dir, DAV_INDEX);
FILE *idx = fopen(index, "r"); FILE *idx = fopen(index, "r");
if (!idx) { if (!idx) {
free(index); free(index);
@ -3019,7 +3021,7 @@ write_node(dav_node *node, FILE *file, const char *indent)
return -1; return -1;
} }


char *ind = ne_concat(indent, " ", NULL); char *ind = xasprintf("%s ", indent);


if (node != root && !is_backup(node)) { if (node != root && !is_backup(node)) {
if (fprintf(file, "%s<d:%s><![CDATA[%s]]></d:%s>\n", ind, type[PATH], node->path, if (fprintf(file, "%s<d:%s><![CDATA[%s]]></d:%s>\n", ind, type[PATH], node->path,
@ -3156,10 +3158,10 @@ static int
xml_cdata(void *userdata, int state, const char *cdata, size_t len) xml_cdata(void *userdata, int state, const char *cdata, size_t len)
{ {
if (!xml_data) { if (!xml_data) {
xml_data = ne_strndup(cdata, len); xml_data = xstrndup(cdata, len);
} else { } else {
char *add = ne_strndup(cdata, len); char *add = xstrndup(cdata, len);
char *new = ne_concat(xml_data, add, NULL); char *new = xasprintf("%s%s", xml_data, add);
free(add); free(add);
free(xml_data); free(xml_data);
xml_data = new; xml_data = new;

View File

@ -55,6 +55,7 @@
#endif #endif


#include "xalloc.h" #include "xalloc.h"
#include "xvasprintf.h"


#include "defaults.h" #include "defaults.h"
#include "mount_davfs.h" #include "mount_davfs.h"
@ -155,9 +156,7 @@ init_coda(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata)
*dev = 0; *dev = 0;
int minor = 0; int minor = 0;
while (*dev <= 0 && minor < MAX_CODADEVS) { while (*dev <= 0 && minor < MAX_CODADEVS) {
char *path; char *path = xasprintf("%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME, minor);
if (asprintf(&path, "%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME, minor) < 0)
abort();
*dev = open(path, O_RDWR | O_NONBLOCK); *dev = open(path, O_RDWR | O_NONBLOCK);
free(path); free(path);
++minor; ++minor;
@ -166,10 +165,8 @@ init_coda(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata)
if (*dev <= 0 && system("/sbin/modprobe coda &>/dev/null") == 0) { if (*dev <= 0 && system("/sbin/modprobe coda &>/dev/null") == 0) {
minor = 0; minor = 0;
while (*dev <= 0 && minor < MAX_CODADEVS) { while (*dev <= 0 && minor < MAX_CODADEVS) {
char *path; char *path = xasprintf("%s/%s%i", DAV_DEV_DIR, CODA_DEV_NAME,
if (asprintf(&path, "%s/%s%i", minor);
DAV_DEV_DIR, CODA_DEV_NAME, minor) < 0)
abort();
*dev = open(path, O_RDWR | O_NONBLOCK); *dev = open(path, O_RDWR | O_NONBLOCK);
if (*dev <= 0) { if (*dev <= 0) {
if (mknod(path, S_IFCHR, makedev(CODA_MAJOR, minor)) == 0) { if (mknod(path, S_IFCHR, makedev(CODA_MAJOR, minor)) == 0) {
@ -215,9 +212,7 @@ init_fuse(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata,
size_t *buf_size, const char *url, const char *mpoint, size_t *buf_size, const char *url, const char *mpoint,
unsigned long int mopts, uid_t owner, gid_t group, mode_t mode) unsigned long int mopts, uid_t owner, gid_t group, mode_t mode)
{ {
char *path; char *path = xasprintf("%s/%s", DAV_DEV_DIR, FUSE_DEV_NAME);
if (asprintf(&path, "%s/%s", DAV_DEV_DIR, FUSE_DEV_NAME) < 0)
abort();


*dev = open(path, O_RDWR | O_NONBLOCK); *dev = open(path, O_RDWR | O_NONBLOCK);
if (*dev <= 0 && system("/sbin/modprobe fuse &>/dev/null") == 0) { if (*dev <= 0 && system("/sbin/modprobe fuse &>/dev/null") == 0) {
@ -244,15 +239,13 @@ init_fuse(int *dev, dav_run_msgloop_fn *msg_loop, void **mdata,
} }


#if SIZEOF_VOID_P == 8 #if SIZEOF_VOID_P == 8
if (asprintf((char **) mdata, "fd=%i,rootmode=%o,user_id=%i,group_id=%i," *mdata = xasprintf("fd=%i,rootmode=%o,user_id=%i,group_id=%i,"
"allow_other,max_read=%lu", *dev, mode, owner, group, "allow_other,max_read=%lu", *dev, mode, owner, group,
*buf_size - 4096) < 0) *buf_size - 4096);
abort();
#else #else
if (asprintf((char **) mdata, "fd=%i,rootmode=%o,user_id=%i,group_id=%i," *mdata = xasprintf("fd=%i,rootmode=%o,user_id=%i,group_id=%i,"
"allow_other,max_read=%u", *dev, mode, owner, group, "allow_other,max_read=%u", *dev, mode, owner, group,
*buf_size - 4096) < 0) *buf_size - 4096);
abort();
#endif #endif
if (mount(url, mpoint, "fuse", mopts, *mdata) == 0) { if (mount(url, mpoint, "fuse", mopts, *mdata) == 0) {
*msg_loop = dav_fuse_loop; *msg_loop = dav_fuse_loop;

View File

@ -71,6 +71,8 @@


#include "canonicalize.h" #include "canonicalize.h"
#include "xalloc.h" #include "xalloc.h"
#include "xvasprintf.h"
#include "xstrndup.h"


#include <ne_string.h> #include <ne_string.h>
#include <ne_uri.h> #include <ne_uri.h>
@ -382,7 +384,7 @@ main(int argc, char *argv[])
dav_close_cache(got_sigterm); dav_close_cache(got_sigterm);
dav_close_webdav(); dav_close_webdav();
if (is_mounted()) { if (is_mounted()) {
char *prog = ne_concat("/bin/umount -il ", mpoint, NULL); char *prog = xasprintf("/bin/umount -il %s", mpoint);
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting %s"), mpoint); syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting %s"), mpoint);
if (system(prog) != 0) if (system(prog) != 0)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting failed")); syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_ERR), _("unmounting failed"));
@ -497,7 +499,7 @@ check_dirs(dav_args *args)
} }
release_privileges(args); release_privileges(args);


fname = ne_concat(DAV_SYS_CONF_DIR "/" DAV_SECRETS, NULL); fname = xasprintf("%s/%s", DAV_SYS_CONF_DIR, DAV_SECRETS);
if (stat(fname, &st) == 0) { if (stat(fname, &st) == 0) {
if (st.st_uid != 0) if (st.st_uid != 0)
error(EXIT_FAILURE, 0, _("file %s has wrong owner"), fname); error(EXIT_FAILURE, 0, _("file %s has wrong owner"), fname);
@ -510,46 +512,41 @@ check_dirs(dav_args *args)


if (!args->privileged) { if (!args->privileged) {


char *path = ne_concat(args->home, "/.", PACKAGE, NULL); char *path = xasprintf("%s/.%s", args->home, PACKAGE);
if (stat(path, &st) != 0) if (stat(path, &st) != 0)
mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);


if (stat(path, &st) == 0) { if (stat(path, &st) == 0) {
fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CACHE, NULL); fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CACHE);
if (stat(fname, &st) != 0) if (stat(fname, &st) != 0)
mkdir(fname, S_IRWXU); mkdir(fname, S_IRWXU);
free(fname); free(fname);


fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CERTS_DIR);
NULL);
if (stat(fname, &st) != 0) if (stat(fname, &st) != 0)
mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); mkdir(fname, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
free(fname); free(fname);


fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, fname = xasprintf("%s/.%s/%s/%s", args->home, PACKAGE,
"/", DAV_CLICERTS_DIR, NULL); DAV_CERTS_DIR, DAV_CLICERTS_DIR);
if (stat(fname, &st) != 0) if (stat(fname, &st) != 0)
mkdir(fname, S_IRWXU); mkdir(fname, S_IRWXU);
free(fname); free(fname);


fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CONFIG, NULL); fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CONFIG);
if (stat(fname, &st) != 0) { if (stat(fname, &st) != 0) {
char *template = ne_concat(DAV_DATA_DIR, "/", DAV_CONFIG, NULL); char *template = xasprintf("%s/%s", DAV_DATA_DIR, DAV_CONFIG);
char *command = ne_concat("cp ", template, " ", fname, char *command = xasprintf("cp %s %s", template, fname);
NULL);
if (system(command) != 0); if (system(command) != 0);
free(command); free(command);
free(template); free(template);
} }
free(fname); free(fname);


fname = ne_concat(args->home, "/.", PACKAGE, "/", DAV_SECRETS, fname = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_SECRETS);
NULL);
if (stat(fname, &st) != 0) { if (stat(fname, &st) != 0) {
char *template = ne_concat(DAV_DATA_DIR, "/", DAV_SECRETS, char *template = xasprintf("%s/%s", DAV_DATA_DIR, DAV_SECRETS);
NULL); char *command = xasprintf("cp %s %s", template, fname);
char *command = ne_concat("cp ", template, " ", fname,
NULL);
if (system(command) == 0) if (system(command) == 0)
chmod(fname, S_IRUSR | S_IWUSR); chmod(fname, S_IRUSR | S_IWUSR);
free(command); free(command);
@ -658,8 +655,7 @@ check_double_mounts(dav_args *args)
*m = '-'; *m = '-';
m = strchr(mp, '/'); m = strchr(mp, '/');
} }
char *pidf = NULL; char *pidf = xasprintf("%s/%s.pid", DAV_SYS_RUN, mp);
if (asprintf(&pidf, "%s/%s.pid", DAV_SYS_RUN, mp) < 0) abort();
free(mp); free(mp);
if (args->debug & DAV_DBG_CONFIG) if (args->debug & DAV_DBG_CONFIG)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "PID file: %s", pidf); syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "PID file: %s", pidf);
@ -938,7 +934,7 @@ parse_commandline(dav_args *args, int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 2: case 2:
if (*argv[i] == '\"' || *argv[i] == '\'') { if (*argv[i] == '\"' || *argv[i] == '\'') {
url = ne_strndup(argv[i] + 1, strlen(argv[i]) -2); url = xstrndup(argv[i] + 1, strlen(argv[i]) - 2);
} else { } else {
url = xstrdup(argv[i]); url = xstrdup(argv[i]);
} }
@ -971,8 +967,7 @@ parse_commandline(dav_args *args, int argc, char *argv[])
if (args->conf) { if (args->conf) {
expand_home(&args->conf, args); expand_home(&args->conf, args);
} else if (!args->privileged) { } else if (!args->privileged) {
if (asprintf(&args->conf, "%s/.%s/%s", args->home, PACKAGE, args->conf = xasprintf("%s/.%s/%s", args->home, PACKAGE, DAV_CONFIG);
DAV_CONFIG) < 0) abort();
} }


return args; return args;
@ -1023,8 +1018,8 @@ parse_config(dav_args *args)
if (args->servercert) if (args->servercert)
expand_home(&args->servercert, args); expand_home(&args->servercert, args);
if (args->servercert && *args->servercert != '/' && !args->privileged) { if (args->servercert && *args->servercert != '/' && !args->privileged) {
char *f = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, char *f = xasprintf("%s/.%s/%s/%s", args->home, PACKAGE, DAV_CERTS_DIR,
"/", args->servercert, NULL); args->servercert);
if (access(f, F_OK) == 0) { if (access(f, F_OK) == 0) {
free(args->servercert); free(args->servercert);
args->servercert = f; args->servercert = f;
@ -1033,8 +1028,8 @@ parse_config(dav_args *args)
} }
} }
if (args->servercert && *args->servercert != '/') { if (args->servercert && *args->servercert != '/') {
char *f = ne_concat(DAV_SYS_CONF_DIR, "/", DAV_CERTS_DIR, "/", char *f = xasprintf("%s/%s/%s", DAV_SYS_CONF_DIR, DAV_CERTS_DIR,
args->servercert, NULL); args->servercert);
free(args->servercert); free(args->servercert);
args->servercert = f; args->servercert = f;
} }
@ -1042,23 +1037,22 @@ parse_config(dav_args *args)
if (args->secrets) if (args->secrets)
expand_home(&args->secrets, args); expand_home(&args->secrets, args);
if (!args->privileged && !args->secrets) if (!args->privileged && !args->secrets)
args->secrets = ne_concat(args->home, "/.", PACKAGE, "/", DAV_SECRETS, args->secrets = xasprintf("%s/.%s/%s", args->home, PACKAGE,
NULL); DAV_SECRETS);



if (args->clicert) if (args->clicert)
expand_home(&args->clicert, args); expand_home(&args->clicert, args);
if (args->clicert && *args->clicert != '/' && !args->privileged) { if (args->clicert && *args->clicert != '/' && !args->privileged) {
char *f = ne_concat(args->home, "/.", PACKAGE, "/", DAV_CERTS_DIR, "/", char *f = xasprintf("%s/.%s/%s/%s/%s", args->home, PACKAGE,
DAV_CLICERTS_DIR, "/", args->clicert, NULL); DAV_CERTS_DIR, DAV_CLICERTS_DIR, args->clicert);
if (access(f, F_OK) == 0) { if (access(f, F_OK) == 0) {
free(args->clicert); free(args->clicert);
args->clicert = f; args->clicert = f;
} }
} }
if (args->clicert && *args->clicert != '/' && args->privileged) { if (args->clicert && *args->clicert != '/' && args->privileged) {
char *f = ne_concat(DAV_SYS_CONF_DIR, "/", DAV_CERTS_DIR, "/", char *f = xasprintf("%s/%s/%s/%s", DAV_SYS_CONF_DIR, DAV_CERTS_DIR,
DAV_CLICERTS_DIR, "/", args->clicert, NULL); DAV_CLICERTS_DIR, args->clicert);
free(args->clicert); free(args->clicert);
args->clicert = f; args->clicert = f;
} }
@ -1097,8 +1091,8 @@ parse_config(dav_args *args)
if (args->cache_dir) { if (args->cache_dir) {
expand_home(&args->cache_dir, args); expand_home(&args->cache_dir, args);
} else { } else {
args->cache_dir = ne_concat(args->home, "/.", PACKAGE, "/", args->cache_dir = xasprintf("%s/.%s/%s", args->home, PACKAGE,
DAV_CACHE, NULL); DAV_CACHE);
} }
} }


@ -1287,21 +1281,19 @@ write_mtab_entry(const dav_args *args)
mntent.mnt_fsname = url; mntent.mnt_fsname = url;
mntent.mnt_dir = mpoint; mntent.mnt_dir = mpoint;
mntent.mnt_type = DAV_FS_TYPE; mntent.mnt_type = DAV_FS_TYPE;
mntent.mnt_opts = NULL; mntent.mnt_opts = xasprintf("%s%s%s%s%s%s",
if (asprintf(&mntent.mnt_opts, "%s%s%s%s%s%s",
(args->mopts & MS_RDONLY) ? "ro" : "rw", (args->mopts & MS_RDONLY) ? "ro" : "rw",
(args->mopts & MS_NOSUID) ? ",nosuid" : "", (args->mopts & MS_NOSUID) ? ",nosuid" : "",
(args->mopts & MS_NOEXEC) ? ",noexec" : "", (args->mopts & MS_NOEXEC) ? ",noexec" : "",
(args->mopts & MS_NODEV) ? ",nodev" : "", (args->mopts & MS_NODEV) ? ",nodev" : "",
(args->netdev) ? ",_netdev" : "", (args->netdev) ? ",_netdev" : "",
(args->add_mopts != NULL) ? args->add_mopts : "") < 0) (args->add_mopts != NULL) ? args->add_mopts : "");
abort();
mntent. mnt_freq = 0; mntent. mnt_freq = 0;
mntent. mnt_passno = 0; mntent. mnt_passno = 0;


if (!args->privileged) { if (!args->privileged) {
char *opts = mntent.mnt_opts; char *opts = mntent.mnt_opts;
mntent.mnt_opts = ne_concat(opts, ",user=", args->uid_name, NULL); mntent.mnt_opts = xasprintf("%s,user=%s", opts, args->uid_name);
free(opts); free(opts);
} }


@ -1529,9 +1521,7 @@ expand_home(char **dir, const dav_args *args)
if (*p != '/') if (*p != '/')
return; return;


char *new_dir = NULL; char *new_dir = xasprintf("%s%s", args->home, p);
if (asprintf(&new_dir, "%s%s", args->home, p) < 0)
abort();
free(*dir); free(*dir);
*dir = new_dir; *dir = new_dir;
} }
@ -1638,10 +1628,8 @@ get_options(dav_args *args, char *option)
} else { } else {
args->fsuid = pwd->pw_uid; args->fsuid = pwd->pw_uid;
} }
if (asprintf(&add_mopts, "%s,uid=%i", add_mopts = xasprintf("%s,uid=%i",
(args->add_mopts) ? args->add_mopts : "", (args->add_mopts) ? args->add_mopts : "", args->fsuid);
args->fsuid) < 0)
abort();
if (args->add_mopts) if (args->add_mopts)
free(args->add_mopts); free(args->add_mopts);
args->add_mopts = add_mopts; args->add_mopts = add_mopts;
@ -1654,10 +1642,8 @@ get_options(dav_args *args, char *option)
} else { } else {
args->fsgid = grp->gr_gid; args->fsgid = grp->gr_gid;
} }
if (asprintf(&add_mopts, "%s,gid=%i", add_mopts = xasprintf("%s,gid=%i",
(args->add_mopts) ? args->add_mopts : "", (args->add_mopts) ? args->add_mopts : "", args->fsgid);
args->fsgid) < 0)
abort();
if (args->add_mopts) if (args->add_mopts)
free(args->add_mopts); free(args->add_mopts);
args->add_mopts = add_mopts; args->add_mopts = add_mopts;
@ -2208,11 +2194,14 @@ read_config(dav_args *args, const char * filename, int system)
} else if (applies && count == 3) { } else if (applies && count == 3) {


if (strcmp(parmv[0], "add_header") == 0) { if (strcmp(parmv[0], "add_header") == 0) {
if (args->header) {
char *tmp = args->header; char *tmp = args->header;
args->header = ne_concat(parmv[1], ": ", parmv[2], "\r\n", tmp, args->header = xasprintf("%s: %s\r\n%s", parmv[1],
NULL); parmv[2], tmp);
if (tmp) if (tmp) free(tmp);
free(tmp); } else {
args->header = xasprintf("%s: %s\r\n", parmv[1], parmv[2]);
}
} else { } else {
error_at_line(EXIT_FAILURE, 0, filename, lineno, error_at_line(EXIT_FAILURE, 0, filename, lineno,
_("unknown option")); _("unknown option"));
@ -2258,8 +2247,7 @@ read_no_proxy_list(dav_args *args)


char *host = NULL; char *host = NULL;
if (strchr(np, ':')) { if (strchr(np, ':')) {
if (asprintf(&host, "%s:%d", args->host, args->port) < 0) host = xasprintf("%s:%d", args->host, args->port);
abort();
} else { } else {
host = xstrdup(args->host); host = xstrdup(args->host);
} }
@ -2497,7 +2485,7 @@ split_uri(char **scheme, char **host, int *port,char **path, const char *uri)
} else if (*(pa + strlen(pa) - 1) == '/') { } else if (*(pa + strlen(pa) - 1) == '/') {
*path = xstrdup(pa); *path = xstrdup(pa);
} else { } else {
if (asprintf(path, "%s/", pa) < 1) abort(); *path = xasprintf("%s/", pa);
} }
} }



View File

@ -41,6 +41,7 @@
#endif #endif


#include "xalloc.h" #include "xalloc.h"
#include "xvasprintf.h"


#include <ne_string.h> #include <ne_string.h>


@ -140,14 +141,14 @@ main(int argc, char *argv[])
*m = '-'; *m = '-';
m = strchr(mp, '/'); m = strchr(mp, '/');
} }
char *pidfile = ne_concat(DAV_SYS_RUN, "/", mp, ".pid", NULL); char *pidfile = xasprintf("%s/%s.pid", DAV_SYS_RUN, mp);
free(mp); free(mp);


char *umount_command = ne_concat("umount -i '", mpoint, "'", NULL); char *umount_command = xasprintf("umount -i '%s'", mpoint);


char *pid = NULL; char pid[32];
FILE *file = fopen(pidfile, "r"); FILE *file = fopen(pidfile, "r");
if (!file || fscanf(file, "%a[0-9]", &pid) != 1 || !pid) { if (!file || fscanf(file, "%30[0-9]", pid) != 1 || !pid) {
error(0, 0, error(0, 0,
_("\n" _("\n"
" can't read PID from file %s;\n" " can't read PID from file %s;\n"
@ -157,7 +158,7 @@ main(int argc, char *argv[])
} }
fclose(file); fclose(file);


char *ps_command = ne_concat("ps -p ", pid, NULL); char *ps_command = xasprintf("ps -p %s", pid);
FILE *ps_in = popen(ps_command, "r"); FILE *ps_in = popen(ps_command, "r");
if (!ps_in) { if (!ps_in) {
error(0, 0, error(0, 0,

View File

@ -57,6 +57,8 @@
#endif #endif


#include "xalloc.h" #include "xalloc.h"
#include "xstrndup.h"
#include "xvasprintf.h"


#include <ne_alloc.h> #include <ne_alloc.h>
#include <ne_auth.h> #include <ne_auth.h>
@ -377,7 +379,7 @@ dav_init_webdav(const dav_args *args)
ne_set_connect_timeout(session, args->connect_timeout); ne_set_connect_timeout(session, args->connect_timeout);
#endif /* NE_VERSION_MINOR > 26 */ #endif /* NE_VERSION_MINOR > 26 */


char *useragent = ne_concat(PACKAGE_TARNAME, "/", PACKAGE_VERSION, NULL); char *useragent = xasprintf("%s/%s", PACKAGE_TARNAME, PACKAGE_VERSION);
ne_set_useragent(session, useragent); ne_set_useragent(session, useragent);
free(useragent); free(useragent);


@ -1278,7 +1280,7 @@ convert(char **s, iconv_t conv)
&& insize == 0 && outsize >= MB_LEN_MAX) { && insize == 0 && outsize >= MB_LEN_MAX) {
memset(out, 0, MB_LEN_MAX); memset(out, 0, MB_LEN_MAX);
free(*s); free(*s);
*s = ne_strndup(buf, out - buf + MB_LEN_MAX); *s = xstrndup(buf, out - buf + MB_LEN_MAX);
} }


free(buf); free(buf);
@ -1551,11 +1553,11 @@ replace_slashes(char **name)
char *nn; char *nn;
*slash = '\0'; *slash = '\0';
if (slash == *name) { if (slash == *name) {
nn = ne_concat("slash-", slash + 1, NULL); nn = xasprintf("slash-%s", slash + 1);
} else if (slash == end) { } else if (slash == end) {
nn = ne_concat(*name, "-slash", NULL); nn = xasprintf("%s-slash", *name);
} else { } else {
nn = ne_concat(*name, "-slash-", slash + 1, NULL); nn = xasprintf("%s-slash-%s", *name, slash + 1);
} }
free(*name); free(*name);
*name = nn; *name = nn;
@ -1776,7 +1778,7 @@ prop_result(void *userdata, const ne_uri *uri, const ne_prop_result_set *set)
*(result->path + strlen(result->path) - 1) = '\0'; *(result->path + strlen(result->path) - 1) = '\0';
} else { } else {
if (result->is_dir) { if (result->is_dir) {
char *tmp = ne_concat(result->path, "/", NULL); char *tmp = xasprintf("%s/", result->path);
free(result->path); free(result->path);
result->path = tmp; result->path = tmp;
} }
@ -2056,7 +2058,7 @@ update_cookie(ne_request *req, void *userdata, const ne_status *status)
} }


char *value = ne_strndup(cookie_hdr, sep - cookie_hdr + 1); char *value = ne_strndup(cookie_hdr, sep - cookie_hdr + 1);
cookie = ne_concat("Cookie: $Version=1;", value, "\r\n", NULL); cookie = xasprintf("Cookie: $Version=1;%s\r\n", value);
free(value); free(value);


ne_hook_pre_send(session, add_header, cookie); ne_hook_pre_send(session, add_header, cookie);