- 论坛徽章:
- 2
|
本帖最后由 yaoyefengyun 于 2015-08-06 15:36 编辑
kvm虚拟机、cenots7、virtio磁盘
使用yum安装系统自带httpd
手动挂载正常,手动执行自己写的程序挂载也正常,但通过cgi执行挂载时失败。
程序加了s权限,设置了uid,关闭了selinux,不知道是不是需要修改httpd配置文件。
具体代码如下:- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <errno.h>
- #include <sys/mount.h>
- int main(int argc, char **argv)
- {
- uid_t uid;
- gid_t gid;
- printf("Content-Type: text/plain\n\n");
- if (argc != 4) {
- printf("usage: mymount <filesystem> <mounted> <type>\n");
- exit(EXIT_FAILURE);
- }
- if (setuid(0) == -1) {
- printf("%s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- if (setgid(0) == -1) {
- printf("%s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- uid = getuid();
- gid = getgid();
- printf("uid: %d, gid: %d\n", uid, gid);
- printf("mount(%s, %s, %s, 0, NULL)\n", argv[1], argv[2], argv[3]);
- if (mount(argv[1], argv[2], argv[3], 0, NULL) == -1) {
- printf("%s\n", strerror(errno));
- exit(EXIT_FAILURE);
- }
- return 0;
- }
复制代码 重启系统后,通过浏览器第一次执行 .../mymount?/dev/vdf1+/mnt/vdf1+xfs 结果:
uid: 0, gid: 0
mount(/dev/vdf1, /mnt/vdf1, xfs, 0, NULL)
再次执行则出现如下结果:
uid: 0, gid: 0
mount(/dev/vdf1, /mnt/vdf1, xfs, 0, NULL)
Device or resource busy
再刷新网页结果相同
但这时,手动执行该程序,却能成功挂载。这一般来说是什么原因造成的啊? |
|