C++ 在C+中安装samba共享+;
我正在做一个项目,必须在Ubuntu上安装samba共享。此项目将由非root用户使用。现在我正在使用一个名为C++ 在C+中安装samba共享+;,c++,linux,ubuntu,mount,C++,Linux,Ubuntu,Mount,我正在做一个项目,必须在Ubuntu上安装samba共享。此项目将由非root用户使用。现在我正在使用一个名为gvfs mount的应用程序,因为它不需要根密码来装载 我的应用程序使用特定的命令行参数运行该可执行文件,它可以工作,但错误检查很困难。我正在使用一个名为的库来启动gvfs挂载,并对其stdin/out进行写入和读取,但我可以预测应用程序何时会向stdout写入内容。这是一个问题,因为如果我想从gvfs mount的输出中读取一些内容,但应用程序没有写入任何内容,那么宿主应用程序将被阻
gvfs mount
的应用程序,因为它不需要根密码来装载
我的应用程序使用特定的命令行参数运行该可执行文件,它可以工作,但错误检查很困难。我正在使用一个名为的库来启动gvfs挂载
,并对其stdin/out进行写入和读取,但我可以预测应用程序何时会向stdout写入内容。这是一个问题,因为如果我想从gvfs mount
的输出中读取一些内容,但应用程序没有写入任何内容,那么宿主应用程序将被阻止,因为这将等待一些永远不会出现的内容
我知道我可以使用sys/mount.h
中的mount
功能,但这需要root权限。我的问题是:C++中有关于这个主题的API、库或教程吗?p>
编辑:
作为电影的作者,我看了GVFS的源代码,我转换成C++。以下是我的基本代码:
#include <gtkmm.h>
#include <stdexcept>
#include <iostream>
Glib::RefPtr<Gio::File> file;
Glib::RefPtr<Glib::MainLoop> main_loop;
void on_async_ready(Glib::RefPtr<Gio::AsyncResult>& result)
{
file->mount_enclosing_volume_finish(result);
main_loop->quit();
}
int main()
{
Gio::init();
Glib::init();
main_loop = Glib::MainLoop::create(false);
file = Gio::File::create_for_commandline_arg("smb://192.168.1.3/Memory\\ core");
Glib::RefPtr<Gio::MountOperation> mount_operation = Gio::MountOperation::create();
mount_operation->set_domain("domain");
mount_operation->set_username("user");
mount_operation->set_password("password");
try
{
file->mount_enclosing_volume(mount_operation, &on_async_ready);
}
catch(const Glib::Error& ex)
{
std::cerr << ex.what() << std::endl;
}
main_loop->run();
return 0;
}
#include <gtkmm.h>
#include <iostream>
Glib::RefPtr<Gio::File> file;
Glib::RefPtr<Glib::MainLoop> main_loop;
void on_async_ready(Glib::RefPtr<Gio::AsyncResult>& result)
{
try
{
file->mount_enclosing_volume_finish(result);
}
catch(const Glib::Error& ex)
{
std::cerr << ex.what() << std::endl;
}
main_loop->quit();
}
int main()
{
Gio::init();
Glib::init();
main_loop = Glib::MainLoop::create(false);
file = Gio::File::create_for_commandline_arg("smb://192.168.1.3/Memory core");
Glib::RefPtr<Gio::MountOperation> mount_operation = Gio::MountOperation::create();
mount_operation->set_domain("domain");
mount_operation->set_username("user");
mount_operation->set_password("password");
file->mount_enclosing_volume(mount_operation, &on_async_ready);
main_loop->run();
return 0;
}
#包括
#包括
#包括
Glib::RefPtr文件;
Glib::RefPtr主回路;
异步准备就绪时无效(Glib::RefPtr&result)
{
文件->装入卷\u完成(结果);
主循环->退出();
}
int main()
{
Gio::init();
Glib::init();
main_loop=Glib::MainLoop::create(false);
file=Gio::file::为命令行参数(“smb://192.168.1.3/Memory\\核心);
Glib::RefPtr mount_operation=Gio::MountOperation::create();
挂载操作->设置域(“域”);
挂载操作->设置用户名(“用户”);
挂载操作->设置密码(“密码”);
尝试
{
文件->装入包含卷的卷(装入操作和异步就绪);
}
捕获(const Glib::Error&ex)
{
std::cerr可能重复的gvfs mount
并不是过多的代码:您可以从命令行装载该共享吗?如果您的系统未设置为由非特权用户装载,那么您的任何代码都无法节省时间。是的,我认为相同的uri与gvfs-mount配合得很好。我的印象是gvfs mount
只需在引擎盖下使用mount(2)
。您可以编译调试版本并在调试器下测试它。。。