Description: make blacklisting work like in module-init-tools
 Do not load a blacklisted module even if modprobe is invoked with one of
 its aliases.
Origin: upstream, commit:6882017f809691d070e4df26414676d0219145d5
Applied-Upstream: commit:6882017f809691d070e4df26414676d0219145d5
---

commit 6882017f809691d070e4df26414676d0219145d5
Author: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Date:   Fri Aug 17 09:38:05 2012 -0300

    libkmod-module: Add KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY flag
    
    With this flag kmod_module_probe_insert_module() check if module is
    blacklisted only if it's also an alias. This is needed in order to allow
    blacklisting a module by name and effectively blacklisting all its
    aliases as module-init-tools was doing.
    
    Before this patch we could load pcspkr module as follows:
    
    	/etc/modprobe.d/test.conf:
    		alias yay pcspkr
    		blacklist pcspkr
    
    	$ modprobe yay
    
    Now libkmod has support to blacklist "yay" because "pcspkr" is blacklisted.

diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
index 1271c70..9756d57 100644
--- a/libkmod/libkmod-module.c
+++ b/libkmod/libkmod-module.c
@@ -1172,9 +1172,15 @@ KMOD_EXPORT int kmod_module_probe_insert_module(struct kmod_module *mod,
 			return 0;
 	}
 
-	err = flags & (KMOD_PROBE_APPLY_BLACKLIST |
-					KMOD_PROBE_APPLY_BLACKLIST_ALL);
-	if (err != 0) {
+	/*
+	 * Ugly assignement + check. We need to check if we were told to check
+	 * blacklist and also return the reason why we failed.
+	 * KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY will take effect only if the
+	 * module is an alias, so we also need to check it
+	 */
+	if ((mod->alias != NULL && ((err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY)))
+			|| (err = flags & KMOD_PROBE_APPLY_BLACKLIST_ALL)
+			|| (err = flags & KMOD_PROBE_APPLY_BLACKLIST)) {
 		if (module_is_blacklisted(mod))
 			return err;
 	}
diff --git a/libkmod/libkmod.h b/libkmod/libkmod.h
index 2f813a8..d03ab19 100644
--- a/libkmod/libkmod.h
+++ b/libkmod/libkmod.h
@@ -161,6 +161,7 @@ enum kmod_probe {
 	/* codes below can be used in return value, too */
 	KMOD_PROBE_APPLY_BLACKLIST_ALL =	0x10000,
 	KMOD_PROBE_APPLY_BLACKLIST =		0x20000,
+	KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY =	0x40000,
 };
 
 /* Flags to kmod_module_apply_filter() */
commit 36ddee65620f97c34d79815a24c65993e0c84754
Author: Lucas De Marchi <lucas.demarchi@profusion.mobi>
Date:   Fri Aug 17 09:42:47 2012 -0300

    modprobe: Unconditionally use KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY
    
    This fixes a change in behavior regarding kmod and module-init-tools:
    when trying to load a module by alias, we should check if it's
    blacklisted, regardless of the command line arguments passed.
    
    This was reported by "Dmitry V. Levin <ldv@altlinux.org>".

diff --git a/tools/modprobe.c b/tools/modprobe.c
index f8a2805..b108112 100644
--- a/tools/modprobe.c
+++ b/tools/modprobe.c
@@ -582,6 +582,7 @@ static int insmod(struct kmod_ctx *ctx, const char *alias,
 	if (do_show || verbose > DEFAULT_VERBOSE)
 		show = &print_action;
 
+	flags |= KMOD_PROBE_APPLY_BLACKLIST_ALIAS_ONLY;
 
 	if (use_blacklist)
 		flags |= KMOD_PROBE_APPLY_BLACKLIST;
