Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 90924 | Differences between
and this patch

Collapse All | Expand All

(-)dchroot.c.old (-51 / +49 lines)
Lines 199-213 Link Here
199
		return -1;
199
		return -1;
200
	} else if (pid == 0) {
200
	} else if (pid == 0) {
201
201
202
		if (!argv) {
202
    int cmdnum = 0;
203
			/* Will execute a shell in the new chroot. */
203
    int argc = 0;
204
204
205
			cmd = malloc(sizeof(char *) * 4);
205
    /* estimate length of command list to su */
206
		if (!argv) {
207
      argc = 4;
208
		} else {
209
			while (argv[argc] != NULL) {
210
        argc++;
211
      }
212
      argc += 5;
213
    }
214
    cmd = malloc(sizeof(char *) * argc);
215
216
    if (!cmd) {
217
      dchroot_perror("malloc");
218
      exit(EXIT_FAILURE);
219
    }
220
221
    cmd[cmdnum++] = "/bin/su";
222
223
    if (opts.dir[0] == '\0') {
224
      /* /bin/su, -, username, ... */
225
      cmd[cmdnum++] = "-";
226
    } else {
227
#ifdef WITH_GNU_SU
228
      /* /bin/su, -p, username, ... */
229
      cmd[cmdnum++] = "-p";
230
#endif
231
      /* /bin/su, username, ... */
232
      /* su from shadow package doesn't know about -p option. */
233
    }
234
    cmd[cmdnum++] = username;
206
235
207
			if (!cmd) {
236
		if (!argv) {
208
				dchroot_perror("malloc");
237
			/* Will execute a shell in the new chroot. */
209
				exit(EXIT_FAILURE);
210
			}
211
238
212
			if (!opts.quiet) {
239
			if (!opts.quiet) {
213
				printf("Executing shell in '%s' chroot.\n",
240
				printf("Executing shell in '%s' chroot.\n",
Lines 215-275 Link Here
215
				fflush(NULL);
242
				fflush(NULL);
216
			}
243
			}
217
244
218
			cmd[0] = "/bin/su";
245
			cmd[cmdnum++] = NULL;
219
220
			if (opts.dir[0] == '\0') {
221
				/* /bin/su, -, username, NULL */
222
				cmd[1] = "-";
223
			} else {
224
				/* /bin/su, -p, username, NULL */
225
				cmd[1] = "-p";
226
			}
227
			cmd[2] = username;
228
			cmd[3] = NULL;
229
246
230
		} else {
247
		} else {
231
			/* Will execute the command in argv[] in the
248
			/* Will execute the commands in argv[] in the
232
			 * new chroot. 
249
			 * new chroot. 
233
			 */
250
			 */
234
251
235
			int argc = 0;
252
			int i = 0;
236
			int i = 0, j = 0;
253
      int shcmdstart = 0;
237
			
254
			
238
			while (argv[i++] != NULL) {
255
#ifdef WITH_GNU_SU
239
				argc++;
256
      /* prevent gnu su from grabbing options inteded for the shell */
240
			}
257
			cmd[cmdnum++] = "--";
241
			
258
#endif
242
			cmd = malloc(sizeof(char *) * (argc + 5));
259
243
			
260
      shcmdstart = cmdnum + 1;
244
			if (!cmd) {
261
			while (argv[i] != NULL) {
245
				dchroot_perror("malloc");
262
				cmd[cmdnum++] = argv[i];
246
				exit(EXIT_FAILURE);
263
				i++;
247
			}
248
		
249
			i = 0;
250
			cmd[i++] = "/bin/su";
251
			
252
			if (opts.dir[0] == '\0') {
253
				/* /bin/su - username argv[0] argv[1] ... */
254
				cmd[i++] = "-";
255
			} else {
256
				/* /bin/su -p username argv[0] argv[1] ... */
257
				cmd[i++] = "-p";
258
			}
259
			
260
			cmd[i++] = username;
261
			cmd[i++] = "--";
262
263
			while (argv[j] != NULL) {
264
				cmd[i++] = argv[j];
265
				j++;
266
			}
264
			}
267
265
268
			cmd[i] = NULL;
266
			cmd[cmdnum] = NULL;
269
267
270
			if (!opts.quiet) {
268
			if (!opts.quiet) {
271
				printf("(%s) ", chroot_to->name);
269
				printf("(%s) ", chroot_to->name);
272
				i = 4;
270
				i = shcmdstart;
273
				while (cmd[i]) {
271
				while (cmd[i]) {
274
					printf("%s ", cmd[i]);
272
					printf("%s ", cmd[i]);
275
					i++;
273
					i++;

Return to bug 90924