Staging: p9auth: fix up codingstyle issues
This fixes up a number of scripts/codingstyle.pl warnings and errors Cc: Ashwin Ganti <ashwin.ganti@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
parent
4bf0438332
commit
77dc1139f4
|
@ -18,8 +18,7 @@
|
||||||
#include <linux/fcntl.h>
|
#include <linux/fcntl.h>
|
||||||
#include <linux/cdev.h>
|
#include <linux/cdev.h>
|
||||||
#include <linux/syscalls.h>
|
#include <linux/syscalls.h>
|
||||||
#include <asm/system.h>
|
#include <linux/uaccess.h>
|
||||||
#include <asm/uaccess.h>
|
|
||||||
#include <linux/list.h>
|
#include <linux/list.h>
|
||||||
#include <linux/err.h>
|
#include <linux/err.h>
|
||||||
#include <linux/mm.h>
|
#include <linux/mm.h>
|
||||||
|
@ -33,6 +32,7 @@
|
||||||
#include <linux/crypto.h>
|
#include <linux/crypto.h>
|
||||||
#include <linux/sched.h>
|
#include <linux/sched.h>
|
||||||
#include <linux/cred.h>
|
#include <linux/cred.h>
|
||||||
|
#include <asm/system.h>
|
||||||
|
|
||||||
#ifndef CAP_MAJOR
|
#ifndef CAP_MAJOR
|
||||||
#define CAP_MAJOR 0
|
#define CAP_MAJOR 0
|
||||||
|
@ -61,13 +61,11 @@ struct cap_dev {
|
||||||
struct cdev cdev;
|
struct cdev cdev;
|
||||||
};
|
};
|
||||||
|
|
||||||
int cap_trim(struct cap_dev *);
|
char *cap_hash(char *plain_text, unsigned int plain_text_size, char *key,
|
||||||
ssize_t cap_write(struct file *, const char __user *, size_t, loff_t *);
|
unsigned int key_size);
|
||||||
char *cap_hash(char *plain_text, unsigned int plain_text_size, char *key, unsigned int key_size);
|
|
||||||
void hex_dump(unsigned char * buf, unsigned int len);
|
|
||||||
|
|
||||||
int cap_major = CAP_MAJOR;
|
int cap_major = CAP_MAJOR;
|
||||||
int cap_minor = 0;
|
int cap_minor;
|
||||||
int cap_nr_devs = CAP_NR_DEVS;
|
int cap_nr_devs = CAP_NR_DEVS;
|
||||||
int cap_node_size = CAP_NODE_SIZE;
|
int cap_node_size = CAP_NODE_SIZE;
|
||||||
|
|
||||||
|
@ -116,9 +114,7 @@ int cap_open(struct inode *inode, struct file *filp)
|
||||||
}
|
}
|
||||||
/* initialise the head if it is NULL */
|
/* initialise the head if it is NULL */
|
||||||
if (dev->head == NULL) {
|
if (dev->head == NULL) {
|
||||||
dev->head =
|
dev->head = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
|
||||||
(struct cap_node *) kmalloc(sizeof(struct cap_node),
|
|
||||||
GFP_KERNEL);
|
|
||||||
INIT_LIST_HEAD(&(dev->head->list));
|
INIT_LIST_HEAD(&(dev->head->list));
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -129,9 +125,8 @@ int cap_release(struct inode *inode, struct file *filp)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t
|
ssize_t cap_write(struct file *filp, const char __user *buf, size_t count,
|
||||||
cap_write(struct file * filp, const char __user * buf,
|
loff_t *f_pos)
|
||||||
size_t count, loff_t * f_pos)
|
|
||||||
{
|
{
|
||||||
struct cap_node *node_ptr, *tmp;
|
struct cap_node *node_ptr, *tmp;
|
||||||
struct list_head *pos;
|
struct list_head *pos;
|
||||||
|
@ -145,10 +140,8 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
if (down_interruptible(&dev->sem))
|
if (down_interruptible(&dev->sem))
|
||||||
return -ERESTARTSYS;
|
return -ERESTARTSYS;
|
||||||
|
|
||||||
node_ptr =
|
node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
|
||||||
(struct cap_node *) kmalloc(sizeof(struct cap_node),
|
user_buf = kmalloc(count, GFP_KERNEL);
|
||||||
GFP_KERNEL);
|
|
||||||
user_buf = (char *) kmalloc(count, GFP_KERNEL);
|
|
||||||
memset(user_buf, 0, count);
|
memset(user_buf, 0, count);
|
||||||
|
|
||||||
if (copy_from_user(user_buf, buf, count)) {
|
if (copy_from_user(user_buf, buf, count)) {
|
||||||
|
@ -156,7 +149,8 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If the minor number is 0 ( /dev/caphash ) then simply add the
|
/*
|
||||||
|
* If the minor number is 0 ( /dev/caphash ) then simply add the
|
||||||
* hashed capability supplied by the user to the list of hashes
|
* hashed capability supplied by the user to the list of hashes
|
||||||
*/
|
*/
|
||||||
if (0 == iminor(filp->f_dentry->d_inode)) {
|
if (0 == iminor(filp->f_dentry->d_inode)) {
|
||||||
|
@ -165,9 +159,11 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
memcpy(node_ptr->data, user_buf, count);
|
memcpy(node_ptr->data, user_buf, count);
|
||||||
list_add(&(node_ptr->list), &(dev->head->list));
|
list_add(&(node_ptr->list), &(dev->head->list));
|
||||||
} else {
|
} else {
|
||||||
/* break the supplied string into tokens with @ as the delimiter
|
/*
|
||||||
If the string is "user1@user2@randomstring" we need to split it
|
* break the supplied string into tokens with @ as the
|
||||||
and hash 'user1@user2' using 'randomstring' as the key
|
* delimiter If the string is "user1@user2@randomstring" we
|
||||||
|
* need to split it and hash 'user1@user2' using 'randomstring'
|
||||||
|
* as the key.
|
||||||
*/
|
*/
|
||||||
user_buf_running = kstrdup(user_buf, GFP_KERNEL);
|
user_buf_running = kstrdup(user_buf, GFP_KERNEL);
|
||||||
source_user = strsep(&user_buf_running, "@");
|
source_user = strsep(&user_buf_running, "@");
|
||||||
|
@ -176,7 +172,7 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
|
|
||||||
/* hash the string user1@user2 with rand_str as the key */
|
/* hash the string user1@user2 with rand_str as the key */
|
||||||
len = strlen(source_user) + strlen(target_user) + 1;
|
len = strlen(source_user) + strlen(target_user) + 1;
|
||||||
hash_str = (char *) kmalloc(len, GFP_KERNEL);
|
hash_str = kmalloc(len, GFP_KERNEL);
|
||||||
memset(hash_str, 0, len);
|
memset(hash_str, 0, len);
|
||||||
strcat(hash_str, source_user);
|
strcat(hash_str, source_user);
|
||||||
strcat(hash_str, "@");
|
strcat(hash_str, "@");
|
||||||
|
@ -196,7 +192,10 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
* list of hashes
|
* list of hashes
|
||||||
*/
|
*/
|
||||||
list_for_each(pos, &(cap_devices->head->list)) {
|
list_for_each(pos, &(cap_devices->head->list)) {
|
||||||
/* Change the user id of the process if the hashes match */
|
/*
|
||||||
|
* Change the user id of the process if the hashes
|
||||||
|
* match
|
||||||
|
*/
|
||||||
if (0 ==
|
if (0 ==
|
||||||
memcmp(result,
|
memcmp(result,
|
||||||
list_entry(pos, struct cap_node,
|
list_entry(pos, struct cap_node,
|
||||||
|
@ -208,8 +207,9 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
simple_strtol(source_user, NULL, 0);
|
simple_strtol(source_user, NULL, 0);
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
|
||||||
/* Check whether the process writing to capuse is actually owned by
|
/*
|
||||||
* the source owner
|
* Check whether the process writing to capuse
|
||||||
|
* is actually owned by the source owner
|
||||||
*/
|
*/
|
||||||
if (source_int != current_uid()) {
|
if (source_int != current_uid()) {
|
||||||
printk(KERN_ALERT
|
printk(KERN_ALERT
|
||||||
|
@ -217,9 +217,11 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
retval = -EFAULT;
|
retval = -EFAULT;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/* What all id's need to be changed here? uid, euid, fsid, savedids ??
|
/*
|
||||||
* Currently I am changing the effective user id
|
* What all id's need to be changed here? uid,
|
||||||
* since most of the authorisation decisions are based on it
|
* euid, fsid, savedids ?? Currently I am
|
||||||
|
* changing the effective user id since most of
|
||||||
|
* the authorisation decisions are based on it
|
||||||
*/
|
*/
|
||||||
new = prepare_creds();
|
new = prepare_creds();
|
||||||
if (!new) {
|
if (!new) {
|
||||||
|
@ -232,16 +234,21 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
if (retval)
|
if (retval)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
/* Remove the capability from the list and break */
|
/*
|
||||||
tmp =
|
* Remove the capability from the list and
|
||||||
list_entry(pos, struct cap_node, list);
|
* break
|
||||||
|
*/
|
||||||
|
tmp = list_entry(pos, struct cap_node, list);
|
||||||
list_del(pos);
|
list_del(pos);
|
||||||
kfree(tmp);
|
kfree(tmp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (0 == flag) {
|
if (0 == flag) {
|
||||||
/* The capability is not present in the list of the hashes stored, hence return failure */
|
/*
|
||||||
|
* The capability is not present in the list of the
|
||||||
|
* hashes stored, hence return failure
|
||||||
|
*/
|
||||||
printk(KERN_ALERT
|
printk(KERN_ALERT
|
||||||
"Invalid capabiliy written to /dev/capuse \n");
|
"Invalid capabiliy written to /dev/capuse \n");
|
||||||
retval = -EFAULT;
|
retval = -EFAULT;
|
||||||
|
@ -259,7 +266,7 @@ cap_write(struct file * filp, const char __user * buf,
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct file_operations cap_fops = {
|
const struct file_operations cap_fops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.write = cap_write,
|
.write = cap_write,
|
||||||
.open = cap_open,
|
.open = cap_open,
|
||||||
|
@ -344,14 +351,15 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
|
||||||
char *key, unsigned int key_size)
|
char *key, unsigned int key_size)
|
||||||
{
|
{
|
||||||
struct scatterlist sg;
|
struct scatterlist sg;
|
||||||
char *result = (char *) kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
|
char *result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
|
||||||
struct crypto_hash *tfm;
|
struct crypto_hash *tfm;
|
||||||
struct hash_desc desc;
|
struct hash_desc desc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC);
|
tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC);
|
||||||
if (IS_ERR(tfm)) {
|
if (IS_ERR(tfm)) {
|
||||||
printk("failed to load transform for hmac(sha1): %ld\n",
|
printk(KERN_ERR
|
||||||
|
"failed to load transform for hmac(sha1): %ld\n",
|
||||||
PTR_ERR(tfm));
|
PTR_ERR(tfm));
|
||||||
kfree(result);
|
kfree(result);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -365,7 +373,7 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
|
||||||
|
|
||||||
ret = crypto_hash_setkey(tfm, key, key_size);
|
ret = crypto_hash_setkey(tfm, key, key_size);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("setkey() failed ret=%d\n", ret);
|
printk(KERN_ERR "setkey() failed ret=%d\n", ret);
|
||||||
kfree(result);
|
kfree(result);
|
||||||
result = NULL;
|
result = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -373,13 +381,13 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
|
||||||
|
|
||||||
ret = crypto_hash_digest(&desc, &sg, plain_text_size, result);
|
ret = crypto_hash_digest(&desc, &sg, plain_text_size, result);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
printk("digest () failed ret=%d\n", ret);
|
printk(KERN_ERR "digest () failed ret=%d\n", ret);
|
||||||
kfree(result);
|
kfree(result);
|
||||||
result = NULL;
|
result = NULL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
printk("crypto hash digest size %d\n",
|
printk(KERN_DEBUG "crypto hash digest size %d\n",
|
||||||
crypto_hash_digestsize(tfm));
|
crypto_hash_digestsize(tfm));
|
||||||
hexdump(result, MAX_DIGEST_SIZE);
|
hexdump(result, MAX_DIGEST_SIZE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue