Use hcrypto for kernel md5
[openafs.git] / src / afs / afs_cell.c
index 9b3fd9a..03ed2c3 100644 (file)
@@ -19,7 +19,7 @@
 #include "afsincludes.h"       /* Afs-based standard headers */
 #include "afs/afs_stats.h"     /* afs statistics */
 #include "afs/afs_osi.h"
-#include "afs/afs_md5.h"
+#include "hcrypto/md5.h"
 
 /* Local variables. */
 afs_rwlock_t afs_xcell;                /* Export for cmdebug peeking at locks */
@@ -229,7 +229,8 @@ afs_cellname_new(char *name, afs_int32 cellnum)
     if (cellnum == 0)
        cellnum = afs_cellnum_next;
 
-    cn = (struct cell_name *)afs_osi_Alloc(sizeof(*cn));
+    cn = afs_osi_Alloc(sizeof(*cn));
+    osi_Assert(cn != NULL);
     cn->next = afs_cellname_head;
     cn->cellnum = cellnum;
     cn->cellname = afs_strdup(name);
@@ -511,7 +512,8 @@ afs_NewCellAlias(char *alias, char *cell)
     }
 
     UpgradeSToWLock(&afs_xcell, 682);
-    tc = (struct cell_alias *)afs_osi_Alloc(sizeof(struct cell_alias));
+    tc = afs_osi_Alloc(sizeof(struct cell_alias));
+    osi_Assert(tc != NULL);
     tc->alias = afs_strdup(alias);
     tc->cell = afs_strdup(cell);
     tc->next = afs_cellalias_head;
@@ -830,6 +832,24 @@ afs_GetPrimaryCell(afs_int32 locktype)
 }
 
 /*!
+ * Return number of the primary cell.
+ * \return
+ *    Cell number, or 0 if primary cell not found
+ */
+afs_int32
+afs_GetPrimaryCellNum(void)
+{
+    struct cell *cell;
+    afs_int32 cellNum = 0;
+    cell = afs_GetPrimaryCell(READ_LOCK);
+    if (cell) {
+       cellNum = cell->cellNum;
+       afs_PutCell(cell, READ_LOCK);
+    }
+    return cellNum;
+}
+
+/*!
  * Returns true if the given cell is the primary cell.
  * \param cell
  * \return
@@ -904,6 +924,7 @@ afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
 {
     struct cell *tc, *tcl = 0;
     afs_int32 i, newc = 0, code = 0;
+    struct md5 m;
 
     AFS_STATCNT(afs_NewCell);
 
@@ -913,12 +934,15 @@ afs_NewCell(char *acellName, afs_int32 * acellHosts, int aflags,
     if (tc) {
        aflags &= ~CNoSUID;
     } else {
-       tc = (struct cell *)afs_osi_Alloc(sizeof(struct cell));
+       tc = afs_osi_Alloc(sizeof(struct cell));
+       osi_Assert(tc != NULL);
        memset(tc, 0, sizeof(*tc));
        tc->cellName = afs_strdup(acellName);
        tc->fsport = AFS_FSPORT;
        tc->vlport = AFS_VLPORT;
-       AFS_MD5_String(tc->cellHandle, tc->cellName, strlen(tc->cellName));
+       MD5_Init(&m);
+       MD5_Update(&m, tc->cellName, strlen(tc->cellName));
+       MD5_Final(tc->cellHandle, &m);
        AFS_RWLOCK_INIT(&tc->lock, "cell lock");
        newc = 1;
        aflags |= CNoSUID;