* lib/tcbfuncs.c: Re-indent.

This commit is contained in:
nekral-guest
2010-03-18 00:06:33 +00:00
parent 29025e40f4
commit d1f5c949a9
2 changed files with 236 additions and 176 deletions

View File

@@ -22,6 +22,7 @@
stored_tcb_user.
* lib/tcbfuncs.c: Avoid implicit int to mode_t conversion.
* lib/tcbfuncs.c: Added brackets and parenthesis.
* lib/tcbfuncs.c: Re-indent.
2010-03-17 Nicolas François <nicolas.francois@centraliens.net>

View File

@@ -43,20 +43,22 @@
static /*@null@*//*@only@*/char *stored_tcb_user = NULL;
shadowtcb_status shadowtcb_drop_priv()
shadowtcb_status shadowtcb_drop_priv (void)
{
if (!getdef_bool ("USE_TCB")) {
return SHADOWTCB_SUCCESS;
}
if (stored_tcb_user) {
return (tcb_drop_priv(stored_tcb_user) == 0) ? SHADOWTCB_SUCCESS : SHADOWTCB_FAILURE;
if (NULL != stored_tcb_user) {
if (tcb_drop_priv (stored_tcb_user) == 0) {
return SHADOWTCB_SUCCESS;
}
}
return SHADOWTCB_FAILURE;
}
shadowtcb_status shadowtcb_gain_priv()
shadowtcb_status shadowtcb_gain_priv (void)
{
if (!getdef_bool ("USE_TCB")) {
return SHADOWTCB_SUCCESS;
@@ -85,7 +87,8 @@ static /*@null@*/ char *shadowtcb_path_rel(const char *name, uid_t uid)
return NULL;
}
} else if (uid < SHADOWTCB_HASH_BY * SHADOWTCB_HASH_BY) {
if (asprintf(&ret, ":%dK/%s", uid / SHADOWTCB_HASH_BY, name) == -1) {
if (asprintf (&ret, ":%dK/%s",
uid / SHADOWTCB_HASH_BY, name) == -1) {
OUT_OF_MEMORY;
return NULL;
}
@@ -113,7 +116,9 @@ static /*@null@*/ char *shadowtcb_path_rel_existing(const char *name)
return NULL;
}
if (lstat (path, &st) != 0) {
fprintf(stderr, _("%s: Cannot stat %s: %s\n"), Prog, path, strerror(errno));
fprintf (stderr,
_("%s: Cannot stat %s: %s\n"),
Prog, path, strerror (errno));
free (path);
return NULL;
}
@@ -127,20 +132,26 @@ static /*@null@*/ char *shadowtcb_path_rel_existing(const char *name)
return rval;
}
if (!S_ISLNK (st.st_mode)) {
fprintf(stderr, _("%s: %s is neither a directory, nor a symlink.\n"), Prog, path);
fprintf (stderr,
_("%s: %s is neither a directory, nor a symlink.\n"),
Prog, path);
free (path);
return NULL;
}
ret = readlink (path, link, sizeof (link) - 1);
if (ret == -1) {
fprintf(stderr, _("%s: Cannot read symbolic link %s: %s\n"), Prog, path, strerror(errno));
fprintf (stderr,
_("%s: Cannot read symbolic link %s: %s\n"),
Prog, path, strerror (errno));
free (path);
return NULL;
}
free (path);
if ((size_t)ret >= sizeof(link) - 1) {
link[sizeof(link) - 1] = '\0';
fprintf(stderr, _("%s: Suspiciously long symlink: %s\n"), Prog, link);
fprintf (stderr,
_("%s: Suspiciously long symlink: %s\n"),
Prog, link);
return NULL;
}
link[(size_t)ret] = '\0';
@@ -196,7 +207,9 @@ static shadowtcb_status mkdir_leading(const char *name, uid_t uid)
}
ptr = path;
if (stat (TCB_DIR, &st) != 0) {
fprintf(stderr, _("%s: Cannot stat %s: %s\n"), Prog, TCB_DIR, strerror(errno));
fprintf (stderr,
_("%s: Cannot stat %s: %s\n"),
Prog, TCB_DIR, strerror (errno));
goto out_free_path;
}
while ((ind = strchr (ptr, '/'))) {
@@ -206,15 +219,21 @@ static shadowtcb_status mkdir_leading(const char *name, uid_t uid)
return SHADOWTCB_FAILURE;
}
if ((mkdir (dir, 0700) != 0) && (errno != EEXIST)) {
fprintf(stderr, _("%s: Cannot create directory %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot create directory %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free_dir;
}
if (chown (dir, 0, st.st_gid) != 0) {
fprintf(stderr, _("%s: Cannot change owner of %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owner of %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free_dir;
}
if (chmod (dir, 0711) != 0) {
fprintf(stderr, _("%s: Cannot change mode of %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change mode of %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free_dir;
}
free (dir);
@@ -242,7 +261,9 @@ static shadowtcb_status unlink_suffs(const char *user)
return SHADOWTCB_FAILURE;
}
if ((unlink (tmp) != 0) && (errno != ENOENT)) {
fprintf(stderr, _("%s: unlink: %s: %s\n"), Prog, tmp, strerror(errno));
fprintf (stderr,
_("%s: unlink: %s: %s\n"),
Prog, tmp, strerror (errno));
free (tmp);
return SHADOWTCB_FAILURE;
}
@@ -265,7 +286,9 @@ static shadowtcb_status rmdir_leading(char *path)
}
if (rmdir (dir) != 0) {
if (errno != ENOTEMPTY) {
fprintf(stderr, _("%s: Cannot remove directory %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot remove directory %s: %s\n"),
Prog, dir, strerror (errno));
ret = SHADOWTCB_FAILURE;
}
free (dir);
@@ -292,7 +315,9 @@ static shadowtcb_status move_dir(const char *user_newname, uid_t user_newid)
goto out_free_nomem;
}
if (stat (olddir, &oldmode) != 0) {
fprintf(stderr, _("%s: Cannot stat %s: %s\n"), Prog, olddir, strerror(errno));
fprintf (stderr,
_("%s: Cannot stat %s: %s\n"),
Prog, olddir, strerror (errno));
goto out_free;
}
old_uid = oldmode.st_uid;
@@ -317,14 +342,18 @@ static shadowtcb_status move_dir(const char *user_newname, uid_t user_newid)
goto out_free;
}
if (rename (real_old_dir, real_new_dir) != 0) {
fprintf(stderr, _("%s: Cannot rename %s to %s: %s\n"), Prog, real_old_dir, real_new_dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot rename %s to %s: %s\n"),
Prog, real_old_dir, real_new_dir, strerror (errno));
goto out_free;
}
if (rmdir_leading (real_old_dir_rel) == SHADOWTCB_FAILURE) {
goto out_free;
}
if ((unlink (olddir) != 0) && (errno != ENOENT)) {
fprintf(stderr, _("%s: Cannot remove %s: %s\n"), Prog, olddir, strerror(errno));
fprintf (stderr,
_("%s: Cannot remove %s: %s\n"),
Prog, olddir, strerror (errno));
goto out_free;
}
if (asprintf (&newdir, TCB_DIR "/%s", user_newname) == -1) {
@@ -336,7 +365,9 @@ static shadowtcb_status move_dir(const char *user_newname, uid_t user_newid)
}
if ( (strcmp (real_new_dir, newdir) != 0)
&& (symlink (real_new_dir_rel, newdir) != 0)) {
fprintf(stderr, _("%s: Cannot create symbolic link %s: %s\n"), Prog, real_new_dir_rel, strerror(errno));
fprintf (stderr,
_("%s: Cannot create symbolic link %s: %s\n"),
Prog, real_new_dir_rel, strerror (errno));
goto out_free;
}
ret = SHADOWTCB_SUCCESS;
@@ -433,20 +464,28 @@ shadowtcb_status shadowtcb_move(/*@NULL@*/const char *user_newname, uid_t user_n
return SHADOWTCB_FAILURE;
}
if (stat (tcbdir, &dirmode) != 0) {
fprintf(stderr, _("%s: Cannot stat %s: %s\n"), Prog, tcbdir, strerror(errno));
fprintf (stderr,
_("%s: Cannot stat %s: %s\n"),
Prog, tcbdir, strerror (errno));
goto out_free;
}
if (chown (tcbdir, 0, 0) != 0) {
fprintf(stderr, _("%s: Cannot change owners of %s: %s\n"), Prog, tcbdir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owners of %s: %s\n"),
Prog, tcbdir, strerror (errno));
goto out_free;
}
if (chmod (tcbdir, 0700) != 0) {
fprintf(stderr, _("%s: Cannot change mode of %s: %s\n"), Prog, tcbdir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change mode of %s: %s\n"),
Prog, tcbdir, strerror (errno));
goto out_free;
}
if (lstat (shadow, &filemode) != 0) {
if (errno != ENOENT) {
fprintf(stderr, _("%s: Cannot lstat %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot lstat %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
fprintf (stderr,
@@ -456,18 +495,22 @@ shadowtcb_status shadowtcb_move(/*@NULL@*/const char *user_newname, uid_t user_n
if (!S_ISREG (filemode.st_mode) ||
filemode.st_nlink != 1) {
fprintf (stderr,
_("%s: Emergency: %s's tcb shadow is not a regular file"
" with st_nlink=1.\n"
_("%s: Emergency: %s's tcb shadow is not a "
"regular file with st_nlink=1.\n"
"The account is left locked.\n"),
Prog, user_newname);
goto out_free;
}
if (chown (shadow, user_newid, filemode.st_gid) != 0) {
fprintf(stderr, _("%s: Cannot change owner of %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owner of %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
if (chmod (shadow, filemode.st_mode & 07777) != 0) {
fprintf(stderr, _("%s: Cannot change mode of %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot change mode of %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
}
@@ -475,7 +518,9 @@ shadowtcb_status shadowtcb_move(/*@NULL@*/const char *user_newname, uid_t user_n
goto out_free;
}
if (chown (tcbdir, user_newid, dirmode.st_gid) != 0) {
fprintf(stderr, _("%s: Cannot change owner of %s: %s\n"), Prog, tcbdir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owner of %s: %s\n"),
Prog, tcbdir, strerror (errno));
goto out_free;
}
ret = SHADOWTCB_SUCCESS;
@@ -498,7 +543,9 @@ shadowtcb_status shadowtcb_create(const char *name, uid_t uid)
return SHADOWTCB_SUCCESS;
}
if (stat (TCB_DIR, &tcbdir_stat) != 0) {
fprintf(stderr, _("%s: Cannot stat %s: %s\n"), Prog, TCB_DIR, strerror(errno));
fprintf (stderr,
_("%s: Cannot stat %s: %s\n"),
Prog, TCB_DIR, strerror (errno));
return SHADOWTCB_FAILURE;
}
shadowgid = tcbdir_stat.st_gid;
@@ -516,29 +563,41 @@ shadowtcb_status shadowtcb_create(const char *name, uid_t uid)
return SHADOWTCB_FAILURE;
}
if (mkdir (dir, 0700) != 0) {
fprintf(stderr, _("%s: mkdir: %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: mkdir: %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free;
}
fd = open (shadow, O_RDWR | O_CREAT | O_TRUNC, 0600);
if (fd < 0) {
fprintf(stderr, _("%s: Cannot open %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot open %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
close (fd);
if (chown (shadow, 0, authgid) != 0) {
fprintf(stderr, _("%s: Cannot change owner of %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owner of %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
if (chmod (shadow, (mode_t) ((authgid == shadowgid) ? 0600 : 0640)) != 0) {
fprintf(stderr, _("%s: Cannot change mode of %s: %s\n"), Prog, shadow, strerror(errno));
fprintf (stderr,
_("%s: Cannot change mode of %s: %s\n"),
Prog, shadow, strerror (errno));
goto out_free;
}
if (chown (dir, 0, authgid) != 0) {
fprintf(stderr, _("%s: Cannot change owner of %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change owner of %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free;
}
if (chmod (dir, (mode_t) ((authgid == shadowgid) ? 02700 : 02710)) != 0) {
fprintf(stderr, _("%s: Cannot change mode of %s: %s\n"), Prog, dir, strerror(errno));
fprintf (stderr,
_("%s: Cannot change mode of %s: %s\n"),
Prog, dir, strerror (errno));
goto out_free;
}
if ( (shadowtcb_set_user (name) == SHADOWTCB_FAILURE)