Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I update the value of a pointer by pulling the value from an ini file?
    primarykey
    data
    text
    <p>I am trying to make a few fixes and enhancements to <a href="http://olivier.sessink.nl/jailkit/jailkit.8.html" rel="nofollow">Jailkit</a>. The source is in CVS version control so I <a href="https://github.com/MarcusEting/jailkit" rel="nofollow">cloned it to GitHub</a>.</p> <p>The way this is set up, you edit a user's home directory in <code>/etc/passwd</code> to be something like:</p> <pre><code>/home/jail/./home/username </code></pre> <p>Then the <code>getjaildir</code> function reads over that which is passed in as <code>oldhomedir</code> until it finds the first <code>/./</code> match right to left on the string and then will set <code>jaildir</code> to what is to the left of that and the <code>newhomedir</code> to everything to the right of that.</p> <p>I want to be able to override <code>jaildir</code> with the value from a configuration file - but I suck at <code>c</code> and so I am having very difficult time even setting the variables manually.</p> <p>Here is the <a href="https://github.com/MarcusEting/jailkit/blob/master/src/jk_lib.c#L183" rel="nofollow">function</a>:</p> <pre><code>/* if it returns 1 it will allocate new memory for jaildir and newhomedir * else it will return 0 */ int getjaildir(const char *oldhomedir, char **jaildir, char **newhomedir) { int i=strlen(oldhomedir); /* we will not accept /./ as jail, so we continue looking while i &gt; 4 (minimum then is /a/./ ) * we start at the end so if there are multiple /path/./path2/./path3 the user will be jailed in the most minimized path */ while (i &gt; 4) { /* DEBUG_MSG("oldhomedir[%d]=%c\n",i,oldhomedir[i]);*/ if (oldhomedir[i] == '/' &amp;&amp; oldhomedir[i-1] == '.' &amp;&amp; oldhomedir[i-2] == '/') { DEBUG_MSG("&amp;oldhomedir[%d]=%s\n",i,&amp;oldhomedir[i]); *jaildir = strndup(oldhomedir, i-2); *newhomedir = strdup(&amp;oldhomedir[i]); return 1; } i--; } return 1; } </code></pre> <p>After many, many attempts at a more complex solution I tried a very simple, hard-coded variation:</p> <pre><code>int getjaildir(const char *oldhomedir, char **jaildir, char **newhomedir) { *jaildir = "/home/jail"; *newhomedir = "/home/username"; return 1; } </code></pre> <p>This compiles fine on linux but when I run it I end up getting <code>Segmentation fault (11)</code>. I read up on pointers, addresses, dereferencing, variable types, string concatenation, etc. but unfortunately I'm used to loosely typed languages so this is pretty hard. What am I doing wrong?</p> <p><strong>update</strong></p> <p>Instead of setting the values in the <code>getjaildir</code> function I am attempting to set them in the mail loop.</p> <p>At the top of the loop we have the variable definitions:</p> <pre><code> char *jaildir=NULL, *newhome=NULL, *shell=NULL; </code></pre> <p>And here is where the function to set them is called:</p> <pre><code>if (!getjaildir(pw-&gt;pw_dir, &amp;jaildir, &amp;newhome)) { syslog(LOG_ERR, "abort, failed to read the jail and the home from %s for user %s (%d)",pw-&gt;pw_dir, pw-&gt;pw_name, getuid()); exit(17); } </code></pre> <p>Can I just do this immediately afterwards to overwrite the values?</p> <pre><code>jaildir="/home/jail"; newhome="/home/testuser"; </code></pre> <p>When I try this it gives me:</p> <pre><code>*** glibc detected *** -su: munmap_chunk(): invalid pointer: 0x00000000004046ee *** </code></pre>
    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