summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--usr.bin/tcfs/tcfs_dbmaint.c17
-rw-r--r--usr.bin/tcfs/tcfs_keymaint.c31
-rw-r--r--usr.bin/tcfs/tcfsaddgroup.c56
-rw-r--r--usr.bin/tcfs/tcfsdefines.h2
-rw-r--r--usr.bin/tcfs/tcfspwdb.h8
-rw-r--r--usr.bin/tcfs/tcfsrmgroup.c2
6 files changed, 56 insertions, 60 deletions
diff --git a/usr.bin/tcfs/tcfs_dbmaint.c b/usr.bin/tcfs/tcfs_dbmaint.c
index b7b0004a223..d368ecc030b 100644
--- a/usr.bin/tcfs/tcfs_dbmaint.c
+++ b/usr.bin/tcfs/tcfs_dbmaint.c
@@ -229,6 +229,7 @@ tcfs_ggetpwnam (char *user, gid_t gid, tcfsgpwdb **dest)
DB *pdb;
DBT srchkey, r;
char *key, *buf;
+ int res;
if (!*dest)
if (!tcfsgpwdbr_new (dest))
@@ -243,10 +244,12 @@ tcfs_ggetpwnam (char *user, gid_t gid, tcfsgpwdb **dest)
return NULL;
sprintf (key, "%s\33%d\0", user, (int)gid);
- srchkey.data=key;
- srchkey.size=(int)strlen (key);
+ srchkey.data = key;
+ srchkey.size = (int)strlen (key);
- if (pdb->get(pdb, &srchkey, &r, 0)) {
+ if ((res = pdb->get(pdb, &srchkey, &r, 0))) {
+ if (res == -1)
+ perror("dbget");
pdb->close (pdb);
return (NULL);
}
@@ -306,12 +309,14 @@ tcfs_gputpwnam (char *user, tcfsgpwdb *src, int flags)
char *tmp;
open_flag = O_RDWR|O_EXCL;
- if (access (TCFSPWDB, F_OK) < 0)
+ if (access (TCFSGPWDB, F_OK) < 0)
open_flag |= O_CREAT;
- pdb = dbopen (TCFSPWDB, open_flag, PERM_SECURE, DB_HASH, NULL);
- if (!pdb)
+ pdb = dbopen (TCFSGPWDB, open_flag, PERM_SECURE, DB_HASH, NULL);
+ if (!pdb) {
+ perror("dbopen");
return 0;
+ }
key = (char *) calloc (strlen(src->user) + 4 + 1, sizeof(char));
sprintf (key, "%s\33%d\0", src->user, src->gid);
diff --git a/usr.bin/tcfs/tcfs_keymaint.c b/usr.bin/tcfs/tcfs_keymaint.c
index 486804ee979..f4df15f36c5 100644
--- a/usr.bin/tcfs/tcfs_keymaint.c
+++ b/usr.bin/tcfs/tcfs_keymaint.c
@@ -59,7 +59,7 @@ tcfs_decrypt_key (char *u, char *pwd, unsigned char *t, unsigned char *tk,
{
int i = 0;
char pass[_PASSWORD_LEN], *cypher;
- char tcfskey[KEYSIZE + 2];
+ char tcfskey[2*KEYSIZE];
des_key_schedule ks;
int keysize = (flag == GROUPKEY) ? KEYSIZE + KEYSIZE/8 : KEYSIZE;
@@ -68,8 +68,10 @@ tcfs_decrypt_key (char *u, char *pwd, unsigned char *t, unsigned char *tk,
strcpy (pass, pwd);
- if (uudecode ((char *)t, tcfskey, sizeof(tcfskey)) == -1)
+ if (uudecode ((char *)t, tcfskey, sizeof(tcfskey)) == -1) {
+ fprintf(stderr, "tcfs_decrypt_key: uudecode failed\n");
return 0;
+ }
while (strlen (pass) < 8) {
char tmp[_PASSWORD_LEN];
@@ -99,6 +101,8 @@ tcfs_encrypt_key (char *u, char *pw, unsigned char *key, unsigned char *ek,
char pass[_PASSWORD_LEN];
des_key_schedule ks;
int keysize = (flag == GROUPKEY) ? KEYSIZE + KEYSIZE/8 : KEYSIZE;
+ int uulen = (flag == GROUPKEY) ? UUGKEYSIZE : UUKEYSIZE;
+ int res;
if (!ek)
return 0;
@@ -120,12 +124,17 @@ tcfs_encrypt_key (char *u, char *pw, unsigned char *key, unsigned char *ek,
i++;
}
- uuencode (key, keysize, ek, UUKEYSIZE);
+ res = uuencode (key, keysize, ek, uulen + 1);
+ if (res != uulen) {
+ fprintf(stderr, "tcfs_encrypt_key: uuencode length wrong\n");
+ return (0);
+ }
return 1;
}
-int tcfs_user_enable(char *filesystem, uid_t user, u_char *key)
+int
+tcfs_user_enable(char *filesystem, uid_t user, u_char *key)
{
struct tcfs_args a;
a.user = user;
@@ -134,7 +143,8 @@ int tcfs_user_enable(char *filesystem, uid_t user, u_char *key)
return tcfs_callfunction(filesystem,&a);
}
-int tcfs_user_disable(char *filesystem, uid_t user)
+int
+tcfs_user_disable(char *filesystem, uid_t user)
{
struct tcfs_args a;
a.user = user;
@@ -142,7 +152,8 @@ int tcfs_user_disable(char *filesystem, uid_t user)
return tcfs_callfunction(filesystem, &a);
}
-int tcfs_proc_enable(char *filesystem, uid_t user, pid_t pid, char *key)
+int
+tcfs_proc_enable(char *filesystem, uid_t user, pid_t pid, char *key)
{
struct tcfs_args a;
a.user = user;
@@ -152,7 +163,8 @@ int tcfs_proc_enable(char *filesystem, uid_t user, pid_t pid, char *key)
return tcfs_callfunction(filesystem, &a);
}
-int tcfs_proc_disable(char *filesystem, uid_t user, pid_t pid)
+int
+tcfs_proc_disable(char *filesystem, uid_t user, pid_t pid)
{
struct tcfs_args a;
a.user = user;
@@ -161,8 +173,9 @@ int tcfs_proc_disable(char *filesystem, uid_t user, pid_t pid)
return tcfs_callfunction(filesystem, &a);
}
-int tcfs_group_enable(char *filesystem, uid_t uid, gid_t gid,
- int tre, char *key)
+int
+tcfs_group_enable(char *filesystem, uid_t uid, gid_t gid,
+ int tre, char *key)
{
struct tcfs_args a;
a.cmd = TCFS_PUT_GIDKEY;
diff --git a/usr.bin/tcfs/tcfsaddgroup.c b/usr.bin/tcfs/tcfsaddgroup.c
index d9e850b08ab..7c81ba3cd18 100644
--- a/usr.bin/tcfs/tcfsaddgroup.c
+++ b/usr.bin/tcfs/tcfsaddgroup.c
@@ -222,7 +222,7 @@ addgroup_main (int argn, char *argv[])
printf ("Group id [or name] of the TCFS group to add to the database: ");
fgets (buff, 2048, stdin);
- len = strlen(buff) - 2;
+ len = strlen(buff) - 1;
buff[len] = buff[len] == '\n' ? 0 : buff[len];
gid = atoi(buff);
@@ -233,7 +233,7 @@ addgroup_main (int argn, char *argv[])
if (!group_id)
tcfs_error (ER_CUSTOM, "Nonexistent group.");
- gid=group_id->gr_gid;
+ gid = group_id->gr_gid;
}
if (gid <= 0)
@@ -252,7 +252,7 @@ addgroup_main (int argn, char *argv[])
printf ("Number of members for the TCFS group ID #%d: ", gid);
fgets (buff, 2048, stdin);
- len = strlen(buff) - 2;
+ len = strlen(buff) - 1;
buff[len] = buff[len] == '\n' ? 0 : buff[len];
members = atoi(buff);
@@ -269,7 +269,7 @@ addgroup_main (int argn, char *argv[])
printf ("Threshold for the TCFS group ID #%d: ", gid);
fgets (buff, 2048, stdin);
- len = strlen(buff) - 2;
+ len = strlen(buff) - 1;
buff[len] = buff[len] == '\n' ? 0 : buff[len];
threshold = atoi(buff);
@@ -339,26 +339,16 @@ addgroup_main (int argn, char *argv[])
strcpy (group_info[members-1]->user, user);
- newkey = (unsigned char*)calloc(KEYSIZE*2, sizeof (char));
+ newkey = (unsigned char*)calloc(GKEYSIZE + 1, sizeof (char));
if (!newkey)
tcfs_error (ER_MEM, NULL);
- cryptedkey = (unsigned char*)calloc(UUKEYSIZE, sizeof(char));
+ cryptedkey = (unsigned char*)calloc(UUGKEYSIZE, sizeof(char));
if (!cryptedkey)
tcfs_error (ER_MEM, NULL);
- memcpy (newkey, gengrpkey (user), KEYSIZE + KEYSIZE/8);
- newkey[KEYSIZE + KEYSIZE/8] = '\0';
-#ifdef DEBUG_TCFS
- {
- int i;
-
- printf ("%s newkey: ", user);
- for (i = 0;i <= KEYSIZE; i++)
- printf ("%u:", newkey[i]);
- printf ("\n");
- }
-#endif
+ memcpy (newkey, gengrpkey (user), GKEYSIZE);
+ newkey[GKEYSIZE] = '\0';
/*
* Encrypt the just generated key with the user password
@@ -366,39 +356,25 @@ addgroup_main (int argn, char *argv[])
if (!tcfs_encrypt_key (user, passwd, newkey, cryptedkey, GROUPKEY))
tcfs_error (ER_MEM, NULL);
-#ifdef DEBUG_TCFS
- {
- unsigned char *key;
- int i;
-
- key=(unsigned char *)calloc(UUKEYSIZE, sizeof(char));
- if (!tcfs_decrypt_key (user, passwd, cryptedkey, key, GROUPKEY))
- exit (0);
-
- printf ("%s key: ", user);
- for (i=0;i<=KEYSIZE;i++)
- printf ("%u:", key[i]);
- printf ("\n");
-
- free (key);
- }
-#endif
-
free (newkey);
- strcpy (group_info[members-1]->gkey, cryptedkey);
+ strlcpy (group_info[members - 1]->gkey, cryptedkey,
+ GKEYSIZE + 1);
free (cryptedkey);
members--;
}
- members=temp_members;
+ members = temp_members;
while (members) {
if (be_verbose)
- printf ("Creating a new entry for user %s in the TCFS database...\n", group_info[members-1]->user);
+ printf ("Creating a new entry for group %d and user %s in the TCFS database...\n",
+ group_info[members-1]->gid,
+ group_info[members-1]->user);
- if (!tcfs_gputpwnam (group_info[members-1]->user, group_info[members-1], U_NEW)) {
+ if (!tcfs_gputpwnam (group_info[members-1]->user,
+ group_info[members-1], U_NEW)) {
/* TODO: Remove the group entries saved before */
tcfs_error (ER_CUSTOM, "Error: cannot add a user to the group.");
}
diff --git a/usr.bin/tcfs/tcfsdefines.h b/usr.bin/tcfs/tcfsdefines.h
index 1841bd5a2de..28dc9d526e9 100644
--- a/usr.bin/tcfs/tcfsdefines.h
+++ b/usr.bin/tcfs/tcfsdefines.h
@@ -14,6 +14,8 @@
#define _TCFSDEFINES_H_
#define UUKEYSIZE ((KEYSIZE / 3 + (KEYSIZE % 3 ? 1 : 0)) * 4)
+#define GKEYSIZE (KEYSIZE + KEYSIZE/8)
+#define UUGKEYSIZE ((GKEYSIZE / 3 + (GKEYSIZE % 3 ? 1 : 0)) * 4)
#define TRUE 1
#define FALSE 0
#define ONE 1 /* decrement key counter by 1 */
diff --git a/usr.bin/tcfs/tcfspwdb.h b/usr.bin/tcfs/tcfspwdb.h
index 899b37ebf22..01f5b581eff 100644
--- a/usr.bin/tcfs/tcfspwdb.h
+++ b/usr.bin/tcfs/tcfspwdb.h
@@ -26,14 +26,14 @@
typedef struct tcfspwdb_r
{
- char user[UserLen];
- char upw[PassLen];
+ char user[LOGIN_NAME_MAX];
+ char upw[UUKEYSIZE + 1];
} tcfspwdb;
typedef struct tcfsgpwdb_r
{
- char user[UserLen];
- char gkey[PassLen];
+ char user[LOGIN_NAME_MAX];
+ char gkey[UUGKEYSIZE + 1];
gid_t gid;
int n;
int soglia;
diff --git a/usr.bin/tcfs/tcfsrmgroup.c b/usr.bin/tcfs/tcfsrmgroup.c
index a41b983d183..4081e03fb91 100644
--- a/usr.bin/tcfs/tcfsrmgroup.c
+++ b/usr.bin/tcfs/tcfsrmgroup.c
@@ -73,7 +73,7 @@ rmgroup_main (int argn, char *argv[])
printf ("Group id of the TCFS group to remove from the database: ");
fgets (buff,2048,stdin);
- len = strlen(buff) - 2;
+ len = strlen(buff) - 1;
buff[len] = buff[len] == '\n' ? 0 : buff[len];
gid=(gid_t)atoi(buff);