aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2009-02-24 23:21:55 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2009-04-03 17:54:23 -0400
commit77dc1139f4a125d46e03fdbb3ac8ab8737ab67d6 (patch)
tree50fa3b608813052a9b9f7525e8acb6afd97d726d
parent4bf0438332d5173836fdc2d6471fec526d0a14a8 (diff)
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>
-rw-r--r--drivers/staging/p9auth/p9auth.c90
1 files changed, 49 insertions, 41 deletions
diff --git a/drivers/staging/p9auth/p9auth.c b/drivers/staging/p9auth/p9auth.c
index 5824c7f88cca..c1e5bc4f30ae 100644
--- a/drivers/staging/p9auth/p9auth.c
+++ b/drivers/staging/p9auth/p9auth.c
@@ -18,8 +18,7 @@
18#include <linux/fcntl.h> 18#include <linux/fcntl.h>
19#include <linux/cdev.h> 19#include <linux/cdev.h>
20#include <linux/syscalls.h> 20#include <linux/syscalls.h>
21#include <asm/system.h> 21#include <linux/uaccess.h>
22#include <asm/uaccess.h>
23#include <linux/list.h> 22#include <linux/list.h>
24#include <linux/err.h> 23#include <linux/err.h>
25#include <linux/mm.h> 24#include <linux/mm.h>
@@ -33,6 +32,7 @@
33#include <linux/crypto.h> 32#include <linux/crypto.h>
34#include <linux/sched.h> 33#include <linux/sched.h>
35#include <linux/cred.h> 34#include <linux/cred.h>
35#include <asm/system.h>
36 36
37#ifndef CAP_MAJOR 37#ifndef CAP_MAJOR
38#define CAP_MAJOR 0 38#define CAP_MAJOR 0
@@ -61,13 +61,11 @@ struct cap_dev {
61 struct cdev cdev; 61 struct cdev cdev;
62}; 62};
63 63
64int cap_trim(struct cap_dev *); 64char *cap_hash(char *plain_text, unsigned int plain_text_size, char *key,
65ssize_t cap_write(struct file *, const char __user *, size_t, loff_t *); 65 unsigned int key_size);
66char *cap_hash(char *plain_text, unsigned int plain_text_size, char *key, unsigned int key_size);
67void hex_dump(unsigned char * buf, unsigned int len);
68 66
69int cap_major = CAP_MAJOR; 67int cap_major = CAP_MAJOR;
70int cap_minor = 0; 68int cap_minor;
71int cap_nr_devs = CAP_NR_DEVS; 69int cap_nr_devs = CAP_NR_DEVS;
72int cap_node_size = CAP_NODE_SIZE; 70int cap_node_size = CAP_NODE_SIZE;
73 71
@@ -116,9 +114,7 @@ int cap_open(struct inode *inode, struct file *filp)
116 } 114 }
117 /* initialise the head if it is NULL */ 115 /* initialise the head if it is NULL */
118 if (dev->head == NULL) { 116 if (dev->head == NULL) {
119 dev->head = 117 dev->head = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
120 (struct cap_node *) kmalloc(sizeof(struct cap_node),
121 GFP_KERNEL);
122 INIT_LIST_HEAD(&(dev->head->list)); 118 INIT_LIST_HEAD(&(dev->head->list));
123 } 119 }
124 return 0; 120 return 0;
@@ -129,9 +125,8 @@ int cap_release(struct inode *inode, struct file *filp)
129 return 0; 125 return 0;
130} 126}
131 127
132ssize_t 128ssize_t cap_write(struct file *filp, const char __user *buf, size_t count,
133cap_write(struct file * filp, const char __user * buf, 129 loff_t *f_pos)
134 size_t count, loff_t * f_pos)
135{ 130{
136 struct cap_node *node_ptr, *tmp; 131 struct cap_node *node_ptr, *tmp;
137 struct list_head *pos; 132 struct list_head *pos;
@@ -145,10 +140,8 @@ cap_write(struct file * filp, const char __user * buf,
145 if (down_interruptible(&dev->sem)) 140 if (down_interruptible(&dev->sem))
146 return -ERESTARTSYS; 141 return -ERESTARTSYS;
147 142
148 node_ptr = 143 node_ptr = kmalloc(sizeof(struct cap_node), GFP_KERNEL);
149 (struct cap_node *) kmalloc(sizeof(struct cap_node), 144 user_buf = kmalloc(count, GFP_KERNEL);
150 GFP_KERNEL);
151 user_buf = (char *) kmalloc(count, GFP_KERNEL);
152 memset(user_buf, 0, count); 145 memset(user_buf, 0, count);
153 146
154 if (copy_from_user(user_buf, buf, count)) { 147 if (copy_from_user(user_buf, buf, count)) {
@@ -156,7 +149,8 @@ cap_write(struct file * filp, const char __user * buf,
156 goto out; 149 goto out;
157 } 150 }
158 151
159 /* If the minor number is 0 ( /dev/caphash ) then simply add the 152 /*
153 * If the minor number is 0 ( /dev/caphash ) then simply add the
160 * hashed capability supplied by the user to the list of hashes 154 * hashed capability supplied by the user to the list of hashes
161 */ 155 */
162 if (0 == iminor(filp->f_dentry->d_inode)) { 156 if (0 == iminor(filp->f_dentry->d_inode)) {
@@ -165,9 +159,11 @@ cap_write(struct file * filp, const char __user * buf,
165 memcpy(node_ptr->data, user_buf, count); 159 memcpy(node_ptr->data, user_buf, count);
166 list_add(&(node_ptr->list), &(dev->head->list)); 160 list_add(&(node_ptr->list), &(dev->head->list));
167 } else { 161 } else {
168 /* break the supplied string into tokens with @ as the delimiter 162 /*
169 If the string is "user1@user2@randomstring" we need to split it 163 * break the supplied string into tokens with @ as the
170 and hash 'user1@user2' using 'randomstring' as the key 164 * delimiter If the string is "user1@user2@randomstring" we
165 * need to split it and hash 'user1@user2' using 'randomstring'
166 * as the key.
171 */ 167 */
172 user_buf_running = kstrdup(user_buf, GFP_KERNEL); 168 user_buf_running = kstrdup(user_buf, GFP_KERNEL);
173 source_user = strsep(&user_buf_running, "@"); 169 source_user = strsep(&user_buf_running, "@");
@@ -176,7 +172,7 @@ cap_write(struct file * filp, const char __user * buf,
176 172
177 /* hash the string user1@user2 with rand_str as the key */ 173 /* hash the string user1@user2 with rand_str as the key */
178 len = strlen(source_user) + strlen(target_user) + 1; 174 len = strlen(source_user) + strlen(target_user) + 1;
179 hash_str = (char *) kmalloc(len, GFP_KERNEL); 175 hash_str = kmalloc(len, GFP_KERNEL);
180 memset(hash_str, 0, len); 176 memset(hash_str, 0, len);
181 strcat(hash_str, source_user); 177 strcat(hash_str, source_user);
182 strcat(hash_str, "@"); 178 strcat(hash_str, "@");
@@ -196,7 +192,10 @@ cap_write(struct file * filp, const char __user * buf,
196 * list of hashes 192 * list of hashes
197 */ 193 */
198 list_for_each(pos, &(cap_devices->head->list)) { 194 list_for_each(pos, &(cap_devices->head->list)) {
199 /* Change the user id of the process if the hashes match */ 195 /*
196 * Change the user id of the process if the hashes
197 * match
198 */
200 if (0 == 199 if (0 ==
201 memcmp(result, 200 memcmp(result,
202 list_entry(pos, struct cap_node, 201 list_entry(pos, struct cap_node,
@@ -208,8 +207,9 @@ cap_write(struct file * filp, const char __user * buf,
208 simple_strtol(source_user, NULL, 0); 207 simple_strtol(source_user, NULL, 0);
209 flag = 1; 208 flag = 1;
210 209
211 /* Check whether the process writing to capuse is actually owned by 210 /*
212 * the source owner 211 * Check whether the process writing to capuse
212 * is actually owned by the source owner
213 */ 213 */
214 if (source_int != current_uid()) { 214 if (source_int != current_uid()) {
215 printk(KERN_ALERT 215 printk(KERN_ALERT
@@ -217,9 +217,11 @@ cap_write(struct file * filp, const char __user * buf,
217 retval = -EFAULT; 217 retval = -EFAULT;
218 goto out; 218 goto out;
219 } 219 }
220 /* What all id's need to be changed here? uid, euid, fsid, savedids ?? 220 /*
221 * Currently I am changing the effective user id 221 * What all id's need to be changed here? uid,
222 * since most of the authorisation decisions are based on it 222 * euid, fsid, savedids ?? Currently I am
223 * changing the effective user id since most of
224 * the authorisation decisions are based on it
223 */ 225 */
224 new = prepare_creds(); 226 new = prepare_creds();
225 if (!new) { 227 if (!new) {
@@ -232,16 +234,21 @@ cap_write(struct file * filp, const char __user * buf,
232 if (retval) 234 if (retval)
233 goto out; 235 goto out;
234 236
235 /* Remove the capability from the list and break */ 237 /*
236 tmp = 238 * Remove the capability from the list and
237 list_entry(pos, struct cap_node, list); 239 * break
240 */
241 tmp = list_entry(pos, struct cap_node, list);
238 list_del(pos); 242 list_del(pos);
239 kfree(tmp); 243 kfree(tmp);
240 break; 244 break;
241 } 245 }
242 } 246 }
243 if (0 == flag) { 247 if (0 == flag) {
244 /* The capability is not present in the list of the hashes stored, hence return failure */ 248 /*
249 * The capability is not present in the list of the
250 * hashes stored, hence return failure
251 */
245 printk(KERN_ALERT 252 printk(KERN_ALERT
246 "Invalid capabiliy written to /dev/capuse \n"); 253 "Invalid capabiliy written to /dev/capuse \n");
247 retval = -EFAULT; 254 retval = -EFAULT;
@@ -254,12 +261,12 @@ cap_write(struct file * filp, const char __user * buf,
254 if (dev->size < *f_pos) 261 if (dev->size < *f_pos)
255 dev->size = *f_pos; 262 dev->size = *f_pos;
256 263
257 out: 264out:
258 up(&dev->sem); 265 up(&dev->sem);
259 return retval; 266 return retval;
260} 267}
261 268
262struct file_operations cap_fops = { 269const struct file_operations cap_fops = {
263 .owner = THIS_MODULE, 270 .owner = THIS_MODULE,
264 .write = cap_write, 271 .write = cap_write,
265 .open = cap_open, 272 .open = cap_open,
@@ -332,7 +339,7 @@ int cap_init_module(void)
332 339
333 return 0; 340 return 0;
334 341
335 fail: 342fail:
336 cap_cleanup_module(); 343 cap_cleanup_module();
337 return result; 344 return result;
338} 345}
@@ -344,14 +351,15 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
344 char *key, unsigned int key_size) 351 char *key, unsigned int key_size)
345{ 352{
346 struct scatterlist sg; 353 struct scatterlist sg;
347 char *result = (char *) kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL); 354 char *result = kmalloc(MAX_DIGEST_SIZE, GFP_KERNEL);
348 struct crypto_hash *tfm; 355 struct crypto_hash *tfm;
349 struct hash_desc desc; 356 struct hash_desc desc;
350 int ret; 357 int ret;
351 358
352 tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC); 359 tfm = crypto_alloc_hash("hmac(sha1)", 0, CRYPTO_ALG_ASYNC);
353 if (IS_ERR(tfm)) { 360 if (IS_ERR(tfm)) {
354 printk("failed to load transform for hmac(sha1): %ld\n", 361 printk(KERN_ERR
362 "failed to load transform for hmac(sha1): %ld\n",
355 PTR_ERR(tfm)); 363 PTR_ERR(tfm));
356 kfree(result); 364 kfree(result);
357 return NULL; 365 return NULL;
@@ -365,7 +373,7 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
365 373
366 ret = crypto_hash_setkey(tfm, key, key_size); 374 ret = crypto_hash_setkey(tfm, key, key_size);
367 if (ret) { 375 if (ret) {
368 printk("setkey() failed ret=%d\n", ret); 376 printk(KERN_ERR "setkey() failed ret=%d\n", ret);
369 kfree(result); 377 kfree(result);
370 result = NULL; 378 result = NULL;
371 goto out; 379 goto out;
@@ -373,17 +381,17 @@ char *cap_hash(char *plain_text, unsigned int plain_text_size,
373 381
374 ret = crypto_hash_digest(&desc, &sg, plain_text_size, result); 382 ret = crypto_hash_digest(&desc, &sg, plain_text_size, result);
375 if (ret) { 383 if (ret) {
376 printk("digest () failed ret=%d\n", ret); 384 printk(KERN_ERR "digest () failed ret=%d\n", ret);
377 kfree(result); 385 kfree(result);
378 result = NULL; 386 result = NULL;
379 goto out; 387 goto out;
380 } 388 }
381 389
382 printk("crypto hash digest size %d\n", 390 printk(KERN_DEBUG "crypto hash digest size %d\n",
383 crypto_hash_digestsize(tfm)); 391 crypto_hash_digestsize(tfm));
384 hexdump(result, MAX_DIGEST_SIZE); 392 hexdump(result, MAX_DIGEST_SIZE);
385 393
386 out: 394out:
387 crypto_free_hash(tfm); 395 crypto_free_hash(tfm);
388 return result; 396 return result;
389} 397}