예제 #1
0
파일: su.c 프로젝트: phhusson/Superuser
static __attribute__ ((noreturn)) void allow_init(struct su_context *ctx) {
    if(ctx->init[0]=='!') {
        int ret = init_remove(ctx->init+1, ctx->from.uid);
        if(!ret) {
            fprintf(stderr, "The mentioned init path didn't exist\n");
            exit(1);
        }
        exit(0);
    }
    if(strcmp("--ls", ctx->init) == 0) {
        init_ls(ctx->from.uid);
        exit(0);
    }
    if(!init_uniq(ctx->init))
        //This script is already in init list
        exit(1);

	int fd = open("/data/su/init", O_WRONLY|O_APPEND|O_CREAT, 0600);
	if(fd<0) {
		fprintf(stderr, "Failed to open init file\n");
        exit(1);
	}
    char *str = NULL;
    int len = asprintf(&str, "%d:%s", ctx->from.uid, ctx->init);
    write(fd, str, len+1); //len doesn't include final \0 and we want to write it
    free(str);
	close(fd);
    exit(0);
}
예제 #2
0
int do_ls0(char *argv[])
{
    init_ls();
    int retval = hw3_ops.readdir(get_cwd(), NULL, filler, 0, NULL);
    print_ls();
    return retval;
}
예제 #3
0
int do_ls1(char *argv[])
{
    char path[128];
    sprintf(path, "%s/%s", get_cwd(), argv[0]);
    init_ls();
    int retval = hw3_ops.readdir(fix_path(path), NULL, filler, 0, NULL);
    print_ls();
    return retval;
}
예제 #4
0
int _lsdashl(char *path)
{
    struct stat sb;
    int retval = hw3_ops.getattr(path, &sb);
    if (retval == 0) {
	init_ls();
	if (S_ISDIR(sb.st_mode)) 
	    retval = hw3_ops.readdir(path, NULL, dashl_filler, 0, NULL);
	else
	    retval = dashl_filler(NULL, path, &sb, 0);
	print_ls();
    }
    return retval;
}