<br><br><div class="gmail_quote">On Sun, Apr 25, 2010 at 9:39 AM, Jeff Layton <span dir="ltr">&lt;<a href="mailto:jlayton@samba.org">jlayton@samba.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
-----BEGIN PGP SIGNED MESSAGE-----<br>
Hash: SHA1<br>
<br>
On Sat, 24 Apr 2010 19:21:08 -0400<br>
Scott Lovenberg &lt;<a href="mailto:scott.lovenberg@gmail.com">scott.lovenberg@gmail.com</a>&gt; wrote:<br>
<br>
Maybe try not to put all of the description on the subject line. You<br>
can use multiple lines and it makes it a little tougher to import the<br>
patch.<br></blockquote><div>Hrm... those were multiple lines.  There was a hard return after the first sentence.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

<div><div></div><div class="h5"><br>
&gt; Signed-off-by: Scott Lovenberg &lt;<a href="mailto:scott.lovenberg@gmail.com">scott.lovenberg@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  mount.cifs.c |  141 ++++++++++++++++++++++++++++++++++------------------------<br>
&gt;  1 files changed, 83 insertions(+), 58 deletions(-)<br>
&gt;<br>
&gt; diff --git a/mount.cifs.c b/mount.cifs.c<br>
&gt; index 97dae82..09d6351 100644<br>
&gt; --- a/mount.cifs.c<br>
&gt; +++ b/mount.cifs.c<br>
&gt; @@ -121,6 +121,14 @@<br>
&gt;   */<br>
&gt;  #define CIFS_SETUID_FLAGS (MS_NOSUID|MS_NODEV)<br>
&gt;<br>
&gt; +/*<br>
&gt; + * Values for parsing a credentials file.<br>
&gt; + */<br>
&gt; +#define CRED_UNPARSEABLE 0<br>
&gt; +#define CRED_USER 1<br>
&gt; +#define CRED_PASS 2<br>
&gt; +#define CRED_DOM 4<br>
&gt; +<br>
&gt;  /* struct for holding parsed mount info for use by privleged process */<br>
&gt;  struct parsed_mount_info {<br>
&gt;       unsigned long flags;<br>
&gt; @@ -511,20 +519,43 @@ toggle_dac_capability(int writable, int enable)<br>
&gt;  #endif /* HAVE_LIBCAP */<br>
&gt;  #endif /* HAVE_LIBCAP_NG */<br>
&gt;<br>
&gt; -/*<br>
&gt; - * Null terminate string at first &#39;\n&#39;<br>
&gt; - */<br>
&gt; -static void null_terminate_endl(char* source)<br>
&gt; +static void null_terminate_endl(char *source)<br>
&gt;  {<br>
&gt; -     char* newline = strchr(source, &#39;\n&#39;);<br>
&gt; +     char *newline = strchr(source, &#39;\n&#39;);<br>
&gt;       if (newline)<br>
&gt;               *newline = &#39;\0&#39;;<br>
&gt;  }<br>
&gt;<br>
&gt; -<br>
&gt; +/*<br>
&gt; + * Parse a line from the credentials file.  Changes target to first<br>
&gt; + * character after &#39;=&#39; on &#39;line&#39; and returns the value type of the line<br>
&gt; + * Returns CRED_UNPARSEABLE on failure or if either parameter is NULL.<br>
&gt; + */<br>
&gt; +static int parse_cred_line(char *line, char **target)<br>
&gt; +{<br>
&gt; +     if (line == NULL || target == NULL)<br>
&gt; +             goto parsing_err;<br>
&gt; +<br>
&gt; +     /* position target at first char of value */<br>
&gt; +     *target = strchr(line, &#39;=&#39;);<br>
&gt; +     if (!target)<br>
</div></div>        ^^^^^^^^^^^^<br>
Should be:<br>
        if (!*target)<br>
<br>
...right?</blockquote><div>Correct. Silly mistake.</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div class="h5">
&gt; +             goto parsing_err;<br>
&gt; +     *target += 1;<br>
&gt; +<br>
&gt; +     /* tell the caller which value target points to */<br>
&gt; +     if (strncasecmp(&quot;user&quot;, line, 4) == 0)<br>
&gt; +             return CRED_USER;<br>
&gt; +     if (strncasecmp(&quot;pass&quot;, line, 4) == 0)<br>
&gt; +             return CRED_PASS;<br>
&gt; +     if (strncasecmp(&quot;dom&quot;, line, 3) == 0)<br>
&gt; +             return CRED_DOM;<br>
&gt; +<br>
&gt; +     parsing_err:<br>
&gt; +             return CRED_UNPARSEABLE;<br>
&gt; +}<br>
&gt;<br>
&gt;  static int open_cred_file(char *file_name,<br>
&gt; -                       struct parsed_mount_info *parsed_info)<br>
&gt; +                     struct parsed_mount_info *parsed_info)<br>
&gt;  {<br>
&gt;       char *line_buf;<br>
&gt;       char *temp_val;<br>
&gt; @@ -535,30 +566,29 @@ static int open_cred_file(char *file_name,<br>
&gt;<br>
&gt;       i = toggle_dac_capability(0, 1);<br>
&gt;       if (i)<br>
&gt; -             return i;<br>
&gt; -<br>
&gt; +             goto return_i;<br>
&gt; +<br>
&gt;       i = access(file_name, R_OK);<br>
&gt;       if (i) {<br>
&gt;               toggle_dac_capability(0, 0);<br>
&gt; -             return i;<br>
&gt; +             goto return_i;<br>
&gt;       }<br>
&gt;<br>
&gt;       fs = fopen(file_name, &quot;r&quot;);<br>
&gt;       if (fs == NULL) {<br>
&gt;               toggle_dac_capability(0, 0);<br>
&gt; -             return errno;<br>
&gt; +             i = errno;<br>
&gt; +             goto return_i;<br>
&gt;       }<br>
&gt;<br>
&gt;       i = toggle_dac_capability(0, 0);<br>
&gt; -     if (i) {<br>
&gt; -             fclose(fs);<br>
&gt; -             return i;<br>
&gt; -     }<br>
&gt; -<br>
&gt; -     line_buf = (char *)malloc(line_buf_size);<br>
&gt; +     if(i)<br>
&gt; +             goto return_i;<br>
&gt; +<br>
&gt; +     line_buf = (char*)malloc(line_buf_size);<br>
&gt;       if (line_buf == NULL) {<br>
&gt; -             fclose(fs);<br>
&gt; -             return EX_SYSERR;<br>
&gt; +             i = EX_SYSERR;<br>
&gt; +             goto return_i;<br>
&gt;       }<br>
&gt;<br>
&gt;       /* parse line from credentials file */<br>
&gt; @@ -570,47 +600,42 @@ static int open_cred_file(char *file_name,<br>
&gt;               }<br>
&gt;               null_terminate_endl(line_buf);<br>
&gt;<br>
&gt; -             /* parse user */<br>
&gt; -             if (strncasecmp(&quot;user&quot;, line_buf + i, 4) == 0) {<br>
&gt; -                     temp_val = strchr(line_buf + i, &#39;=&#39;);<br>
&gt; -                     if (temp_val) {<br>
&gt; -                             /* go past equals sign */<br>
&gt; -                             temp_val++;<br>
&gt; -                             parsed_info-&gt;got_user = 1;<br>
&gt; -                             strlcpy(parsed_info-&gt;username, temp_val,<br>
&gt; -                                     sizeof(parsed_info-&gt;username));<br>
&gt; -                     }<br>
&gt; -             }<br>
&gt; -<br>
&gt; -             /* parse password */<br>
&gt; -             else if (strncasecmp(&quot;pass&quot;, line_buf + i, 4) == 0) {<br>
&gt; -                     temp_val = strchr(line_buf + i, &#39;=&#39;);<br>
&gt; -                     if (!temp_val)<br>
&gt; -                             continue;<br>
&gt; -                     ++temp_val;<br>
&gt; -                     i = set_password(parsed_info, temp_val);<br>
&gt; -                     if (i)<br>
&gt; -                             return i;<br>
&gt; -             }<br>
&gt; -<br>
&gt; -             /* parse domain */<br>
&gt; -             else if (strncasecmp(&quot;dom&quot;, line_buf + i, 3) == 0) {<br>
&gt; -                     temp_val = strchr(line_buf + i, &#39;=&#39;);<br>
&gt; -                     if (temp_val) {<br>
&gt; -                             /* go past equals sign */<br>
&gt; -                             temp_val++;<br>
&gt; -                             if (parsed_info-&gt;verboseflag)<br>
&gt; -                                     fprintf(stderr, &quot;\nDomain %s\n&quot;,<br>
&gt; -                                             temp_val);<br>
&gt; -                             strlcpy(parsed_info-&gt;domain, temp_val,<br>
&gt; -                                     sizeof(parsed_info-&gt;domain));<br>
&gt; -                     }<br>
&gt; +             /* parse next token */<br>
&gt; +             switch(parse_cred_line(line_buf + i, &amp;temp_val)) {<br>
&gt; +             case CRED_USER:<br>
&gt; +                     parse_username(temp_val, parsed_info);<br>
<br>
</div></div>I think you should check the return value from parse_username here too.<br>
<div class="im"><br></div></blockquote><div>Probably a good idea. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="im">
&gt; +                     break;<br>
&gt; +             case CRED_PASS:<br>
&gt; +                     if ((i = set_password(parsed_info, temp_val)))<br>
&gt; +                             goto return_i;<br>
&gt; +                     break;<br>
&gt; +             case CRED_DOM:<br>
&gt; +                     if (parsed_info-&gt;verboseflag)<br>
&gt; +                             fprintf(stderr, &quot;\nDomain %s\n&quot;,<br>
&gt; +                                     temp_val);<br>
&gt; +                     strlcpy(parsed_info-&gt;domain, temp_val,<br>
&gt; +                             sizeof(parsed_info-&gt;domain));<br>
&gt; +                     break;<br>
&gt; +             case CRED_UNPARSEABLE:<br>
&gt; +                     if (parsed_info-&gt;verboseflag)<br>
&gt; +                             fprintf(stderr,<br>
&gt; +                                     &quot;Credential formatted incorrectly: %s&quot;,<br>
&gt; +                                     temp_val);<br>
&gt; +                     break;<br>
&gt;               }<br>
&gt; -<br>
&gt;       }<br>
&gt; -     fclose(fs);<br>
&gt; -     SAFE_FREE(line_buf);<br>
&gt; -     return 0;<br>
&gt; +<br>
&gt; +     i = 0;<br>
&gt; +     /* jump point for errors */<br>
&gt; +     return_i:<br>
<br>
</div>        ^^^^^^^^<br>
Minor nit: typically labels are flush to the left, and the code below<br>
shouldn&#39;t be indented as much.<br>
<div class="im"><br>
&gt; +             if (fs != NULL)<br>
&gt; +                     fclose(fs);<br>
&gt; +<br>
&gt; +             /* make sure passwords are scrubbed from memory */<br>
&gt; +             if (line_buf != NULL)<br>
&gt; +                     memset(line_buf, 0, line_buf_size);<br>
&gt; +             SAFE_FREE(line_buf);<br>
&gt; +             return i;<br>
&gt;  }<br>
&gt;<br>
&gt;  static int<br>
<br>
</div>There&#39;s also some trailing whitespace and other formatting errors that<br>
checkpatch complained about, and the patch didn&#39;t apply cleanly to the<br>
head git commit. I cleaned up most of these problems and will send a<br>
revised patch in a bit.<br>
<br></blockquote><div>Thanks, I forgot to synchronize with remote before I created the patch.  As for the white space, I think that&#39;s an artifact from git, there wasn&#39;t any in the original patch.  Still getting to the bottom of that. </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
- --<br>
<div class="im">Jeff Layton &lt;<a href="mailto:jlayton@samba.org">jlayton@samba.org</a>&gt;<br>
</div>-----BEGIN PGP SIGNATURE-----<br>
Version: GnuPG v2.0.14 (GNU/Linux)<br>
<br>
iEYEARECAAYFAkvURfsACgkQyP0gxQMdzIAcNgCgkfVOVnYMIeLgxjnmDlFjURTV<br>
sCQAn2gmgmkJ80WDfc/UDwyY5uhqNbsJ<br>
=iFIZ<br>
-----END PGP SIGNATURE-----<br>
</blockquote></div><br><br clear="all"><br>-- <br>Peace and Blessings,<br>-Scott.<br><br>