Linux Setuid shell脚本

Linux Setuid shell脚本,linux,Linux,需要一些关于传递argv的帮助,以便shell脚本可以作为/usr/local/bin/script.sh用户域运行 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <unistd.h> int main( int argc, char *argv[] ) { if( argc == 3 ) { char *user = arg

需要一些关于传递argv的帮助,以便shell脚本可以作为/usr/local/bin/script.sh用户域运行

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main( int argc, char *argv[] )
{

   if( argc == 3 )
   {
      char *user = argv[1];
      char *domain = argv[2];
      setuid(0);
      system("/usr/local/bin/somescript.sh user domain");
      return 0;
   }
   else if( argc > 3 )
   {
      printf("Too many arguments supplied.\n");
   }
   else
   {
      printf("One argument expected.\n");
   }
}

我怀疑字符串hello&hello.com没有传递到/usr/local/bin/somescript.sh。有人可以帮忙吗?

您不能通过调用
setuid(0)
成为root用户

您正在将文本“user”和“domain”字符串传递给脚本。C不是Perl,变量不会神奇地插入字符串

您需要在运行时创建传递给系统的字符串:

char cmd[100];
sprintf(cmd, "/usr/local/bin/somescript.sh %s %s", user, domain);
system(cmd);

您的问题是什么?
setuid
脚本被禁用是有原因的。你为什么这么做?
char cmd[100];
sprintf(cmd, "/usr/local/bin/somescript.sh %s %s", user, domain);
system(cmd);