From 91b08030619e96257c8a9a95824e5a213be28142 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Wed, 25 Sep 2024 21:21:13 +0200 Subject: samba: Remove untested symlink code Not been able to test the symlink code (as it is SMB1 only), instead of having a lot of (possibly, most likely) broken code that might be used by someone, remove it all. --- libs/samba/src/main/cpp/samba.cpp | 35 ----------------------------------- 1 file changed, 35 deletions(-) (limited to 'libs/samba/src/main/cpp') diff --git a/libs/samba/src/main/cpp/samba.cpp b/libs/samba/src/main/cpp/samba.cpp index ed73d62..38ad5da 100644 --- a/libs/samba/src/main/cpp/samba.cpp +++ b/libs/samba/src/main/cpp/samba.cpp @@ -192,30 +192,6 @@ class Context { return smb2_unlink(context_.get(), path.c_str()) == 0; } - std::optional ReadLink(const std::string& path) { - // Good to start with a fairly small size as current implementation - // of smb2_readlink uses strncpy, which pads the whole unused buffer - // with zeros. - uint32_t bufsize = 256; - std::vector buf; - while (true) { - buf.resize(bufsize); - auto ret = smb2_readlink(context_.get(), path.c_str(), buf.data(), bufsize); - if (ret != 0) - return std::nullopt; - // smb2_readlink uses strncpy, so if actual path was larger than bufsize - // there will be no terminating zero. - auto it = std::find(buf.begin(), buf.end(), '\0'); - if (it != buf.end()) - return std::string(buf.begin(), it); - const auto previous = bufsize; - bufsize *= 2; - // Check for bufsize (a uint32_t) overflow. - if (bufsize <= previous) - return std::nullopt; - } - } - [[nodiscard]] std::unique_ptr OpenFile(const std::string& path, int32_t mode) { int flags; switch (mode) { @@ -289,13 +265,6 @@ jboolean nativeContextUnlink(JNIEnv* env, jclass clazz, jlong ptr, jstring path) return reinterpret_cast(ptr)->Unlink(jni::StringToUTF8(env, jni::ParamRef(env, path))) ? JNI_TRUE : JNI_FALSE; } -jstring nativeContextReadLink(JNIEnv* env, jclass clazz, jlong ptr, jstring path) { - auto ret = reinterpret_cast(ptr)->ReadLink(jni::StringToUTF8(env, jni::ParamRef(env, path))); - if (ret.has_value()) - return jni::UTF8ToString(env, ret.value()).release(); - return nullptr; -} - jlong nativeContextOpenFile(JNIEnv* env, jclass clazz, jlong ptr, jstring path, jint mode) { return reinterpret_cast(reinterpret_cast(ptr)->OpenFile(jni::StringToUTF8(env, jni::ParamRef(env, path)), mode).release()); } @@ -382,7 +351,6 @@ void RegisterSamba(JNIEnv* env) { { "nativeContextMakeDir", "(JLjava/lang/String;)Z", reinterpret_cast(&nativeContextMakeDir) }, { "nativeContextRemoveDir", "(JLjava/lang/String;)Z", reinterpret_cast(&nativeContextRemoveDir) }, { "nativeContextUnlink", "(JLjava/lang/String;)Z", reinterpret_cast(&nativeContextUnlink) }, - { "nativeContextReadLink", "(JLjava/lang/String;)Ljava/lang/String;", reinterpret_cast(&nativeContextReadLink) }, { "nativeContextOpenFile", "(JLjava/lang/String;I)J", reinterpret_cast(&nativeContextOpenFile) }, { "nativeUrlDestroy", "(J)V", reinterpret_cast(&nativeUrlDestroy) }, @@ -424,9 +392,6 @@ jni::LocalRef CreateDirEntry(JNIEnv* env, const std::string& name, cons case SMB2_TYPE_FILE: type = 1; break; - case SMB2_TYPE_LINK: - type = 2; - break; default: return {env, nullptr}; } -- cgit v1.2.3-70-g09d2