Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
int do_ls0(char *argv[])
{
    init_ls();
    int retval = hw3_ops.readdir(get_cwd(), NULL, filler, 0, NULL);
    print_ls();
    return retval;
}
Ejemplo n.º 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;
}
Ejemplo n.º 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;
}