1/* 2 * Copyright (c) 2005-2007 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * modeUnbless.c 25 * bless 26 * 27 * Created by Shantonu Sen on 7/23/09. 28 * Copyright 2009 Apple Inc. All rights reserved. 29 * 30 */ 31 32 33#include <stdlib.h> 34#include <stdio.h> 35#include <unistd.h> 36#include <sys/stat.h> 37#include <sys/mount.h> 38#include <sys/param.h> 39 40#include "enums.h" 41#include "structs.h" 42 43#include "bless.h" 44#include "bless_private.h" 45#include "protos.h" 46 47int modeUnbless(BLContextPtr context, struct clarg actargs[klast]) { 48 49 int ret; 50 int isHFS; 51 52 struct statfs sb; 53 54 if (!actargs[kunbless].present) { 55 blesscontextprintf(context, kBLLogLevelError, "No volume specified\n" ); 56 return 1; 57 } 58 59 ret = BLGetCommonMountPoint(context, actargs[kunbless].argument, "", actargs[kmount].argument); 60 if(ret) { 61 blesscontextprintf(context, kBLLogLevelError, "Can't determine mount point of '%s'\n", actargs[kunbless].argument ); 62 } else { 63 blesscontextprintf(context, kBLLogLevelVerbose, "Mount point is '%s'\n", actargs[kmount].argument ); 64 } 65 66 ret = BLIsMountHFS(context, actargs[kmount].argument, &isHFS); 67 if(ret) { 68 blesscontextprintf(context, kBLLogLevelError, "Could not determine filesystem of %s\n", actargs[kmount].argument ); 69 return 1; 70 } 71 72 if(0 != statfs(actargs[kmount].argument, &sb)) { 73 blesscontextprintf(context, kBLLogLevelError, "Can't statfs %s\n" , 74 actargs[kmount].argument); 75 return 1; 76 } 77 78 79 if(isHFS) { 80 uint32_t oldwords[8]; 81 82 ret = BLGetVolumeFinderInfo(context, actargs[kmount].argument, oldwords); 83 if(ret) { 84 blesscontextprintf(context, kBLLogLevelError, "Error getting old Finder info words for %s\n", actargs[kmount].argument ); 85 return 1; 86 } 87 88 /* unbless! unbless */ 89 90 oldwords[0] = 0; 91 oldwords[1] = 0; 92 oldwords[2] = 0; 93 oldwords[3] = 0; 94 oldwords[4] = 0; 95 oldwords[5] = 0; 96 97 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[0] = %d\n", oldwords[0] ); 98 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[1] = %d\n", oldwords[1] ); 99 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[2] = %d\n", oldwords[2] ); 100 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[3] = %d\n", oldwords[3] ); 101 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[4] = %d\n", oldwords[4] ); 102 blesscontextprintf(context, kBLLogLevelVerbose, "finderinfo[5] = %d\n", oldwords[5] ); 103 104 105 if(geteuid() != 0 && geteuid() != sb.f_owner) { 106 blesscontextprintf(context, kBLLogLevelError, "Authorization required\n" ); 107 return 1; 108 } 109 110 ret = BLSetVolumeFinderInfo(context, actargs[kmount].argument, oldwords); 111 if(ret) { 112 blesscontextprintf(context, kBLLogLevelError, "Can't set Finder info fields for volume mounted at %s: %s\n", actargs[kmount].argument , strerror(errno)); 113 return 2; 114 } 115 116 } 117 118 return 0; 119} 120