2010-05-05 22:33:58

by Timo Aaltonen

[permalink] [raw]
Subject: RE: [PATCH] Check for AD style machine principal name

On Thu, 6 May 2010, [email protected] wrote:

> -----Original Message-----
> From: [email protected] [mailto:[email protected]=
rnel.org] On Behalf Of Timo Aaltonen
> Sent: Wednesday, May 05, 2010 6:16 PM
> To: Kevin Coffman
> Cc: J. Bruce Fields; [email protected]
> Subject: Re: [PATCH] Check for AD style machine principal name
>
> On Wed, 5 May 2010, Kevin Coffman wrote:
>
>> On Wed, May 5, 2010 at 12:53 PM, Timo Aaltonen <timo.aaltonen@aalto.=
fi> wrote:
>>>
>>> CC:ing the "new" list.
>>>
>>> On Tue, 27 Apr 2010, J. Bruce Fields wrote:
>>>
>>>> On Mon, Apr 26, 2010 at 05:00:59PM +0300, [email protected] w=
rote:
>>>>>
>>>>> @@ -737,6 +737,26 @@ gssd_search_krb5_keytab(krb5_context context=
,
>>>>> krb5_keytab kt,
>>>>> =A0}
>>>>>
>>>>> =A0/*
>>>>> + * Convert the hostname to machine principal name as created
>>>>> + * by MS Active Directory.
>>>>> +*/
>>>>> +
>>>>> +static char *
>>>>> +hostname_to_adprinc(char *name)
>>>>> +{
>>>>> + =A0 =A0 =A0 int i =3D 0;
>>>>> + =A0 =A0 =A0 char *buf =3D strdup(name);
>>>>
>>>> We should handle the possible NULL return.
>>>
>>> How about not calling hostname_to_adprinc from find_keytab_entry un=
less
>>> myhostname is !=3D NULL?
>>
>> I think he meant that strdup() may fail, and return NULL. That has =
to
>> be handled here, and a possible resulting NULL return from
>> host_to_adprinc() should also be handled below.
>
> Ahh.. ok so how about this:
>
> static char *
> hostname_to_adprinc(char *name)
> {
> int i =3D 0;
> int len =3D strlen(name);
> char *buf;
> if ((buf =3D malloc(len+1))) {
>
>> Doesn't this need to be "+2" since you are adding a '$' and a '\0' t=
o the end of the string, neither of which is included in the strlen() c=
alculation?

Yep, you're right. Shouldn't adding to the buffer fail then, when the=20
malloc leaves the string short?

> strcpy(buf, name);
> while(i < len) {
> buf[i] =3D toupper(buf[i]);
> i++;
> }
>
>> Instead of copying name to buf and then converting the characters in=
buf to uppercase, why not copy and convert in one loop?

This
buf[i] =3D toupper(name[i]);

works fine, thanks :)

--=20
Timo Aaltonen
Systems Specialist
IT Services, Aalto University