Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple? argv[] conversion to char*
    primarykey
    data
    text
    <p>So I have a sample application source I am trying to modify for my own purposes</p> <p>it basically is running a shell script (test example below) but with privs using apple's security framework (see link below for original source).</p> <pre><code>#!/bin/bash echo $@ whoami </code></pre> <p>In that sample code we pass the following:</p> <pre><code> myFlags = kAuthorizationFlagDefaults; // 8 myStatus = AuthorizationExecuteWithPrivileges // 9 (myAuthorizationRef, myToolPath, myFlags, myArguments, &amp;myCommunicationsPipe); </code></pre> <p>I have modified the command to add myToolPath as the first argument as so:</p> <pre><code> // Grab the arguent length int size = strlen(argv[1]); // Grab the first argument char myToolPath[size]; strcpy(myToolPath,argv[1]); </code></pre> <p>which works, it means when I run</p> <pre><code>./compiled_priv_tool /tmp/example.sh </code></pre> <p>It returns "root" rather then the user I am using.</p> <p>But now I want to be able to pass arguments to this helper and have them added to this array This is what the example does in the sample code</p> <pre><code> char *myArguments[] = { "-u", NULL }; </code></pre> <p>So my previous shell example would have output like this:</p> <pre><code>./compiled_priv_tool /tmp/example.sh -u root </code></pre> <p>but I would like to be able to dynamically pass as many arguments as argv can contain to this script so the output would look like this</p> <pre><code>./compiled_priv_tool /tmp/example.sh -u user -f file path -b lah -u user -f file path -b lah root </code></pre> <p>I don't need to handle the arguments in the C code, I just need them to be passed directly to the shell script ( external command ).</p> <p>So heres my (hopefully) simple question, if one wanted to take argv[] and copy it except for argument 0 (which is the path to ./compiled_priv) to something expecting the char * myArguments var what would that look like in code. I learned objective C and never started with C so this is probably pretty basic but I have tried a for loop and copying the two indexes, but its not working. something like:</p> <p>char *myArguments[] = argv</p> <p>is what i want but that does not work, as it says invalid initializer, and even if it did it looks like we need a NULL at the end of the array much like a NSTask. I would include my for loop but its a non starter.</p> <p>So I need to the contents of argv from 1 to the end of the array and to add a NULL to the end and wrap that up in the same form as char *myArguments[] in the original sample code. If I understood c better it would help but in the mean time any thoughts? </p> <p>Here is a link to the source I am playing with if it helps,</p> <p><a href="http://developer.apple.com/library/mac/documentation/security/conceptual/authorization_concepts/03authtasks/authtasks.html#//apple_ref/doc/uid/TP30000995-CH206-TPXREF33" rel="nofollow">http://developer.apple.com/library/mac/documentation/security/conceptual/authorization_concepts/03authtasks/authtasks.html#//apple_ref/doc/uid/TP30000995-CH206-TPXREF33</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload