{
int fd;
- fd = open(filename, flags);
+ fd = open(filename, flags, 0600);
return fd;
}
return buffer;
}
+/* Returns files size. Returns 0 on error. */
+
+uint64 silc_file_size(const char *filename)
+{
+ int ret;
+ struct stat stats;
+
+#ifndef SILC_WIN32\r
+ ret = lstat(filename, &stats);
+#else\r
+ ret = stat(filename, &stats);\r
+#endif\r
+ if (ret < 0)\r
+ return 0;\r
+
+ return (uint64)stats.st_size;
+}
+
/* Gets line from a buffer. Stops reading when a newline or EOF occurs.
This doesn't remove the newline sign from the destination buffer. The
argument begin is returned and should be passed again for the function. */
if (server_id->ip.data_len > 4) {
} else {
- SILC_GET32_MSB(ipv4.s_addr, server_id->ip.data);
+ memcpy(&ipv4.s_addr, server_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
if (client_id->ip.data_len > 4) {
} else {
- SILC_GET32_MSB(ipv4.s_addr, client_id->ip.data);
+ memcpy(&ipv4.s_addr, client_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
if (channel_id->ip.data_len > 4) {
} else {
- SILC_GET32_MSB(ipv4.s_addr, channel_id->ip.data);
+ memcpy(&ipv4.s_addr, channel_id->ip.data, 4);
strcat(rid, inet_ntoa(ipv4));
}
return strdup(string);
}
+
+/* Creates fingerprint from data, usually used with SHA1 digests */
+
+char *silc_fingerprint(const unsigned char *data, uint32 data_len)
+{
+ char fingerprint[64], *cp;
+ int i;
+
+ memset(fingerprint, 0, sizeof(fingerprint));
+ cp = fingerprint;
+ for (i = 0; i < data_len; i++) {
+ snprintf(cp, sizeof(fingerprint), "%02X", data[i]);
+ cp += 2;
+
+ if ((i + 1) % 2 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+
+ if ((i + 1) % 10 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+ }
+ i--;
+ if ((i + 1) % 2 == 0)
+ cp[-2] = 0;
+ if ((i + 1) % 10 == 0)
+ cp[-1] = 0;
+
+ return strdup(fingerprint);
+}