Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: RSyslog: users

SCM_CREDENTIALS saga

 

 

RSyslog users RSS feed   Index | Next | Previous | View Threaded


cristian.ionescu-idbohrn at axis

Aug 14, 2012, 8:45 AM

Post #1 of 8 (369 views)
Permalink
SCM_CREDENTIALS saga

Calling 'setsockopt' with 'optname' SCM_CREDENTIALS seems to be both
wrong and not needed. SCM_CREDENTIALS has value 0x2 and on most
architectures that is same as SO_REUSEADDR. That call fails on
mips-arch but seems to work on other archs. A collegue of mine helped
me understand what's happens. Thanks Edde :)

The following patch removes the bad call:

diff --git a/rsyslog/plugins/imuxsock/imuxsock.c b/rsyslog/plugins/imuxsock/imuxsock.c
index 2e281ea..f945592 100644
--- a/rsyslog/plugins/imuxsock/imuxsock.c
+++ b/rsyslog/plugins/imuxsock/imuxsock.c
@@ -421,10 +421,11 @@ openLogSocket(lstn_t *pLstn)
errmsg.LogError(errno, NO_ERRCODE, "set SO_PASSCRED failed on '%s'", pLstn->sockName);
pLstn->bUseCreds = 0;
}
- if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one, sizeof(one)) != 0) {
- errmsg.LogError(errno, NO_ERRCODE, "set SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
- pLstn->bUseCreds = 0;
- }
+// SCM_CREDENTIALS is not a socket option; skip this; not needed
+// if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one, sizeof(one)) != 0) {
+// errmsg.LogError(errno, NO_ERRCODE, "set SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
+// pLstn->bUseCreds = 0;
+// }
}
# else /* HAVE_SCM_CREDENTIALS */
pLstn->bUseCreds = 0;

Thoughts?


Cheers,

--
Cristian
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


cristian.ionescu-idbohrn at axis

Aug 28, 2012, 6:43 AM

Post #2 of 8 (313 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

Rainer,

2 weeks ago I stumbled on this problem:

On Tue, 14 Aug 2012, Cristian Ionescu-Idbohrn wrote:
>
> Calling 'setsockopt' with 'optname' SCM_CREDENTIALS seems to be both
> wrong and not needed.

and I've sent 2 patches. Bellow, a cleaner patch that even corrects
some warnings.

I wonder if you could comment on the matter?

diff --git a/rsyslog/plugins/imuxsock/imuxsock.c b/rsyslog/plugins/imuxsock/imuxsock.c
index 9ad2421..64d8760 100644
--- a/rsyslog/plugins/imuxsock/imuxsock.c
+++ b/rsyslog/plugins/imuxsock/imuxsock.c
@@ -75,9 +75,11 @@ MODULE_TYPE_NOKEEP
#endif

/* emulate struct ucred for platforms that do not have it */
+#if 0
#ifndef HAVE_SCM_CREDENTIALS
struct ucred { int pid; };
#endif
+#endif

/* handle some defines missing on more than one platform */
#ifndef SUN_LEN
@@ -376,7 +378,9 @@ static inline rsRetVal
openLogSocket(lstn_t *pLstn)
{
DEFiRet;
+# if HAVE_SCM_CREDENTIALS
int one;
+# endif /* HAVE_SCM_CREDENTIALS */

if(pLstn->sockName[0] == '\0')
return -1;
@@ -417,10 +421,21 @@ openLogSocket(lstn_t *pLstn)
errmsg.LogError(errno, NO_ERRCODE, "set SO_PASSCRED failed on '%s'", pLstn->sockName);
pLstn->bUseCreds = 0;
}
+#if 0
+ /*
+ * SCM_CREDENTIALS is not a socket option; its value is usually
+ * 0x2 which on most archs corresponds to socket option
+ * SO_REUSEADDR, but on mips-arch there is no socket option with
+ * value 0x2 and SO_REUSEADDR = 0x4, so the call will fail with
+ * ENOPROTOOPT 'Protocol not available'; skip it.
+ * There does not seem any other special setsockopt call is
+ * needed anyway, besides the above.
+ */
if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one, sizeof(one)) != 0) {
errmsg.LogError(errno, NO_ERRCODE, "set SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
pLstn->bUseCreds = 0;
}
+#endif
}
# else /* HAVE_SCM_CREDENTIALS */
pLstn->bUseCreds = 0;
@@ -631,7 +646,9 @@ static rsRetVal readSocket(lstn_t *pLstn)
# endif
struct ucred *cred;
uchar bufRcv[4096+1];
+# if HAVE_SCM_CREDENTIALS
char aux[128];
+# endif
uchar *pRcv = NULL; /* receive buffer */

assert(pLstn->fd >= 0);


Cheers,

--
Cristian
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


cristian.ionescu-idbohrn at axis

Aug 28, 2012, 9:20 AM

Post #3 of 8 (314 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

On Tue, 28 Aug 2012, Rainer Gerhards wrote:
>
> Sry, have a lot of follow-up from my vacation.

No problem.

> Quickly looking at the patch, I see "#if 0". Any reason to keep that
> code in?

No reason, if you accept the patch. Though, I'm a bit unsure about the
"emulate struct ucred for platforms that do not have it". The configure
test needs, IMO, to be seriously improved. What I mean is that compiling:

,----[ conftest.c ]
| #include <sys/types.h>
| #include <sys/socket.h>
`----

is way too simplistic. IMO, it must, at least, try to use SCM_CREDENTIALS
in a .main.

We may come up with a patch for that, if noone else beats us to that.
I'll speak to my more knowledgeable collegues.


Cheers,

--
Cristian
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


rgerhards at hq

Aug 28, 2012, 9:26 AM

Post #4 of 8 (317 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

Sry, have a lot of follow-up from my vacation. Quickly looking at the patch, I see "#if 0". Any reason to keep that code in?

Rainer

> -----Original Message-----
> From: rsyslog-bounces [at] lists [mailto:rsyslog-
> bounces [at] lists] On Behalf Of Cristian Ionescu-Idbohrn
> Sent: Tuesday, August 28, 2012 3:43 PM
> To: rsyslog [at] lists
> Subject: Re: [rsyslog] SCM_CREDENTIALS saga
>
> Rainer,
>
> 2 weeks ago I stumbled on this problem:
>
> On Tue, 14 Aug 2012, Cristian Ionescu-Idbohrn wrote:
> >
> > Calling 'setsockopt' with 'optname' SCM_CREDENTIALS seems to be both
> > wrong and not needed.
>
> and I've sent 2 patches. Bellow, a cleaner patch that even corrects
> some warnings.
>
> I wonder if you could comment on the matter?
>
> diff --git a/rsyslog/plugins/imuxsock/imuxsock.c
> b/rsyslog/plugins/imuxsock/imuxsock.c
> index 9ad2421..64d8760 100644
> --- a/rsyslog/plugins/imuxsock/imuxsock.c
> +++ b/rsyslog/plugins/imuxsock/imuxsock.c
> @@ -75,9 +75,11 @@ MODULE_TYPE_NOKEEP
> #endif
>
> /* emulate struct ucred for platforms that do not have it */
> +#if 0
> #ifndef HAVE_SCM_CREDENTIALS
> struct ucred { int pid; };
> #endif
> +#endif
>
> /* handle some defines missing on more than one platform */
> #ifndef SUN_LEN
> @@ -376,7 +378,9 @@ static inline rsRetVal
> openLogSocket(lstn_t *pLstn)
> {
> DEFiRet;
> +# if HAVE_SCM_CREDENTIALS
> int one;
> +# endif /* HAVE_SCM_CREDENTIALS */
>
> if(pLstn->sockName[0] == '\0')
> return -1;
> @@ -417,10 +421,21 @@ openLogSocket(lstn_t *pLstn)
> errmsg.LogError(errno, NO_ERRCODE, "set SO_PASSCRED
> failed on '%s'", pLstn->sockName);
> pLstn->bUseCreds = 0;
> }
> +#if 0
> + /*
> + * SCM_CREDENTIALS is not a socket option; its value is
> usually
> + * 0x2 which on most archs corresponds to socket option
> + * SO_REUSEADDR, but on mips-arch there is no socket option
> with
> + * value 0x2 and SO_REUSEADDR = 0x4, so the call will fail
> with
> + * ENOPROTOOPT 'Protocol not available'; skip it.
> + * There does not seem any other special setsockopt call is
> + * needed anyway, besides the above.
> + */
> if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one,
> sizeof(one)) != 0) {
> errmsg.LogError(errno, NO_ERRCODE, "set
> SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
> pLstn->bUseCreds = 0;
> }
> +#endif
> }
> # else /* HAVE_SCM_CREDENTIALS */
> pLstn->bUseCreds = 0;
> @@ -631,7 +646,9 @@ static rsRetVal readSocket(lstn_t *pLstn)
> # endif
> struct ucred *cred;
> uchar bufRcv[4096+1];
> +# if HAVE_SCM_CREDENTIALS
> char aux[128];
> +# endif
> uchar *pRcv = NULL; /* receive buffer */
>
> assert(pLstn->fd >= 0);
>
>
> Cheers,
>
> --
> Cristian
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com/professional-services/
> What's up with rsyslog? Follow https://twitter.com/rgerhards
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


rgerhards at hq

Aug 28, 2012, 10:51 AM

Post #5 of 8 (313 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

> -----Original Message-----
> From: Cristian Ionescu-Idbohrn [mailto:cristian.ionescu-
> idbohrn [at] axis]
> Sent: Tuesday, August 28, 2012 6:21 PM
> To: Rainer Gerhards
> Cc: rsyslog-users
> Subject: Re: [rsyslog] SCM_CREDENTIALS saga
>
> On Tue, 28 Aug 2012, Rainer Gerhards wrote:
> >
> > Sry, have a lot of follow-up from my vacation.
>
> No problem.
>
> > Quickly looking at the patch, I see "#if 0". Any reason to keep that
> > code in?
>
> No reason, if you accept the patch. Though, I'm a bit unsure about the
> "emulate struct ucred for platforms that do not have it". The
> configure
> test needs, IMO, to be seriously improved. What I mean is that
> compiling:
>
> ,----[ conftest.c ]
> | #include <sys/types.h>
> | #include <sys/socket.h>
> `----
>
> is way too simplistic. IMO, it must, at least, try to use
> SCM_CREDENTIALS
> in a .main.
>
> We may come up with a patch for that, if noone else beats us to that.
> I'll speak to my more knowledgeable collegues.

That would be excellent!

Rainer
>
>
> Cheers,
>
> --
> Cristian
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


rgerhards at hq

Sep 12, 2012, 12:56 AM

Post #6 of 8 (285 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

> -----Original Message-----
> From: rsyslog-bounces [at] lists [mailto:rsyslog-
> bounces [at] lists] On Behalf Of Cristian Ionescu-Idbohrn
> Sent: Tuesday, August 28, 2012 3:43 PM
> To: rsyslog [at] lists
> Subject: Re: [rsyslog] SCM_CREDENTIALS saga
>
> Rainer,
>
> 2 weeks ago I stumbled on this problem:
>
> On Tue, 14 Aug 2012, Cristian Ionescu-Idbohrn wrote:
> >
> > Calling 'setsockopt' with 'optname' SCM_CREDENTIALS seems to be both
> > wrong and not needed.
>
> and I've sent 2 patches. Bellow, a cleaner patch that even corrects
> some warnings.
>
> I wonder if you could comment on the matter?

I finally looked at the patch. Some comments below:

>
> diff --git a/rsyslog/plugins/imuxsock/imuxsock.c
> b/rsyslog/plugins/imuxsock/imuxsock.c
> index 9ad2421..64d8760 100644
> --- a/rsyslog/plugins/imuxsock/imuxsock.c
> +++ b/rsyslog/plugins/imuxsock/imuxsock.c
> @@ -75,9 +75,11 @@ MODULE_TYPE_NOKEEP
> #endif
>
> /* emulate struct ucred for platforms that do not have it */
> +#if 0
> #ifndef HAVE_SCM_CREDENTIALS
> struct ucred { int pid; };

This is needed by the BSD folks, so we cannot simply #if0 it.

> #endif
> +#endif
>
> /* handle some defines missing on more than one platform */
> #ifndef SUN_LEN
> @@ -376,7 +378,9 @@ static inline rsRetVal
> openLogSocket(lstn_t *pLstn)
> {
> DEFiRet;
> +# if HAVE_SCM_CREDENTIALS
> int one;
> +# endif /* HAVE_SCM_CREDENTIALS */
>
> if(pLstn->sockName[0] == '\0')
> return -1;
> @@ -417,10 +421,21 @@ openLogSocket(lstn_t *pLstn)
> errmsg.LogError(errno, NO_ERRCODE, "set SO_PASSCRED
> failed on '%s'", pLstn->sockName);
> pLstn->bUseCreds = 0;
> }
> +#if 0
> + /*
> + * SCM_CREDENTIALS is not a socket option; its value is
> usually
> + * 0x2 which on most archs corresponds to socket option
> + * SO_REUSEADDR, but on mips-arch there is no socket option
> with
> + * value 0x2 and SO_REUSEADDR = 0x4, so the call will fail
> with
> + * ENOPROTOOPT 'Protocol not available'; skip it.
> + * There does not seem any other special setsockopt call is
> + * needed anyway, besides the above.
> + */

I think that #if0 and the comment means I can remove that code. Will double-check and, if so, remove it.

Rainer
> if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one,
> sizeof(one)) != 0) {
> errmsg.LogError(errno, NO_ERRCODE, "set
> SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
> pLstn->bUseCreds = 0;
> }
> +#endif
> }
> # else /* HAVE_SCM_CREDENTIALS */
> pLstn->bUseCreds = 0;
> @@ -631,7 +646,9 @@ static rsRetVal readSocket(lstn_t *pLstn)
> # endif
> struct ucred *cred;
> uchar bufRcv[4096+1];
> +# if HAVE_SCM_CREDENTIALS
> char aux[128];
> +# endif
> uchar *pRcv = NULL; /* receive buffer */
>
> assert(pLstn->fd >= 0);
>
>
> Cheers,
>
> --
> Cristian
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com/professional-services/
> What's up with rsyslog? Follow https://twitter.com/rgerhards
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards


jonny.tornbom at axis

Sep 12, 2012, 3:16 AM

Post #7 of 8 (289 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

Hi,

I did some investigation of this and here's my conclusions:

(We are currently using rsyslog 5.8.11 here, my comments below is targeted
towards that version if I don't specify otherwise)

SCM_CREDENTIALS is a control message type, not a socket option, so using
setsockopt(...SCM_CREDENTIALS...) is potentially dangerous and wrong and
should be deleted from the code. (SCM_CREDENTIALS is used in conjuction
with SO_PASSCRED which is the socket option to use.)

I'll give some inline comments below and some additional comments at the end:

On Wed, Sep 12, 2012 at 09:56:33AM +0200, Rainer Gerhards wrote:
> > -----Original Message-----
> > From: rsyslog-bounces [at] lists [mailto:rsyslog-
> > bounces [at] lists] On Behalf Of Cristian Ionescu-Idbohrn
> > Sent: Tuesday, August 28, 2012 3:43 PM
> > To: rsyslog [at] lists
> > Subject: Re: [rsyslog] SCM_CREDENTIALS saga
> >
> > Rainer,
> >
> > 2 weeks ago I stumbled on this problem:
> >
> > On Tue, 14 Aug 2012, Cristian Ionescu-Idbohrn wrote:
> > >
> > > Calling 'setsockopt' with 'optname' SCM_CREDENTIALS seems to be both
> > > wrong and not needed.
> >
> > and I've sent 2 patches. Bellow, a cleaner patch that even corrects
> > some warnings.
> >
> > I wonder if you could comment on the matter?
>
> I finally looked at the patch. Some comments below:
>
> >
> > diff --git a/rsyslog/plugins/imuxsock/imuxsock.c
> > b/rsyslog/plugins/imuxsock/imuxsock.c
> > index 9ad2421..64d8760 100644
> > --- a/rsyslog/plugins/imuxsock/imuxsock.c
> > +++ b/rsyslog/plugins/imuxsock/imuxsock.c
> > @@ -75,9 +75,11 @@ MODULE_TYPE_NOKEEP
> > #endif
> >
> > /* emulate struct ucred for platforms that do not have it */
> > +#if 0
> > #ifndef HAVE_SCM_CREDENTIALS
> > struct ucred { int pid; };
>
> This is needed by the BSD folks, so we cannot simply #if0 it.
>
This shall _not_ be #if 0 since several functions take a struct ucred
as argument. However, I saw you had intentions to apply a patch from
Brad Davis (FreeBSD) that extended the ucred struct with guid/uid, and
that shall not really be necessary since none of that is used. This only
generates some unused variables as far as I could see. (There's a second
issue with the other part of that patch, i'll comment on that at the end
of this mail).

> > #endif
> > +#endif
> >
> > /* handle some defines missing on more than one platform */
> > #ifndef SUN_LEN
> > @@ -376,7 +378,9 @@ static inline rsRetVal
> > openLogSocket(lstn_t *pLstn)
> > {
> > DEFiRet;
---
> > +# if HAVE_SCM_CREDENTIALS
> > int one;
> > +# endif /* HAVE_SCM_CREDENTIALS */
This looks OK on 5.8.11 and v7 too, its only used inside an
HAVE_SCM_CREDENTIALS block.
> >
> > if(pLstn->sockName[0] == '\0')
> > return -1;
> > @@ -417,10 +421,21 @@ openLogSocket(lstn_t *pLstn)
> > errmsg.LogError(errno, NO_ERRCODE, "set SO_PASSCRED
> > failed on '%s'", pLstn->sockName);
> > pLstn->bUseCreds = 0;
> > }
> > +#if 0
> > + /*
> > + * SCM_CREDENTIALS is not a socket option; its value is
> > usually
> > + * 0x2 which on most archs corresponds to socket option
> > + * SO_REUSEADDR, but on mips-arch there is no socket option
> > with
> > + * value 0x2 and SO_REUSEADDR = 0x4, so the call will fail
> > with
> > + * ENOPROTOOPT 'Protocol not available'; skip it.
> > + * There does not seem any other special setsockopt call is
> > + * needed anyway, besides the above.
> > + */
>
> I think that #if0 and the comment means I can remove that code. Will double-check and, if so, remove it.
>
> Rainer
The setsockopt(...SCM_CREDENTIALS...) part needs to be removed since its wrong
and potentially dangerous. This part of Cristians patch should be correct.

> > if(setsockopt(pLstn->fd, SOL_SOCKET, SCM_CREDENTIALS, &one,
> > sizeof(one)) != 0) {
> > errmsg.LogError(errno, NO_ERRCODE, "set
> > SCM_CREDENTIALS failed on '%s'", pLstn->sockName);
> > pLstn->bUseCreds = 0;
> > }
> > +#endif
> > }
> > # else /* HAVE_SCM_CREDENTIALS */
> > pLstn->bUseCreds = 0;
> > @@ -631,7 +646,9 @@ static rsRetVal readSocket(lstn_t *pLstn)
> > # endif
> > struct ucred *cred;
> > uchar bufRcv[4096+1];
---
> > +# if HAVE_SCM_CREDENTIALS
> > char aux[128];
> > +# endif
This part is correct in both 5.8.11 and v7, aux is not used outside
of an HAVE_SCM_CREDENTIALS block in this function.
> > uchar *pRcv = NULL; /* receive buffer */
> >
> > assert(pLstn->fd >= 0);
> >
> >
> > Cheers,
> >
> > --
> > Cristian
> > _______________________________________________
> > rsyslog mailing list
> > http://lists.adiscon.net/mailman/listinfo/rsyslog
> > http://www.rsyslog.com/professional-services/
> > What's up with rsyslog? Follow https://twitter.com/rgerhards
> _______________________________________________
> rsyslog mailing list
> http://lists.adiscon.net/mailman/listinfo/rsyslog
> http://www.rsyslog.com/professional-services/
> What's up with rsyslog? Follow https://twitter.com/rgerhards


Ok the patch from Brad Davis (FreeBSD) with my comments inline:

>--- plugins/imuxsock/imuxsock.c.orig 2012-06-18 02:13:18.000000000 -0600
>+++ plugins/imuxsock/imuxsock.c 2012-08-16 16:37:27.000000000 -0600
>@@ -81,7 +81,7 @@
>
> /* emulate struct ucred for platforms that do not have it */
> #ifndef HAVE_SCM_CREDENTIALS
>-struct ucred { int pid; };
>+struct ucred { int pid; uid_t uid; gid_t gid; };
This shall not be necessary, it would be nice with an explanation of why this
is added.
> #endif
>
> /* handle some defines missing on more than one platform */
>@@ -891,9 +891,7 @@
> int iMaxLine;
> struct msghdr msgh;
> struct iovec msgiov;
>-# if HAVE_SCM_CREDENTIALS
> struct cmsghdr *cm;
>-# endif
This part _needs_ to be addressed on current master (v7) since the cm variable
is being used outside of a HAVE_SCM_CREDENTIALS block further down in the same
function. However for 5.8.11 its only used inside of a HAVE_SCM_CREDENTIALS block
and the patch will only generate a compiler warning about an unused variable. So
I think this part of the patch is correct but its version-specific of rsyslog.
> struct ucred *cred;
> struct timeval *ts;
> uchar bufRcv[4096+1];

Another issue was how configure checked if the system had SCM_CREDENTIALS defined.
The current way its done in configure.ac looks correct to me. One could extend it
to check if both SO_PASSCRED and SCM_CREDENTIALS are defined in sys/socket.h
or sys/types.h. (If the macro is defined it should be usable, if not usable, its
outside the scope of rsyslog.)

Another thing I noticed while browsing through plugins/imuxsock/imuxsock.c was that
cred->pid gets assigned a value typecasted to (unsigned long) at some places, where
at other places its casted to an int. Is there a reason for this?

Best regards,
Jonny
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE THAT.


rgerhards at hq

Sep 12, 2012, 6:08 AM

Post #8 of 8 (286 views)
Permalink
Re: SCM_CREDENTIALS saga [In reply to]

Hi Jonny,

[snip]

> > I think that #if0 and the comment means I can remove that code. Will
> double-check and, if so, remove it.
> >
> > Rainer
> The setsockopt(...SCM_CREDENTIALS...) part needs to be removed since
> its wrong
> and potentially dangerous. This part of Cristians patch should be
> correct.

I was a bit puzzled about the "#if 0" - this looked like something done temporarily. I have now removed that code. Thanks for the explanations.

I've also done the other two changes.

> Ok the patch from Brad Davis (FreeBSD) with my comments inline:
>
> >--- plugins/imuxsock/imuxsock.c.orig 2012-06-18 02:13:18.000000000
> -0600
> >+++ plugins/imuxsock/imuxsock.c 2012-08-16 16:37:27.000000000 -0600
> >@@ -81,7 +81,7 @@
> >
> > /* emulate struct ucred for platforms that do not have it */
> > #ifndef HAVE_SCM_CREDENTIALS
> >-struct ucred { int pid; };
> >+struct ucred { int pid; uid_t uid; gid_t gid; };
> This shall not be necessary, it would be nice with an explanation of
> why this
> is added.

I merged that part as it looked danger-free to me for a quick merge. But I agree:

Brad, could you please comment on why you need them?

> >
> > /* handle some defines missing on more than one platform */
> >@@ -891,9 +891,7 @@
> > int iMaxLine;
> > struct msghdr msgh;
> > struct iovec msgiov;
> >-# if HAVE_SCM_CREDENTIALS
> > struct cmsghdr *cm;
> >-# endif
> This part _needs_ to be addressed on current master (v7) since the cm
> variable
> is being used outside of a HAVE_SCM_CREDENTIALS block further down in
> the same
> function. However for 5.8.11 its only used inside of a
> HAVE_SCM_CREDENTIALS block
> and the patch will only generate a compiler warning about an unused
> variable. So
> I think this part of the patch is correct but its version-specific of
> rsyslog.

I did not merge that part of the patch. V5 will soon be legacy and v6 and 7 need this, so this is not the time to apply a more or less cosmetic patch to v5.

> > struct ucred *cred;
> > struct timeval *ts;
> > uchar bufRcv[4096+1];
>
> Another issue was how configure checked if the system had
> SCM_CREDENTIALS defined.
> The current way its done in configure.ac looks correct to me. One could
> extend it
> to check if both SO_PASSCRED and SCM_CREDENTIALS are defined in
> sys/socket.h
> or sys/types.h. (If the macro is defined it should be usable, if not
> usable, its
> outside the scope of rsyslog.)

Will look into that later. Autoconf is not my best friend ;)

> Another thing I noticed while browsing through
> plugins/imuxsock/imuxsock.c was that
> cred->pid gets assigned a value typecasted to (unsigned long) at some
> places, where
> at other places its casted to an int. Is there a reason for this?

Yup: if you look closely, the cast happens for printf only. As I do not know what number of bits we have on each platform, I cast it to unsigned long, which usually should do. Even if it2 64 bits, some debug output messages are truncated (the counter printf is still sufficient).

Rainer
_______________________________________________
rsyslog mailing list
http://lists.adiscon.net/mailman/listinfo/rsyslog
http://www.rsyslog.com/professional-services/
What's up with rsyslog? Follow https://twitter.com/rgerhards
NOTE WELL: This is a PUBLIC mailing list, posts are ARCHIVED by a myriad of sites beyond our control. PLEASE UNSUBSCRIBE and DO NOT POST if you DON'T LIKE THAT.

RSyslog users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.