summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@altlinux.org>2020-03-16 21:02:18 +0000
committerDmitry V. Levin <ldv@altlinux.org>2020-03-19 18:40:16 +0000
commit13ec29f9c11e9ee73fc0f62dd56b3dffc7742c39 (patch)
treec24cc9766d692da768f32daa5c8c8d4c7447f5c4
parent052c5349e602b090507ec61f792428da1b9ef839 (diff)
modules/pam_xauth: use pam_str_skip_prefix
* modules/pam_xauth/pam_xauth.c: Include "pam_inline.h". (pam_sm_open_session, pam_sm_close_session): Use pam_str_skip_prefix instead of ugly strncmp invocations.
-rw-r--r--modules/pam_xauth/pam_xauth.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/modules/pam_xauth/pam_xauth.c b/modules/pam_xauth/pam_xauth.c
index f74a0c98..7d661a45 100644
--- a/modules/pam_xauth/pam_xauth.c
+++ b/modules/pam_xauth/pam_xauth.c
@@ -364,17 +364,19 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
/* Parse arguments. We don't understand many, so no sense in breaking
* this into a separate function. */
for (i = 0; i < argc; i++) {
+ const char *str;
+
if (strcmp(argv[i], "debug") == 0) {
debug = 1;
continue;
}
- if (strncmp(argv[i], "xauthpath=", 10) == 0) {
- xauth = argv[i] + 10;
+ if ((str = pam_str_skip_prefix(argv[i], "xauthpath=")) != NULL) {
+ xauth = str;
continue;
}
- if (strncmp(argv[i], "targetuser=", 11) == 0) {
- long l = strtol(argv[i] + 11, &tmp, 10);
- if ((strlen(argv[i] + 11) > 0) && (*tmp == '\0')) {
+ if ((str = pam_str_skip_prefix(argv[i], "targetuser=")) != NULL) {
+ long l = strtol(str, &tmp, 10);
+ if ((*str != '\0') && (*tmp == '\0')) {
targetuser = l;
} else {
pam_syslog(pamh, LOG_WARNING,
@@ -383,9 +385,9 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
}
continue;
}
- if (strncmp(argv[i], "systemuser=", 11) == 0) {
- long l = strtol(argv[i] + 11, &tmp, 10);
- if ((strlen(argv[i] + 11) > 0) && (*tmp == '\0')) {
+ if ((str = pam_str_skip_prefix(argv[i], "systemuser=")) != NULL) {
+ long l = strtol(str, &tmp, 10);
+ if ((*str != '\0') && (*tmp == '\0')) {
systemuser = l;
} else {
pam_syslog(pamh, LOG_WARNING,
@@ -537,8 +539,8 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED,
/* Check that we got a cookie. If not, we get creative. */
if (((cookie == NULL) || (strlen(cookie) == 0)) &&
- ((strncmp(display, "localhost:", 10) == 0) ||
- (strncmp(display, "localhost/unix:", 15) == 0))) {
+ (pam_str_skip_prefix(display, "localhost:") != NULL ||
+ pam_str_skip_prefix(display, "localhost/unix:") != NULL)) {
char *t, *screen;
size_t tlen, slen;
/* Free the useless cookie string. */
@@ -769,11 +771,11 @@ pam_sm_close_session (pam_handle_t *pamh, int flags UNUSED,
debug = 1;
continue;
}
- if (strncmp(argv[i], "xauthpath=", 10) == 0)
+ if (pam_str_skip_prefix(argv[i], "xauthpath=") != NULL)
continue;
- if (strncmp(argv[i], "systemuser=", 11) == 0)
+ if (pam_str_skip_prefix(argv[i], "systemuser=") != NULL)
continue;
- if (strncmp(argv[i], "targetuser=", 11) == 0)
+ if (pam_str_skip_prefix(argv[i], "targetuser=") != NULL)
continue;
pam_syslog(pamh, LOG_WARNING, "unrecognized option `%s'",
argv[i]);