Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipa-getkeytab enhancements #202

Closed
wants to merge 4 commits into from

Conversation

martbab
Copy link
Contributor

@martbab martbab commented Nov 1, 2016

This PR implements '-H' and '-Y' options mentioned in
https://fedorahosted.org/freeipa/ticket/6409 along with the ability to specify
CA cert on the command line (which proved useful during the work on installer
refactoring).

Since my C skills are not at the level I would like them to be it would be nice
if you point out even the tiniest mistakes, risky code or non-idiomatic usage.

Also the test case test_retrieval_using_plain_ldap fails due to unsuccesful
simple bind. I wanted to implement StartTLS for simple binds over ldap://, but
I get the following errors in dirsrv error log:

    [01/Nov/2016:10:44:52.395126000 +0000] connection - conn=883 fd=135
    Incoming BER Element was 3 bytes, max allowable is 209715200 bytes.
    Change the nsslapd-maxbersize attribute in cn=config to increase.

I guess there is something fishy with the way I initialize the StartTLS
session. I would appreciate your help with it.

@@ -712,6 +717,8 @@ int main(int argc, const char *argv[])
_("LDAP DN"), _("DN to bind as if not using kerberos") },
{ "bindpw", 'w', POPT_ARG_STRING, &bindpw, 0,
_("LDAP password"), _("password to use if not using kerberos") },
{ "cacert", 'c', POPT_ARG_STRING, &ca_cert_file, 0,
_("Path to the IPA CA certificate"), _("IPA CA certificate")},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation does not follow the style of the rest of the code here

int port = 0;
char *scheme = NULL;

if (!mech) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand why you are using the mech to determine the URI scheme, these are unrelated things.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is probably some leftover from previous incarnations of the patch. If I manage to make StartTLS work this may actually be irrelevant since we may use ldap://$FQDN and have secure connection.

else {
return 1;
}
url_len = snprintf(url,0,"%s://%s:%d",scheme,servername,port) +1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please just use asprintf() in here.

ret = ipa_server_to_uri(server, sasl_mech, &ldap_uri);
if (ret) {
fprintf(stderr, _("Incompatible combination of server name and "
"SASL bind mechanism\n"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error message looks wrong.
ipa_server_to_uri() currently fails only if the mechanism is not recognized (but that one is checked earlier already), or if string allocation fails.

@@ -837,7 +931,7 @@ int main(int argc, const char *argv[])
exit(4);
}

if (NULL == bindpw) {
if (NULL == bindpw && strncmp(sasl_mech, LDAP_SASL_GSSAPI, 79) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

79 ?

int rc = LDAP_SUCCESS;
char *startswith_ldap = NULL;

startswith_ldap = strstr("ldap://", ldap_uri);
Copy link
Contributor

@simo5 simo5 Nov 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ldap:// can be only at the start of the string, please use strncmp(ldap_uri, "ldap://", 7)

Copy link
Contributor

@simo5 simo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Close, but there are minor issues to fix, also I would not couple SAL mech with choice of URI scheme in all cases.

@martbab
Copy link
Contributor Author

martbab commented Nov 2, 2016

Thank you for review @simo5 . I have fixed the issues and reworked the LDAP initialization and binding logic a bit to clean it up. It produced green tests for me. I have also updated the command man page as I missed that during initial work.

@martbab
Copy link
Contributor Author

martbab commented Nov 4, 2016

Bump for review, this is prerequisite to further installer refactoring work.

Copy link
Contributor

@simo5 simo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly just style nitpicks

}
sprintf(url,"%s://%s:%d",scheme,servername,port);
int rc = ldap_initialize(ld, url);
url_len = asprintf(&url,"%s://%s:%d",scheme,servername,port);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after comma


free(url);
return rc;
if (url_len == -1){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after close parens

int tls_hard = LDAP_OPT_X_TLS_HARD;
int tls_demand = LDAP_OPT_X_TLS_DEMAND;
char *ldap = "ldap://";
char *ldaps = "ldaps://";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no need to use an actual variable, beside these would have to be defined as const char as the strings are constant.

Use defines:
#define SCHEMA_LDAP "ldap://"
#define SCHEMA_LDAPS "ldaps://"
Then for lenght you can use sizeof(SCHEMA_LDAP) -1

return ret;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't add empty line

@@ -221,21 +274,26 @@ static int ipa_ldap_bind(const char *server_name, krb5_principal bind_princ,
&bv, NULL, NULL, NULL);
if (ret != LDAP_SUCCESS) {
fprintf(stderr, _("Simple bind failed\n"));
goto done;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong, if bind fails we should get out

fprintf(stderr, _("Cannot specify server and LDAP uri "
"simultaneously.\n"));
if (!quiet)
poptPrintUsage(pc, stderr, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incorrect indentation

The LDAP password to use when not binding with Kerberos. \fB\-D\fR and \fB\-w\fR can not be used together with \fB\-Y\fR.
.TP
\fB\-\-cacert\fR
The path to IPA CA certificate used to validate LDAPS/STARTTLS connection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> path to 'the' IPA CA certificate
-> connections (plural)

Defaults to /etc/ipa/ca.crt
.TP
\fB\-H, \-\-ldapuri\fR
LDAP URI. If ldap:// is specified, STARTTLS session is initiated by default. Can not be used with \fB\-s\fR.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove 'session'

LDAP URI. If ldap:// is specified, STARTTLS session is initiated by default. Can not be used with \fB\-s\fR.
.TP
\fB\-Y, \-\-mech\fR
SASL mechanism to use if fB\-D\fR and \fB\-w\fR are not used. Choose between GSSAPI and EXTERNAL.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> s/Choose between GSSAPI and/Use either GSSAPI or/

ssl = LDAP_OPT_X_TLS_HARD;;
ret = ldap_set_option(ld, LDAP_OPT_X_TLS, &ssl);
}
else if (strncmp(ldap_uri, ldaps, strlen(ldaps)) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

} else if,
don't go to a new line wth the else

@martbab
Copy link
Contributor Author

martbab commented Nov 8, 2016

Another bump for review.

}
sprintf(url,"%s://%s:%d",scheme,servername,port);
int rc = ldap_initialize(ld, url);
url_len = asprintf(&url,"%s%s:%d", SCHEMA_LDAP, servername, port);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after comma

Copy link
Contributor

@simo5 simo5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the last nit and it's an ACK

@martbab
Copy link
Contributor Author

martbab commented Nov 8, 2016

Done.

@martbab martbab added the ack Pull Request approved, can be merged label Nov 8, 2016
Martin Babinsky added 4 commits November 8, 2016 17:02
get rid of hardcoded CA cert path and allow the caller to use supplied custom
paths instead

https://fedorahosted.org/freeipa/ticket/6409
ipa-getkeytab command was augmented in a way that allows more flexible
selection of bind mechanisms:

   * -H <LDAP_URI> option was added to specify full LDAP uri. By default the
     URI will be constructed from retrieved server name as is done now.
     Specifying this options precludes use of -s.

   * -Y <EXTERNAL|GSSAPI> specifes SASL bind mechanism if no bind DN
     was given (which implies simple bind)

This allows the command to be used also locally via LDAPI, eliminating the
need to provide any credentials at all as root (e.g. in installers)

https://fedorahosted.org/freeipa/ticket/6409
The test suite is now leveraging host/service tracker objects as test case
fixture, removing much of ad-hoc setup/teardown.

https://fedorahosted.org/freeipa/ticket/6409
All new retrieval methods are covered including testing for excluded option
combinations.

https://fedorahosted.org/freeipa/ticket/6409
@martbab martbab added the pushed Pull Request has already been pushed label Nov 8, 2016
@martbab martbab closed this Nov 8, 2016
@martbab martbab deleted the getkeytab-enhancements branch December 16, 2016 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
2 participants