1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

s3: use directory_create_or_exist_strict() to create corepath

This simplifies the code and even works in testenv where the chown call
fails.

Signed-off-by: Gregor Beck <gbeck@sernet.de>
Reviewed-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
This commit is contained in:
Gregor Beck 2013-04-22 13:33:00 +02:00 committed by Michael Adam
parent dfff01910b
commit ae6a13eecb

View File

@ -43,34 +43,35 @@ static char *corepath;
*/
static char *get_default_corepath(const char *logbase, const char *progname)
{
const mode_t mode = 0700;
const uid_t uid = getuid();
char *tmp_corepath;
/* Setup core dir in logbase. */
tmp_corepath = talloc_asprintf(NULL, "%s/cores", logbase);
if (!tmp_corepath)
if (!tmp_corepath) {
DEBUG(0, ("Out of memory\n"));
return NULL;
}
if ((mkdir(tmp_corepath, 0700) == -1) && errno != EEXIST)
if (!directory_create_or_exist_strict(tmp_corepath, uid, mode)) {
DEBUG(0, ("Failed to create %s for user %d with mode 0%o\n",
tmp_corepath, (int)uid, (int)mode));
goto err_out;
if (chmod(tmp_corepath, 0700) == -1)
goto err_out;
talloc_free(tmp_corepath);
}
/* Setup progname-specific core subdir */
tmp_corepath = talloc_asprintf(NULL, "%s/cores/%s", logbase, progname);
if (!tmp_corepath)
return NULL;
if (mkdir(tmp_corepath, 0700) == -1 && errno != EEXIST)
tmp_corepath = talloc_asprintf_append(tmp_corepath, "/%s", progname);
if (!tmp_corepath) {
DEBUG(0, ("Out of memory\n"));
goto err_out;
}
if (chown(tmp_corepath, getuid(), getgid()) == -1)
goto err_out;
if (chmod(tmp_corepath, 0700) == -1)
if (!directory_create_or_exist(tmp_corepath, uid, mode)) {
DEBUG(0, ("Failed to create %s for user %d with mode 0%o\n",
tmp_corepath, (int)uid, (int)mode));
goto err_out;
}
return tmp_corepath;