コード例 #1
0
ファイル: chown.c プロジェクト: CKost/Authorization
int
main(int argc, char **argv)
{
	if(argc != 3){
		printf(STDOUT, "Please give a file, and a User ID\nNo files Changed\n$ chown FILE USER_Number\n");
		exit();
	}
	if((int)*argv[2] == 63){
		uchown(argv[1],-1);
	}else{
		int x = uchown(argv[1], atoi(argv[2]));


		if(-1 == x){
			printf(1, "Error: File Name Invalid\n");
		}
		if(-2 == x){
			printf(1, "Error: Not a valid UID\n");
		}
		if (0 == x)
		{
			printf(STDOUT,"%s%s%s%s\n", "You changed ", argv[1], " to ", argv[2]);
		}
	}
	
 	 exit();

}
コード例 #2
0
ファイル: uchown.c プロジェクト: AtomSoftTech/retrobsd
int main(int argc, char *argv[])
{
    struct filesystem *f;
    int i;
    int mode;
    char temp[1024];
    char *cwd;
    char *fsname = getsetting("imagefile");;

    if (!fsname) {
        printf("Have you run ulogin?\n");
        return 10;
    }

    if (argc < 3) {
        printf("Usage: %s <uid> <file> ...\n", argv[0]);
        return 10;
    }

    sscanf(argv[1], "%o", &mode);
        
    f = fsopen(fsname);
    if (!f) {
        printf("Unable to open %s\n", fsname);
        return 10;
    }
    cwd = getsetting("cwd");
    for (i = 2; i < argc; i++) {
        if (argv[i][0] == '/') {
            uchown(f, argv[i], mode);
        } else {
            if (!cwd) {
                sprintf(temp, "/%s", argv[i]);
            } else {
                sprintf(temp, "%s/%s", cwd, argv[i]);
            }
            compresspath(temp);
            uchown(f, temp, mode);
        }
    }
    fsclose(f);
    if (cwd)
        free(cwd);
    free(fsname);
    return 0;
}