Differences From
Artifact [c81247c932]:
40 40
41 41 #define options \
42 42 o('l',lower,mode = lower) \
43 43 o('m',mix,mode = mix) \
44 44 o('u',upper,mode = upper)\
45 45 _cl_opt
46 46
47 -enum /* constants */ {
48 - null = 0, true = 1, false = 0
49 -};
50 -
51 47 typedef enum bad {
52 48 ok = 0,
53 49 fail = 1,
54 50 bad_user,
55 51 bad_option,
56 52 bad_syntax,
57 53 bad_entropy,
58 54 bad_copy,
59 55 bad_usage = 64, /* fleabsd idiom */
60 56 } bad;
61 57
62 -typedef _Bool bool;
63 58 typedef unsigned long long iaia_word_type;
64 59 typedef bad iaia_error_type;
65 60 enum /* iaia errors */ {
66 61 iaia_e_ok = ok,
67 62 iaia_e_base = fail,
68 63 iaia_e_domain = fail,
69 64 iaia_e_overflow = fail,
................................................................................
98 93
99 94 #ifdef _CLIPBOARD
100 95 char* const* cbd_cmds[] = {
101 96 /* NOTE: these commands must be specified in order of
102 97 * most- to least-specific. more than one utility may
103 98 * be present on a given system, so we need to make sure
104 99 * the right one is called. */
105 - (char* const[]){"termux-clipboard-set", null},
106 - (char* const[]){"xsel", "-bi", null},
100 + (char* const[]){"termux-clipboard-set", nullptr},
101 + (char* const[]){"xsel", "-bi", nullptr},
107 102 /* TODO: allow command to be specified by env var */
108 - null
103 + nullptr
109 104 };
110 105 #endif
111 106 int main(int argc, const char** argv) {
112 107 if (argc == 0) return -1;
113 108 if (argc == 1) {
114 109 size_t namelen = strlen(argv[0]);
115 110 say("\x1b[1musage:\x1b[m ");
................................................................................
130 125 unsigned long long len, q = 1;
131 126 bool gotlen = false;
132 127 bool gotq = false;
133 128
134 129 # ifdef _CLIPBOARD
135 130 bool copy = true;
136 131 # endif
137 - for (const char** arg = argv; *arg != null; ++arg) {
132 + for (const char** arg = argv; *arg != nullptr; ++arg) {
138 133 if ((*arg)[0] == '-') {
139 134 if ((*arg)[1] == '-') { /* long opt */
140 135 unsigned char a;
141 136 if (tblget(sz(argtbl), argtbl, *arg + 2, &a) == ok) switch (a) {
142 137 # define o(short, long, code) case arg_##long:code;break;
143 138 options
144 139 # undef o
................................................................................
168 163 }
169 164 if (!gotlen) return bad_syntax;
170 165 # ifdef _CLIPBOARD
171 166 if (geteuid() == 0 && copy) {
172 167 /* on a sane system, what we'd do is hike up the process
173 168 * tree til we found a non-root user. alas, this is UNIX. */
174 169 const char* realuser = getenv("SUDO_USER");
175 - if (realuser == null) realuser = "nobody";
170 + if (realuser == nullptr) realuser = "nobody";
176 171
177 172 say("\x1b[1;33mwarning:\x1b[m you are running \x1b[4m");
178 173 size_t namelen = strlen(argv[0]);
179 174 write(2,argv[0],namelen);
180 175 say("\x1b[24m as \x1b[1mroot\x1b[m! dropping to \x1b[1m");
181 176 write(2,realuser,strlen(realuser));
182 177 setenv("USER", realuser, true);
183 178 say("\x1b[m to prevent malicious behavior\n");
184 179
185 180 struct passwd* nobody = getpwnam(realuser);
186 - if (nobody == null) {
181 + if (nobody == nullptr) {
187 182 say("\x1b[1;31mfatal:\x1b[m could not get UID to drop privileges; bailing");
188 183 return bad_user;
189 184 } else {
190 185 setenv("HOME", nobody -> pw_dir, true);
191 - setenv("SHELL", "/dev/null", true);
186 + setenv("SHELL", "/dev/nullptr", true);
192 187 setuid(nobody -> pw_uid);
193 188 if (geteuid() == 0)
194 189 say("\x1b[1;31mnice try:\x1b[m i don't fucking think so, you sneaky bastard");
195 190 }
196 191
197 192 }
198 193 # endif
................................................................................
228 223 char* const clipboard_env_arg = getenv("mkpw_clipboard_setter_arg");
229 224 // FIXME: allow multiple args
230 225 int fds[2];
231 226 if (pipe(fds) != 0) return 63;
232 227 if (!fork()) {
233 228 close(fds[1]);
234 229 dup2(fds[0], 0);
235 - if (clipboard_env != null) {
230 + if (clipboard_env != nullptr) {
236 231 execvp(clipboard_env, (char* const[]){
237 - clipboard_env, clipboard_env_arg, null});
232 + clipboard_env, clipboard_env_arg, nullptr});
238 233 return bad_copy;
239 - } else for(char* const** cmd = cbd_cmds; *cmd != null; ++cmd) {
234 + } else for(char* const** cmd = cbd_cmds; *cmd != nullptr; ++cmd) {
240 235 execvp((*cmd)[0], *cmd);
241 236 }
242 237 return bad_copy; /* exec failed */
243 238 } else {
244 239 close(fds[0]);
245 240 write(fds[1], buf, len);
246 241 write(fds[1], "\n", 1);