annotate dpid/misc_new.c @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents 6c8346ed1073
children 16e52ecf20a8
rev   line source
779
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
1 /*
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
2 * File: misc_new.c
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
3 *
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
4 * Copyright 2008 Jorge Arellano Cid <jcid@dillo.org>
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
5 *
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
6 * This program is free software; you can redistribute it and/or modify
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
7 * it under the terms of the GNU General Public License as published by
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
9 * (at your option) any later version.
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
10 */
49735e578039 [mq]: add-dpid-copyright
Jeremy Henty <onepoint@starurchin.org>
parents: 153
diff changeset
11
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
12 #include <errno.h> /* errno, err-codes */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
13 #include <unistd.h>
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
14 #include <time.h>
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
15 #include <sys/stat.h> /* stat */
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
16 #include <stdlib.h> /* rand, srand */
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
17
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
18 #include "../dlib/dlib.h"
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
19 #include "dpid_common.h"
1223
a09dbf132be6 Remove system includes for dpid
Jorge Arellano Cid <jcid@dillo.org>
parents: 1059
diff changeset
20 #include "misc_new.h" /* for function prototypes */
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
21
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
22
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
23 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
24 * Close a FD handling EINTR.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
25 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
26 int a_Misc_close_fd(int fd)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
27 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
28 int st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
29
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
30 do {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
31 st = close(fd);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
32 } while (st < 0 && errno == EINTR);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
33 return st;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
34 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
35
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
36 /*! Reads a dpi tag from a socket
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
37 * \li Continues after a signal interrupt
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
38 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
39 * Dstr pointer to tag on success, NULL on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
40 * \important Caller is responsible for freeing the returned Dstr *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
41 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
42 Dstr *a_Misc_rdtag(int socket)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
43 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
44 char c = '\0';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
45 ssize_t rdlen;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
46 Dstr *tag;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
47
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
48 tag = dStr_sized_new(64);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
49
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
50 errno = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
51
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
52 do {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
53 rdlen = read(socket, &c, 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
54 if (rdlen == -1 && errno != EINTR)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
55 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
56 dStr_append_c(tag, c);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
57 } while (c != '>');
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
58
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
59 if (rdlen == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
60 perror("a_Misc_rdtag");
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
61 dStr_free(tag, TRUE);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
62 return (NULL);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
63 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
64 return (tag);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
65 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
66
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
67 /*!
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
68 * Read a dpi tag from sock
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
69 * \return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
70 * pointer to dynamically allocated request tag
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
71 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
72 char *a_Misc_readtag(int sock)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
73 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
74 char *tag, c, buf[10];
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
75 size_t buflen, i;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
76 size_t taglen = 0, tagmem = 10;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
77 ssize_t rdln = 1;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
78
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
79 tag = NULL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
80 buf[0] = '\0';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
81 buflen = sizeof(buf) / sizeof(buf[0]);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
82 // new start
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
83 tag = (char *) dMalloc(tagmem + 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
84 for (i = 0; (rdln = read(sock, &c, 1)) != 0; i++) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
85 if (i == tagmem) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
86 tagmem += tagmem;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
87 tag = (char *) dRealloc(tag, tagmem + 1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
88 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
89 tag[i] = c;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
90 taglen += rdln;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
91 if (c == '>') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
92 tag[i + 1] = '\0';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
93 break;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
94 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
95 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
96 // new end
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
97 if (rdln == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
98 ERRMSG("a_Misc_readtag", "read", errno);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
99 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
100
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
101 return (tag);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
102 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
103
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
104 /*! Reads a dpi tag from a socket without hanging on read.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
105 * \li Continues after a signal interrupt
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
106 * \Return
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
107 * \li 1 on success
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
108 * \li 0 if input is not available within timeout microseconds.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
109 * \li -1 on failure
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
110 * \important Caller is responsible for freeing the returned Dstr *
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
111 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
112 /* Is this useful?
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
113 int a_Misc_nohang_rdtag(int socket, int timeout, Dstr **tag)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
114 {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
115 int n_fd;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
116 fd_set sock_set, select_set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
117 struct timeval tout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
118
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
119 FD_ZERO(&sock_set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
120 FD_SET(socket, &sock_set);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
121
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
122 errno = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
123 do {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
124 select_set = sock_set;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
125 tout.tv_sec = 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
126 tout.tv_usec = timeout;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
127 n_fd = select(socket + 1, &select_set, NULL, NULL, &tout);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
128 } while (n_fd == -1 && errno == EINTR);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
129
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
130 if (n_fd == -1) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
131 MSG_ERR("%s:%d: a_Misc_nohang_rdtag: %s\n",
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
132 __FILE__, __LINE__, dStrerror(errno));
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
133 return(-1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
134 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
135 if (n_fd == 0) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
136 return(0);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
137 } else {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
138 *tag = a_Misc_rdtag(socket);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
139 return(1);
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
140 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
141 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
142 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
143
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
144 /*
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
145 * Alternative to mkdtemp().
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
146 * Not as strong as mkdtemp, but enough for creating a directory.
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
147 */
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
148 char *a_Misc_mkdtemp(char *template)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
149 {
88
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
150 for (;;) {
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
151 if (a_Misc_mkfname(template) && mkdir(template, 0700) == 0)
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
152 break;
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
153 if (errno == EEXIST)
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
154 continue;
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
155 return 0;
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
156 }
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
157 return template;
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
158 }
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
159
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
160 /*
153
f175ca0f22be - Typo correction.
jcid
parents: 88
diff changeset
161 * Return a new, nonexistent file name from a template
88
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
162 * (adapted from dietlibc; alternative to mkdtemp())
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
163 */
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
164 char *a_Misc_mkfname(char *template)
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
165 {
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
166 char *tmp = template + strlen(template) - 6;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
167 int i;
1059
7bec6cfe6b6b Switched a few remaining "unsigned int" to "uint_t"
Jorge Arellano Cid <jcid@dillo.org>
parents: 779
diff changeset
168 uint_t random;
88
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
169 struct stat stat_buf;
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
170
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
171 if (tmp < template)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
172 goto error;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
173 for (i = 0; i < 6; ++i)
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
174 if (tmp[i] != 'X') {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
175 error:
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
176 errno = EINVAL;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
177 return 0;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
178 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
179 srand((uint_t)(time(0) ^ getpid()));
88
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
180
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
181 for (;;) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
182 random = (unsigned) rand();
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
183 for (i = 0; i < 6; ++i) {
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
184 int hexdigit = (random >> (i * 5)) & 0x1f;
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
185
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
186 tmp[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
187 }
88
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
188 if (stat(template, &stat_buf) == -1 && errno == ENOENT)
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
189 return template;
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
190
f1eca1aba94a - Removed a warning in dpi by adding a mkfname function.
jcid
parents: 0
diff changeset
191 MSG_ERR("a_Misc_mkfname: another round for %s \n", template);
0
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
192 }
6ee11bf9e3ea Initial revision
jcid
parents:
diff changeset
193 }
1384
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
194
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
195 /*
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
196 * Return a new, random hexadecimal string of 'nchar' characters.
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
197 */
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
198 char *a_Misc_mksecret(int nchar)
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
199 {
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
200 int i;
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
201 uint_t random;
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
202 char *secret = dNew(char, nchar + 1);
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
203
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
204 srand((uint_t)(time(0) ^ getpid()));
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
205 random = (unsigned) rand();
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
206 for (i = 0; i < nchar; ++i) {
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
207 int hexdigit = (random >> (i * 5)) & 0x0f;
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
208
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
209 secret[i] = hexdigit > 9 ? hexdigit + 'a' - 10 : hexdigit + '0';
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
210 }
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
211 secret[i] = 0;
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
212 MSG("a_Misc_mksecret: %s\n", secret);
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
213
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
214 return secret;
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
215 }
6c8346ed1073 Introduce basic shared-secret-based authentication
Jorge Arellano Cid <jcid@dillo.org>
parents: 1223
diff changeset
216