All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel J Walsh <dwalsh@redhat.com>
To: Karl MacMillan <kmacmillan@mentalrootkit.com>
Cc: Mark Goldman <mgoldman@tresys.com>, SE Linux <selinux@tycho.nsa.gov>
Subject: Re: [patch 1/3] libsemanage: genhomedircon replacement
Date: Thu, 24 May 2007 11:44:47 -0400	[thread overview]
Message-ID: <4655B2EF.4010609@redhat.com> (raw)
In-Reply-To: <1180017921.2940.24.camel@localhost.localdomain>

Karl MacMillan wrote:
> On Thu, 2007-05-24 at 10:04 -0400, Mark Goldman wrote:
>   
>> On Tue, 2007-05-22 at 17:08 -0400, Karl MacMillan wrote:
>> <snip>
>>     
>>>> +int semanage_genhomedircon(semanage_handle_t * sh, int usepasswd)
>>>> +{
>>>> +	state_t s;
>>>> +
>>>> +	char outfile[PATH_MAX];
>>>> +	char hdt[PATH_MAX];
>>>> +	char fcf[PATH_MAX];
>>>> +
>>>> +	FILE *out = NULL;
>>>> +	int retval = 0;
>>>> +
>>>> +	assert(sh);
>>>> +
>>>> +	s.homedir_template_path = hdt;
>>>> +	snprintf(s.homedir_template_path, PATH_MAX - 1, "%s",
>>>> +		 semanage_path(SEMANAGE_TMP, SEMANAGE_HOMEDIR_TMPL));
>>>> +
>>>> +	snprintf(outfile, PATH_MAX - 1, "%s",
>>>> +		 semanage_path(SEMANAGE_TMP, SEMANAGE_FC_HOMEDIRS));
>>>> +
>>>>         
>>> strdup?
>>>       
>> The paths are allocated on the stack.  Can't strdup them.  All things being
>> equal, I would prefer to keep them on the stack since that is three
>> fewer items I could possibly leak.
>>
>>     
>
> I think malloc'd would be better because otherwise you have to do this
> fun with PATH_MAX and snprintfs (which is hard to read) and end up with
> a lot of data on the stack. Question - do you even need to copy these?
> Why not just store a pointer to what is returned by semanage_path?
>
>   
>>>> +static list_t *default_shell_list(void)
>>>> +{
>>>>         
>>> What is this function for? Why not error out when /etc/shells is not
>>> available?
>>>       
>> Well, the justification here as with several other places is
>> "genhomedircon didn't".
>>
>>     
>
> I think the behavior should be similar, but there is no reason that we
> can't make changes to corner case behavior if we think it would be
> better. So I don't think an _exact_ port is necessary.
>
>   
>>>> +	list_t *list = NULL;
>>>>         
>>> Why are you adding another list type when we just merged one into
>>> libsepol? If you want this merged into trunk before policyrep let's move
>>> the list type over early.
>>>       
>> I'm working off of trunk.  If it isn't in trunk it I can't use it.
>>
>>     
>
> I think another list type is unacceptable so you can either work off
> policyrep or propose early merging of the list types. Either one is fine
> with me.
>
>   
>> <snip>
>>     
>>>> +	shells = fopen("/etc/shells", "r");
>>>> +	if (!shells)
>>>> +		return default_shell_list();
>>>>         
>>> See above - when is this error possible and why not make it fatal.
>>>       
>> Again, "it wasn't fatal in genhomedircon"
>>
>>     
>
> Dan / anyone - why have the default shell list?
>
>   
Just for the reason stated.  If /etc/shells did not exist, we wanted to 
get a list of valid shells.  I chose not to fail in this case.  But I 
guess failure would be ok.  As long as we told the users how to fix.
>> <snip>
>>     
>>>> +	setpwent();
>>>> +	while ((pwbuf = getpwent())) {
>>>>         
>>> You need to check errno to see if there was an error.
>>>
>>> It is not clear from the python docs, but getpwent will definitely pull
>>> user entries from LDAP, NIS, etc. Is that what we want or should we
>>> limit to /etc/passwd only?
>>>       
>> >From what I've been able to gather, python's getpwall is a wrapper 
>> for getpwent. As for whether we want this behavior or not, I'm open 
>> to suggestions.
>>
>>     
>
> Ok - I'm really just concerned that if we try this against a large LDAP
> database things will not go well. Anyone else have an opinion?
>
>   
I believe ldap has some kind of configuration where it will limit the 
amount of data that can be returned.  (At least that is what Nalin tells me)
>> <snip>
>>     
>>>> +static int fwriteheader(state_t * s, FILE * out)
>>>> +{
>>>>         
>>> Needs a better function name.
>>>       
>> Suggestions?
>>
>>     
>
> write_file_context_header? Or don't make it a function at all.
>
>   
>> <snip>
>>     
>>>> +static int write_home_dir_context(FILE * out, list_t * tpl, char *user,
>>>> +				  char *seuser, char *home, char *prefix)
>>>> +{
>>>> +	char *temp;
>>>> +	char *line;
>>>> +
>>>> +	fprintf(out, "\n\n#\n# Home Context for user %s\n#\n\n", user);
>>>> +	for (; tpl; tpl = tpl->next) {
>>>> +		temp = semanage_sed(tpl->data, "HOME_DIR", home);
>>>>         
>>> Wow - I understand that this string handling in C is painful, but is
>>> this really the best alternative? Perhaps parsing the input to make the
>>> substitution easier would be better? Perhaps we should look for some
>>> library code to do this?
>>>       
>> I am not really sure what the problem with this is.  We need to replace
>> arbitrary substrings.  I searched in the C libraries for something that
>> might do what I want.  I couldn't find anything, so I wrote a function
>> to do it.
>>
>>     
>
> This substitution is inefficient and this type of string manipulation in
> general is error prone.
>
>   
>> As for parsing the input to make the substitution easier, I think it
>> would be a lot more work to write or use a full fledged parser.  What
>> we want in this situation is what I wrote in my opinion, although I am
>> open to suggestions.
>>
>> <snip>
>>     
>>>> +static int fwriteoutput(state_t * s, FILE * out)
>>>> +{
>>>>         
>>> This function name should be more descriptive.
>>>       
>> Suggestions?
>>
>>     
>
> Not at the moment - but this is the main entrypoint as far as I can tell
> and the name doesn't imply that at all.
>
>   
>> <snip>
>>     
>>>> +	for (h = homedirs; h; h = h->next) {
>>>> +		s1len = strlen(h->data);
>>>> +		temp = malloc(s1len + sizeof("/[^/]*"));
>>>> +		strcpy(temp, h->data);
>>>> +		strcpy(temp + s1len, "/[^/]*");
>>>>         
>>> strdup
>>>       
>> I needed extra space at the end of the string for the suffix, so I malloc'd
>> it all in one go.
>>
>>     
>
> Ok.
>
>   
>> <snip>
>>     
>>>> +char *semanage_findval(char *file, char *var, char *delim)
>>>> +{
>>>> +	FILE *fd;
>>>> +
>>>> +	char *buff;
>>>> +	char *temp = NULL;
>>>> +
>>>> +	if (!file || !var || !delim)
>>>> +		return NULL;
>>>>         
>>> assert?
>>>       
>> As with other things, genhomedircon would not have aborted on this
>> condition.  It returned "" on all exceptional paths.
>>
>>     
>
> Is it possible for these to be NULL or a sign of an earlier error?
>
>   
>> <snip>
>>     
>>>> +char *semanage_split(char *str, char *delim)
>>>> +{
>>>> +	char *temp = str;
>>>> +
>>>> +	if (!str)
>>>> +		return NULL;
>>>> +	if (!delim || (*delim == '\0'))
>>>> +		return semanage_split_on_space(str);
>>>>         
>>> Having NULL mean space seems odd.
>>>       
>> This function was a python emulation function.  It behaves in the manner
>> that python's split would if you don't pass in a delimiter.
>>
>>     
>
> I'd prefer things to be more idiomatic to C rather than a straight
> python port.
>
>   
>> Consider all unmentioned comments Noted and fixed.
>>
>>     
>
> Great.
>
> Karl
>
>   


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2007-05-24 15:44 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-21  9:54 [patch 0/3] genhomedircon replacement in libsemanage jbrindle
2007-05-21  9:54 ` [patch 1/3] libsemanage: genhomedircon replacement jbrindle
2007-05-22 21:08   ` Karl MacMillan
2007-05-24 14:04     ` Mark Goldman
2007-05-24 14:45       ` Karl MacMillan
2007-05-24 15:44         ` Daniel J Walsh [this message]
2007-05-24 19:20         ` Mark Goldman
2007-05-25 15:52           ` Karl MacMillan
2007-05-25 17:06             ` Joshua Brindle
2007-05-26  0:02               ` Karl MacMillan
2007-05-29 20:25                 ` audit2allow module generation Anand Patel
2007-05-29 21:11                   ` Karl MacMillan
2007-05-30 14:44                     ` Anand Patel
2007-05-31 16:05                       ` Karl MacMillan
2007-06-08 15:36                       ` Karl MacMillan
2007-06-11 13:47                         ` Anand Patel
2007-08-30 13:43                           ` Anand Patel
2007-09-03 16:13                             ` Karl MacMillan
2007-09-10 14:10                               ` Anand Patel
2007-09-10 16:01                                 ` Karl MacMillan
2007-06-19 15:09                 ` [patch 1/3] libsemanage: genhomedircon replacement Joshua Brindle
2007-06-21 16:29                   ` Karl MacMillan
2007-06-21 16:49                     ` Joshua Brindle
2007-06-21 18:04                       ` Karl MacMillan
2007-06-21 18:09                         ` Joshua Brindle
2007-06-21 18:18                           ` Karl MacMillan
2007-06-21 18:25                             ` Joshua Brindle
2007-06-21 18:35                               ` Karl MacMillan
2007-06-21 20:54                                 ` Eamon Walsh
2007-06-22 11:50                                   ` Daniel J Walsh
2007-06-22 15:22                                   ` Karl MacMillan
2007-06-22 15:31                                     ` Joshua Brindle
2007-06-22 16:04                                       ` Karl MacMillan
2007-06-22 16:58                                     ` Eamon Walsh
2007-06-22 19:30                                       ` Karl MacMillan
2007-06-22 20:55                                         ` Eamon Walsh
2007-07-02 14:00                                           ` Joshua Brindle
2007-07-02 14:23                                             ` Karl MacMillan
2007-07-02 15:54                                               ` Joshua Brindle
2007-07-02 21:26                                               ` Joshua Brindle
2007-07-03  1:12                                                 ` James Antill
2007-07-03 11:15                                                   ` Can someone please assist me with selinux issue David Cottle
     [not found]                                                     ` <1183464455.12218.243.camel@moss-spartans.epoch.ncs! c.mil>
2007-07-03 12:07                                                     ` Stephen Smalley
2007-07-04 23:30                                                       ` David Cottle
2007-07-05 12:33                                                         ` Stephen Smalley
2007-07-12 19:03                                                           ` Libsemanage dependency on version of Linux Hasan Rezaul-CHR010
2007-07-12 19:39                                                             ` Stephen Smalley
2007-07-12 19:48                                                               ` Hasan Rezaul-CHR010
2007-07-12 19:57                                                                 ` Stephen Smalley
2007-07-12 19:49                                                               ` Stephen Smalley
2007-07-02 14:54                                             ` [patch 1/3] libsemanage: genhomedircon replacement James Antill
2007-06-22 20:00                                       ` James Antill
2007-05-24 15:05       ` Steve G
2007-05-24 15:27         ` Karl MacMillan
2007-05-24 16:00       ` James Antill
2007-05-25 14:22         ` Mark Goldman
2007-05-21  9:54 ` [patch 2/3] libsemanage: test functions jbrindle
2007-05-21  9:54 ` [patch 3/3] Remove legacy genhomedircon python script jbrindle
2007-05-22 17:23 ` [patch 0/3] genhomedircon replacement in libsemanage Daniel J Walsh
2007-05-22 17:35   ` Joshua Brindle
2007-05-22 21:10     ` Karl MacMillan
2007-05-22 21:11 ` Karl MacMillan
  -- strict thread matches above, loose matches on Subject: below --
2007-08-08 20:22 [patch 0/3] libsemanage: genhomedircon replacement tmiller
2007-08-08 20:22 ` [patch 1/3] " tmiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4655B2EF.4010609@redhat.com \
    --to=dwalsh@redhat.com \
    --cc=kmacmillan@mentalrootkit.com \
    --cc=mgoldman@tresys.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.