util  Diff

Differences From Artifact [d671829e71]:

To Artifact [f1f30ece5b]:


7
8
9
10
11
12
13





14
15
16
17
18
19
20
..
43
44
45
46
47
48
49


50
51
52
53
54
55
56
...
195
196
197
198
199
200
201
202

203
204
205
206
207
208
209
...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
 *      does this by attempting to execute a sequence
 *      of binaries, and then writing the password
 *      to STDIN of the binary that succeeds.
 *  ? generates passwords
 *  → mkpw is unlikely to be portable to non-POSIX
 *    systems, but should run fine on Linux as well
 *    as BSDs with getrandom() support.





 */

#include <unistd.h>
#include <sys/random.h>
#include <sys/syscall.h>
#include <stddef.h>
#include <stdint.h>
................................................................................

typedef enum bad {
	ok = 0,
	fail = 1,
	bad_user,
	bad_option,
	bad_syntax,


	bad_usage = 64, /* fleabsd idiom */
} bad;

typedef _Bool bool;
typedef unsigned long long iaia_word_type;
typedef bad iaia_error_type;
enum /* iaia errors */ {
................................................................................

	char buf[len+1];
	/* *buf = 0; */

	unsigned char noise[len];
	for (size_t i = 0; i<q; ++i) {
		unsigned char* cur = noise;
		syscall(SYS_getrandom, noise, len, 0);

		/* getrandom(noise, len, 0); // android doesnt like it */

		for(char* ptr = buf; ptr < buf + len; ++ptr, ++cur) {
			*ptr = tbl[*cur % chars]; /* such a waste of entropy… :( */
		}

		buf[len] = '\n';
................................................................................
			if (pipe(fds) != 0) return 63;
			if (!fork()) {
				close(fds[1]);
				dup2(fds[0], 0);
				if (clipboard_env != null) {
					execvp(clipboard_env, (char* const[]){
							clipboard_env, clipboard_env_arg, null});
					return -1;
				} else for(char* const** cmd = cbd_cmds; *cmd != null; ++cmd) {
					execvp((*cmd)[0], *cmd);
				}
				return -1; /* exec failed */
			} else {
				close(fds[0]);
				write(fds[1], buf, len);
				write(fds[1], "\n", 1);
				close(fds[1]);
			}
		}
#	endif
	
	return ok;
}







>
>
>
>
>







 







>
>







 







|
>







 







|



|











7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
 *      does this by attempting to execute a sequence
 *      of binaries, and then writing the password
 *      to STDIN of the binary that succeeds.
 *  ? generates passwords
 *  → mkpw is unlikely to be portable to non-POSIX
 *    systems, but should run fine on Linux as well
 *    as BSDs with getrandom() support.
 *  ! for getrandom() to work with the version of
 *    libc on my android phone, the getrandom() call
 *    had to be converted to use the syscall()
 *    interface. this is unlikely to cause problems,
 *    but should be kept in mind.
 */

#include <unistd.h>
#include <sys/random.h>
#include <sys/syscall.h>
#include <stddef.h>
#include <stdint.h>
................................................................................

typedef enum bad {
	ok = 0,
	fail = 1,
	bad_user,
	bad_option,
	bad_syntax,
	bad_entropy,
	bad_copy,
	bad_usage = 64, /* fleabsd idiom */
} bad;

typedef _Bool bool;
typedef unsigned long long iaia_word_type;
typedef bad iaia_error_type;
enum /* iaia errors */ {
................................................................................

	char buf[len+1];
	/* *buf = 0; */

	unsigned char noise[len];
	for (size_t i = 0; i<q; ++i) {
		unsigned char* cur = noise;
		if(syscall(SYS_getrandom, noise, len, 0) == -1)
			return bad_entropy;
		/* getrandom(noise, len, 0); // android doesnt like it */

		for(char* ptr = buf; ptr < buf + len; ++ptr, ++cur) {
			*ptr = tbl[*cur % chars]; /* such a waste of entropy… :( */
		}

		buf[len] = '\n';
................................................................................
			if (pipe(fds) != 0) return 63;
			if (!fork()) {
				close(fds[1]);
				dup2(fds[0], 0);
				if (clipboard_env != null) {
					execvp(clipboard_env, (char* const[]){
							clipboard_env, clipboard_env_arg, null});
					return bad_copy;
				} else for(char* const** cmd = cbd_cmds; *cmd != null; ++cmd) {
					execvp((*cmd)[0], *cmd);
				}
				return bad_copy; /* exec failed */
			} else {
				close(fds[0]);
				write(fds[1], buf, len);
				write(fds[1], "\n", 1);
				close(fds[1]);
			}
		}
#	endif
	
	return ok;
}