Re: Implementing hooks

From: Andrew Morgan (morganat_private)
Date: Thu Apr 19 2001 - 20:22:44 PDT

  • Next message: Amon Ott: "Re: Hook function suggestion"

    Greg KH wrote:
    > But your macro to pass arbitrary data across it will loose type
    > safety.  How can you do:
    >         SECURITY_HOOK_RETURN_ERROR(retval,basic_ops,ioperm,(foo, bar),"ioperm...")
    > and keep the knowledge that the ioperm parameters foo and bar are of a
    > specific type?  That's all I care about, type safety.
    
    This is ok. The PAM code has
    
        D(("this %s that, whatever", "stuff")); 
    
    all over. Where D(x) is conditionally compiled as
    
       printf x;
    
    or a nop, depending on the #ifdef DEBUG condition.
    
    > If you can, do this, then I totally agree with you.  My knowledge of the
    > gcc preprocessor isn't sufficient to figure out how to do this.
    
    In the case of the above macro, something like this (yes, I tested it!)
    should be fine:
    
    =========
    
    #define SECURITY_HOOK_RETURN_ERROR(ret,major,minor,args,description) \
        do { \
           ret = security_module->major->minor args ; \
           if (ret) \
               return ret; \
        } while (0)
    
    struct minor_sec_mod_s {
        int (*ioperm)(int INT, char *CONST_CHAR_P);
    };
    
    struct sec_mod_s {
        struct minor_sec_mod_s *basic_ops;
    } *security_module;
    
    main()
    {
        int foo, retval;
        const char *bar;
    
        SECURITY_HOOK_RETURN_ERROR(retval,basic_ops,ioperm,(foo,
    bar),"ioperm...");
    }
    
    =========
    
    [Note, be happy that the clash of the 'const char *' and the 'char *'
    shows up when you try to compile this - demonstrating that type checking
    is alive and well. (No, don't try to run this at home ;) ]
    
    Cheers
    
    Andrew
    
    _______________________________________________
    linux-security-module mailing list
    linux-security-moduleat_private
    http://mail.wirex.com/mailman/listinfo/linux-security-module
    



    This archive was generated by hypermail 2b30 : Thu Apr 19 2001 - 20:24:54 PDT