diff --git a/encfs/DirNode.cpp b/encfs/DirNode.cpp index bcc55b6..ca473f8 100644 --- a/encfs/DirNode.cpp +++ b/encfs/DirNode.cpp @@ -520,20 +520,26 @@ int DirNode::mkdir(const char *plaintextPath, mode_t mode, uid_t uid, int res = ::mkdir(cyName.c_str(), mode); - if (olduid >= 0) { - setfsuid(olduid); - } - if (oldgid >= 0) { - setfsgid(oldgid); - } - if (res == -1) { int eno = errno; RLOG(WARNING) << "mkdir error on " << cyName << " mode " << mode << ": " << strerror(eno); res = -eno; - } else { - res = 0; + } + + if (olduid >= 0) { + if(setfsuid(olduid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsuid back error: " << strerror(eno); + // does not return error here as initial setfsuid worked + } + } + if (oldgid >= 0) { + if(setfsgid(oldgid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsgid back error: " << strerror(eno); + // does not return error here as initial setfsgid worked + } } return res; diff --git a/encfs/FileNode.cpp b/encfs/FileNode.cpp index bbe4129..e07763c 100644 --- a/encfs/FileNode.cpp +++ b/encfs/FileNode.cpp @@ -194,10 +194,18 @@ int FileNode::mknod(mode_t mode, dev_t rdev, uid_t uid, gid_t gid) { } if (olduid >= 0) { - setfsuid(olduid); + if(setfsuid(olduid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsuid back error: " << strerror(eno); + // does not return error here as initial setfsuid worked + } } if (oldgid >= 0) { - setfsgid(oldgid); + if(setfsgid(oldgid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsgid back error: " << strerror(eno); + // does not return error here as initial setfsgid worked + } } return res; diff --git a/encfs/RawFileIO.cpp b/encfs/RawFileIO.cpp index 7cab3dd..89b7a88 100644 --- a/encfs/RawFileIO.cpp +++ b/encfs/RawFileIO.cpp @@ -136,7 +136,7 @@ int RawFileIO::open(int flags) { #warning O_LARGEFILE not supported #endif - int eno; + int eno = 0; int newFd = ::open(name.c_str(), finalFlags); if (newFd < 0) { eno = errno; diff --git a/encfs/encfs.cpp b/encfs/encfs.cpp index 99fad32..8c6dd2f 100644 --- a/encfs/encfs.cpp +++ b/encfs/encfs.cpp @@ -456,15 +456,33 @@ int encfs_symlink(const char *to, const char *from) { int oldgid = -1; if (ctx->publicFilesystem) { fuse_context *context = fuse_get_context(); - olduid = setfsuid(context->uid); oldgid = setfsgid(context->gid); + if (oldgid == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsgid error: " << strerror(eno); + return -EPERM; + } + olduid = setfsuid(context->uid); + if (olduid == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsuid error: " << strerror(eno); + return -EPERM; + } } res = ::symlink(toCName.c_str(), fromCName.c_str()); if (olduid >= 0) { - setfsuid(olduid); + if(setfsuid(olduid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsuid back error: " << strerror(eno); + // does not return error here as initial setfsuid worked + } } if (oldgid >= 0) { - setfsgid(oldgid); + if(setfsgid(oldgid) == -1) { + int eno = errno; + RLOG(DEBUG) << "setfsgid back error: " << strerror(eno); + // does not return error here as initial setfsgid worked + } } if (res == -1) { diff --git a/encfs/readpassphrase.cpp b/encfs/readpassphrase.cpp index 59a8abd..f9bf0f0 100644 --- a/encfs/readpassphrase.cpp +++ b/encfs/readpassphrase.cpp @@ -125,22 +125,23 @@ restart: memset(&oterm, 0, sizeof(oterm)); } - (void)write(output, prompt, strlen(prompt)); - end = buf + bufsiz - 1; - for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { - if (p < end) { - if ((flags & RPP_SEVENBIT) != 0) { - ch &= 0x7f; - } - if (isalpha(ch) != 0) { - if ((flags & RPP_FORCELOWER) != 0) { - ch = tolower(ch); + if (write(output, prompt, strlen(prompt)) != -1) { + end = buf + bufsiz - 1; + for (p = buf; (nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r';) { + if (p < end) { + if ((flags & RPP_SEVENBIT) != 0) { + ch &= 0x7f; } - if ((flags & RPP_FORCEUPPER) != 0) { - ch = toupper(ch); + if (isalpha(ch) != 0) { + if ((flags & RPP_FORCELOWER) != 0) { + ch = tolower(ch); + } + if ((flags & RPP_FORCEUPPER) != 0) { + ch = toupper(ch); + } } + *p++ = ch; } - *p++ = ch; } } *p = '\0';