summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorLukas Slebodnik <lslebodn@redhat.com>2013-12-02 13:03:33 +0100
committerJakub Hrozek <jhrozek@redhat.com>2014-06-02 19:07:57 +0200
commit5cd660aaa885bca95ac3dca660bb77e5786d5f8e (patch)
tree6450720de4fdbf7a26465c65c2ccc395fbb9b64e /src/util
parentbe7eabee6b7eb8def2441bf5de4c6d4950c155bf (diff)
downloadsssd-5cd660aaa885bca95ac3dca660bb77e5786d5f8e.tar.gz
sssd-5cd660aaa885bca95ac3dca660bb77e5786d5f8e.tar.xz
sssd-5cd660aaa885bca95ac3dca660bb77e5786d5f8e.zip
NSS: Refactor expand_homedir_template
Function expand_homedir_template had lot of parameters. After adding new expand option, all function call should be rewritten, (usually argument NULL will be added) This patch wraps all necessary arguments to structure.
Diffstat (limited to 'src/util')
-rw-r--r--src/util/sss_nss.c43
-rw-r--r--src/util/sss_nss.h12
2 files changed, 34 insertions, 21 deletions
diff --git a/src/util/sss_nss.c b/src/util/sss_nss.c
index 406c95cd0..25a030c3f 100644
--- a/src/util/sss_nss.c
+++ b/src/util/sss_nss.c
@@ -23,9 +23,7 @@
#include "util/sss_nss.h"
char *expand_homedir_template(TALLOC_CTX *mem_ctx, const char *template,
- const char *username, uint32_t uid,
- const char *original, const char *domain,
- const char *flatname)
+ struct sss_nss_homedir_ctx *homedir_ctx)
{
char *copy;
char *p;
@@ -40,6 +38,11 @@ char *expand_homedir_template(TALLOC_CTX *mem_ctx, const char *template,
return NULL;
}
+ if (homedir_ctx == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE, "Missing home directory data.\n");
+ return NULL;
+ }
+
tmp_ctx = talloc_new(NULL);
if (!tmp_ctx) return NULL;
@@ -66,67 +69,71 @@ char *expand_homedir_template(TALLOC_CTX *mem_ctx, const char *template,
}
switch( *n ) {
case 'u':
- if (username == NULL) {
- DEBUG(SSSDBG_CRIT_FAILURE, "Cannot expand user name template "
- "because user name is empty.\n");
+ if (homedir_ctx->username == NULL) {
+ DEBUG(SSSDBG_CRIT_FAILURE,
+ "Cannot expand user name template because user name "
+ "is empty.\n");
goto done;
}
result = talloc_asprintf_append(result, "%s%s", p,
- username);
+ homedir_ctx->username);
break;
case 'U':
- if (uid == 0) {
+ if (homedir_ctx->uid == 0) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot expand uid template "
"because uid is invalid.\n");
goto done;
}
result = talloc_asprintf_append(result, "%s%d", p,
- uid);
+ homedir_ctx->uid);
break;
case 'd':
- if (domain == NULL) {
+ if (homedir_ctx->domain == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot expand domain name "
"template because domain name "
"is empty.\n");
goto done;
}
result = talloc_asprintf_append(result, "%s%s", p,
- domain);
+ homedir_ctx->domain);
break;
case 'f':
- if (domain == NULL || username == NULL) {
+ if (homedir_ctx->domain == NULL
+ || homedir_ctx->username == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot expand fully qualified "
"name template because domain "
"or user name is empty.\n");
goto done;
}
result = talloc_asprintf_append(result, "%s%s@%s", p,
- username, domain);
+ homedir_ctx->username,
+ homedir_ctx->domain);
break;
case 'o':
- if (original == NULL) {
+ if (homedir_ctx->original == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Original home directory for %s is not available, "
- "using empty string\n", username);
+ "using empty string\n", homedir_ctx->username);
orig = "";
} else {
- orig = original;
+ orig = homedir_ctx->original;
}
result = talloc_asprintf_append(result, "%s%s", p, orig);
break;
case 'F':
- if (flatname == NULL) {
+ if (homedir_ctx->flatname == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE, "Cannot expand domain name "
"template because domain flat "
"name is empty.\n");
goto done;
}
- result = talloc_asprintf_append(result, "%s%s", p, flatname);
+ result = talloc_asprintf_append(result, "%s%s", p,
+ homedir_ctx->flatname);
break;
case '%':
diff --git a/src/util/sss_nss.h b/src/util/sss_nss.h
index 6dcdbaef3..771b9ce58 100644
--- a/src/util/sss_nss.h
+++ b/src/util/sss_nss.h
@@ -25,8 +25,14 @@
#include <sys/types.h>
#include <talloc.h>
+struct sss_nss_homedir_ctx {
+ const char *username;
+ uint32_t uid;
+ const char *original;
+ const char *domain;
+ const char *flatname;
+};
+
char *expand_homedir_template(TALLOC_CTX *mem_ctx, const char *template,
- const char *username, uint32_t uid,
- const char *original, const char *domain,
- const char *flatname);
+ struct sss_nss_homedir_ctx *homedir_ctx);
#endif