On Wed, 2020-03-18 at 11:42 +0300, Dmitry V. Levin wrote:
* modules/pam_access/pam_access.c: Include "pam_inline.h".
(parse_args): Use pam_str_skip_prefix instead of ugly strncmp
invocations.
---
modules/pam_access/pam_access.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/modules/pam_access/pam_access.c
b/modules/pam_access/pam_access.c
index b57397be..f53ae3ac 100644
--- a/modules/pam_access/pam_access.c
+++ b/modules/pam_access/pam_access.c
@@ -65,6 +65,7 @@
#include <security/pam_modules.h>
#include <security/pam_modutil.h>
#include <security/pam_ext.h>
+#include "pam_inline.h"
/* login_access.c from logdaemon-5.6 with several changes by
A.Nogin: */
@@ -123,25 +124,27 @@ parse_args(pam_handle_t *pamh, struct
login_info *loginfo,
loginfo->fs = ":";
loginfo->sep = ", \t";
for (i=0; i<argc; ++i) {
- if (!strncmp("fieldsep=", argv[i], 9)) {
+ const char *str;
+
+ if ((str = pam_str_skip_prefix(argv[i], "fieldsep="))) {
Could you please explicitly compare with NULL? This is something that
was introduced as a rule in OpenSSL sources (to always compare pointers
with NULL). Especially here when you also do assignment it improves the
source readability.
No need to resend the patches to re-review for this, if you just apply
this rule everywhere.
/* the admin wants to override the default field separators
*/
- loginfo->fs = argv[i]+9;
+ loginfo->fs = str;
- } else if (!strncmp("listsep=", argv[i], 8)) {
+ } else if ((str = pam_str_skip_prefix(argv[i], "listsep="))) {
/* the admin wants to override the default list separators
*/
- loginfo->sep = argv[i]+8;
+ loginfo->sep = str;
- } else if (!strncmp("accessfile=", argv[i], 11)) {
- FILE *fp = fopen(11 + argv[i], "r");
+ } else if ((str = pam_str_skip_prefix(argv[i], "accessfile=")))
{
+ FILE *fp = fopen(str, "r");
if (fp) {
- loginfo->config_file = 11 + argv[i];
+ loginfo->config_file = str;
fclose(fp);
} else {
pam_syslog(pamh, LOG_ERR,
- "failed to open accessfile=[%s]: %m", 11 +
argv[i]);
+ "failed to open accessfile=[%s]: %m", str);
return 0;
}
--
ldv
_______________________________________________
Pam-developers mailing list -- pam-developers(a)lists.fedorahosted.org
To unsubscribe send an email to
pam-developers-leave(a)lists.fedorahosted.org
Fedora Code of Conduct:
https://docs.fedoraproject.org/en-US/project/code-of-conduct/
List Guidelines:
https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives:
https://lists.fedorahosted.org/archives/list/pam-developers@lists.fedorah...
--
Tomáš Mráz
No matter how far down the wrong road you've gone, turn back.
Turkish proverb
[You'll know whether the road is wrong if you carefully listen to your
conscience.]