<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: using a string variable in a system call in C code in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432215#M728890</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You are right, but I have some small remarks.&lt;BR /&gt;&lt;BR /&gt;You need two arguments to your program, the username and uid. The uid us present in the passwd struct you obtain by using getpwnam call. The code I included shows how to do this.&lt;BR /&gt;&lt;BR /&gt;Also, be sure to test the returned value of the calls you use. In your program, the setuid call could easily not work (if executed by another user), but the program would continue and try to execcute the script.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;Rik&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Sat, 22 Jul 2000 05:55:49 GMT</pubDate>
    <dc:creator>RikTytgat</dc:creator>
    <dc:date>2000-07-22T05:55:49Z</dc:date>
    <item>
      <title>using a string variable in a system call in C code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432213#M728888</link>
      <description>I am trying to figure out to make a system call in C code to execute a script&lt;BR /&gt;that resides in each user's home directory.  I pass the username and userid&lt;BR /&gt;as arguments.  Here's a sample of the latest version of the code:&lt;BR /&gt;&lt;BR /&gt;#include &lt;UNISTD.H&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;#include &lt;STDLIB.H&gt;&lt;BR /&gt;#include &lt;PWD.H&gt;&lt;BR /&gt;void main (argc, argv)&lt;BR /&gt;  int argc;&lt;BR /&gt;  char **argv;&lt;BR /&gt;{&lt;BR /&gt;  struct passwd *user;&lt;BR /&gt;  setuid(atoi(argv[2]));&lt;BR /&gt;  user=getpwnam(argv[1]);&lt;BR /&gt;  system("%s/test_script", user-&amp;gt;pw_dir);&lt;BR /&gt;  setuid(0);&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Executing it gives the following:&lt;BR /&gt;&lt;BR /&gt;sh: %s/test_script:  not found.&lt;BR /&gt;&lt;BR /&gt;Replacing the 'system' with 'printf' and executing it gives the following:&lt;BR /&gt;&lt;BR /&gt;/user1/bkodama/test_script&lt;BR /&gt;&lt;BR /&gt;as desired.&lt;BR /&gt;&lt;BR /&gt;The 'system' call does not seem to recognize the string variable.&lt;BR /&gt;Any ideas???  Thanks,&lt;/PWD.H&gt;&lt;/STDLIB.H&gt;&lt;/STDIO.H&gt;&lt;/UNISTD.H&gt;</description>
      <pubDate>Fri, 21 Jul 2000 20:45:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432213#M728888</guid>
      <dc:creator>Boyd Kodama</dc:creator>
      <dc:date>2000-07-21T20:45:52Z</dc:date>
    </item>
    <item>
      <title>Re: using a string variable in a system call in C code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432214#M728889</link>
      <description>Just figured it out.&lt;BR /&gt;&lt;BR /&gt;Added:&lt;BR /&gt;&lt;BR /&gt;char upath[120];&lt;BR /&gt;&lt;BR /&gt;Revised:&lt;BR /&gt;&lt;BR /&gt;system(upath,"%s/.dt/sessions/sessionexit", user-&amp;gt;pw_dir);&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;sprintf(upath,"%s/.dt/sessions/sessionexit", user-&amp;gt;pw_dir);&lt;BR /&gt;system(upath);&lt;BR /&gt;&lt;BR /&gt;And it worked.</description>
      <pubDate>Fri, 21 Jul 2000 21:00:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432214#M728889</guid>
      <dc:creator>Boyd Kodama</dc:creator>
      <dc:date>2000-07-21T21:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: using a string variable in a system call in C code</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432215#M728890</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;You are right, but I have some small remarks.&lt;BR /&gt;&lt;BR /&gt;You need two arguments to your program, the username and uid. The uid us present in the passwd struct you obtain by using getpwnam call. The code I included shows how to do this.&lt;BR /&gt;&lt;BR /&gt;Also, be sure to test the returned value of the calls you use. In your program, the setuid call could easily not work (if executed by another user), but the program would continue and try to execcute the script.&lt;BR /&gt;&lt;BR /&gt;Bye,&lt;BR /&gt;Rik&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 22 Jul 2000 05:55:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/using-a-string-variable-in-a-system-call-in-c-code/m-p/2432215#M728890</guid>
      <dc:creator>RikTytgat</dc:creator>
      <dc:date>2000-07-22T05:55:49Z</dc:date>
    </item>
  </channel>
</rss>

