request_key system call with KEY_SPEC_USER_SESSION_KEYRING behaves differently on ubuntu and fedora

rahul . rahul110409 at gmail.com
Mon Jan 25 13:15:01 UTC 2010


  Hi ,

I am trying to test request_key system call with keytype as
KEY_SPEC_USER_SESSION_KEYRING .
But i am getting different output on Fedora and Ubuntu systems for the
same kernel(2.6.27) and glibc(2.9) version.
(Test code is given below)

Test Output:

Ubuntu System:
                 added key:33830e13
                 requested key:33830e13
                 request_key: PASSED

Fedora System:
                added key:32bc5be0
                request_key() Failed with 126
                requested key:ffffffff
                Validation Failed126
                request_key: FAILED

Compilation: gcc -o request_key request_key.c -lkeyutils

Following is the test code(request_key.c):

#include <asm/unistd.h>
#include <linux/keyctl.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <keyutils.h>
int main()
{
        key_serial_t addedkey, requestedkey;
        unsigned int err = 0;
        /* Add a key with keytype KEY_SPEC_USER_SESSION_KEYRING */
        if(-1 == (addedkey = add_key("keyring", "request_key", NULL,
0, KEY_SPEC_USER_SESSION_KEYRING ))) {
                printf("add_key() Failed: with %d\n", errno);
                err++;
        }
        //system("cat /proc/keys");
        printf("added key:%x\n", addedkey);
        /* call request_key without callout-info */
        if(-1 == (requestedkey = request_key("keyring", "request_key",
NULL, KEY_SPEC_USER_SESSION_KEYRING))) {
                printf("request_key() Failed with %d\n", errno);
                err++;
        }
        //system("cat /proc/keys");
        printf("requested key:%x\n", requestedkey);
        /* Validate the key */
        if(addedkey != requestedkey){
                printf("Validation Failed%d\n", errno);
                err++;
        }
        /* Unlink the key */
        if(-1 == keyctl_unlink(addedkey, KEY_SPEC_USER_SESSION_KEYRING)) {
                printf("keyctl_unlink() Failed with %d\n", errno);
                err++;
        }
        //system("cat /proc/keys");
        if (0 == err)
                printf(" request_key: PASSED\n");
        else
                printf(" request_key: FAILED\n");
}


Pls provide your comments/Inputs.

What should be done to get the testcase passed on Fedora?

Thank you.


Regards,
Rahul


More information about the test mailing list