Skip to content

Commit 50c3601

Browse files
committed
Adds TmpDiskHelper and uses SMBless to assume root access for TmpFS
1 parent c9cf4d8 commit 50c3601

20 files changed

+1345
-122
lines changed

Common/Constants.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Constants.swift
3+
// TmpDiskHelper
4+
//
5+
// Created by Tim on 2/28/24.
6+
//
7+
8+
import Foundation
9+
10+
struct Constant {
11+
static let helperMachLabel = "com.imothee.TmpDiskHelper"
12+
}
13+
14+
enum TmpDiskError: Error {
15+
case noName
16+
case exists
17+
case invalidSize
18+
case failed
19+
case helperNotInstalled
20+
}

Common/Protocols.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// Protocols.swift
3+
// TmpDiskHelper
4+
//
5+
// Created by Tim on 2/28/24.
6+
//
7+
8+
import Foundation
9+
10+
@objc protocol TmpDiskCreator {
11+
func createTmpDisk(_ command: String)
12+
func uninstall()
13+
}
14+
15+
@objc public protocol TmpDiskClient {
16+
func tmpDiskCreated(_ success: Bool)
17+
}

Common/TmpDiskVolume.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// TmpDiskVolume.swift
3+
// TmpDisk
4+
//
5+
// Created by Tim on 2/28/24.
6+
//
7+
8+
import Foundation
9+
10+
struct TmpDiskVolume: Hashable, Codable {
11+
var name: String = ""
12+
var size: Int = 16
13+
var autoCreate: Bool = false
14+
var indexed: Bool = false
15+
var hidden: Bool = false
16+
var tmpFs: Bool = false
17+
var caseSensitive: Bool = false
18+
var journaled: Bool = false
19+
var warnOnEject: Bool = false
20+
var folders: [String] = []
21+
var icon: String?
22+
23+
func path() -> String {
24+
if tmpFs {
25+
return "\(TmpDiskManager.rootFolder)/\(name)"
26+
}
27+
return "/Volumes/\(name)"
28+
}
29+
30+
func URL() -> URL {
31+
return NSURL.fileURL(withPath: self.path())
32+
}
33+
34+
func dictionary() -> Dictionary<String, Any> {
35+
return [
36+
"name": name,
37+
"size": size,
38+
"indexed": indexed,
39+
"hidden": hidden,
40+
"tmpFs": tmpFs,
41+
"caseSensitive": caseSensitive,
42+
"journaled": journaled,
43+
"warnOnEject": warnOnEject,
44+
"folders": folders,
45+
"icon": icon ?? "",
46+
]
47+
}
48+
49+
func showWarning() -> Bool {
50+
if warnOnEject {
51+
if let files = try? FileManager.default.contentsOfDirectory(atPath: self.path()) {
52+
if !files.filter({ ![".DS_Store", ".tmpdisk", ".fseventsd"].contains($0) }).isEmpty {
53+
return true
54+
}
55+
}
56+
}
57+
return false
58+
}
59+
}

TmpDisk.xcodeproj/project.pbxproj

Lines changed: 217 additions & 9 deletions
Large diffs are not rendered by default.

TmpDisk/AppDelegate.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6363
if isRunning {
6464
DistributedNotificationCenter.default().post(name: .killLauncher, object: Bundle.main.bundleIdentifier!)
6565
}
66+
67+
// Check the helper status
68+
checkHelperStatus()
6669
}
6770

6871
func applicationWillTerminate(_ aNotification: Notification) {
@@ -96,5 +99,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
9699
}
97100
return (name, size)
98101
}
102+
103+
// Check if the helper is installed, if it is check if it needs to be updated
104+
private func checkHelperStatus() {
105+
if let build = Util.checkHelperVersion() {
106+
if let newestHelperVersion = Util.latestEmbeddedHelperVersion() {
107+
if newestHelperVersion > build {
108+
Util.installHelper(update: true)
109+
}
110+
}
111+
}
112+
}
99113
}
100114

TmpDisk/Base.lproj/Main.storyboard

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -800,9 +800,9 @@
800800
</connections>
801801
</stepper>
802802
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="fEV-yb-Se2">
803-
<rect key="frame" x="193" y="184" width="226" height="18"/>
803+
<rect key="frame" x="193" y="184" width="341" height="18"/>
804804
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
805-
<buttonCell key="cell" type="check" title="Use TmpFS (Needs Root Access)" bezelStyle="regularSquare" imagePosition="left" inset="2" id="xBA-Ze-bf2">
805+
<buttonCell key="cell" type="check" title="Use TmpFS (Needs Root Access or Helper Installed)" bezelStyle="regularSquare" imagePosition="left" inset="2" id="xBA-Ze-bf2">
806806
<behavior key="behavior" changeContents="YES" doesNotDimImage="YES" lightByContents="YES"/>
807807
<font key="font" metaFont="system"/>
808808
</buttonCell>
@@ -1043,11 +1043,11 @@
10431043
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
10441044
<prototypeCellViews>
10451045
<tableCellView id="JML-g3-qvT">
1046-
<rect key="frame" x="190" y="0.0" width="401" height="24"/>
1046+
<rect key="frame" x="190" y="0.0" width="900" height="24"/>
10471047
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
10481048
<subviews>
10491049
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="DfW-y0-Gzf">
1050-
<rect key="frame" x="0.0" y="4" width="401" height="16"/>
1050+
<rect key="frame" x="0.0" y="4" width="900" height="16"/>
10511051
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
10521052
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="t3z-IH-wJR">
10531053
<font key="font" usesAppearanceFont="YES"/>
@@ -1078,11 +1078,11 @@
10781078
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
10791079
<prototypeCellViews>
10801080
<tableCellView id="m4U-hC-HcX">
1081-
<rect key="frame" x="289" y="0.0" width="475" height="24"/>
1081+
<rect key="frame" x="289" y="0.0" width="974" height="24"/>
10821082
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
10831083
<subviews>
10841084
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" horizontalCompressionResistancePriority="250" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5ZJ-fg-CTz">
1085-
<rect key="frame" x="0.0" y="4" width="475" height="16"/>
1085+
<rect key="frame" x="0.0" y="4" width="974" height="16"/>
10861086
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
10871087
<textFieldCell key="cell" lineBreakMode="truncatingTail" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" title="Table View Cell" id="qXn-wF-aJV">
10881088
<font key="font" usesAppearanceFont="YES"/>
@@ -1561,16 +1561,25 @@
15611561
<autoresizingMask key="autoresizingMask"/>
15621562
<subviews>
15631563
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="6XO-mK-bhq">
1564-
<rect key="frame" x="32" y="141" width="120" height="16"/>
1564+
<rect key="frame" x="32" y="131" width="120" height="16"/>
15651565
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
15661566
<textFieldCell key="cell" lineBreakMode="clipping" title="TmpFS Root Folder" id="q71-xV-gGa">
15671567
<font key="font" metaFont="system"/>
15681568
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
15691569
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
15701570
</textFieldCell>
15711571
</textField>
1572+
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="YiI-JV-ocs">
1573+
<rect key="frame" x="32" y="223" width="97" height="16"/>
1574+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
1575+
<textFieldCell key="cell" lineBreakMode="clipping" title="TmpDiskHelper" id="gwG-L6-BAO">
1576+
<font key="font" metaFont="system"/>
1577+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
1578+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
1579+
</textFieldCell>
1580+
</textField>
15721581
<textField focusRingType="none" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="4os-jd-sv5">
1573-
<rect key="frame" x="191" y="138" width="243" height="21"/>
1582+
<rect key="frame" x="191" y="128" width="243" height="21"/>
15741583
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
15751584
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" placeholderString="~/.tmpdisk/volumes" drawsBackground="YES" id="fMk-fB-fMf">
15761585
<font key="font" metaFont="system"/>
@@ -1590,18 +1599,55 @@
15901599
</connections>
15911600
</button>
15921601
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="pJA-9b-PqG">
1593-
<rect key="frame" x="83" y="48" width="332" height="82"/>
1602+
<rect key="frame" x="83" y="60" width="332" height="60"/>
15941603
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES"/>
15951604
<textFieldCell key="cell" alignment="center" title="Change where your TmpFS mount points sit. Must be changed when you have no TmpFS volumes mounted." id="EYH-BL-kNS">
15961605
<font key="font" metaFont="system"/>
15971606
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
15981607
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
15991608
</textFieldCell>
16001609
</textField>
1610+
<textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" id="GJg-c6-PtQ">
1611+
<rect key="frame" x="91" y="167" width="299" height="48"/>
1612+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES"/>
1613+
<textFieldCell key="cell" alignment="center" id="LLv-lK-dgg">
1614+
<font key="font" metaFont="system"/>
1615+
<string key="title">Installing the TmpDiskCreator Helper can install TmpFS TmpDisks without asking for your root password. Requires Admin password to install</string>
1616+
<color key="textColor" name="secondaryLabelColor" catalog="System" colorSpace="catalog"/>
1617+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
1618+
</textFieldCell>
1619+
</textField>
1620+
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="wBV-Uc-oE8">
1621+
<rect key="frame" x="171" y="214" width="130" height="32"/>
1622+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
1623+
<buttonCell key="cell" type="push" title="Update Helper" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="oIz-aS-Ulv">
1624+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
1625+
<font key="font" metaFont="system"/>
1626+
</buttonCell>
1627+
<connections>
1628+
<action selector="updateHelper:" target="p4y-fC-51t" id="c6K-CR-6bi"/>
1629+
</connections>
1630+
</button>
1631+
<segmentedControl verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="9gP-Eq-qKM">
1632+
<rect key="frame" x="346" y="220" width="73" height="24"/>
1633+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
1634+
<segmentedCell key="cell" borderStyle="border" alignment="left" style="rounded" trackingMode="selectOne" id="pt1-DY-kC4">
1635+
<font key="font" metaFont="system"/>
1636+
<segments>
1637+
<segment label="Off" width="32" selected="YES"/>
1638+
<segment label="On" width="32" tag="1"/>
1639+
</segments>
1640+
</segmentedCell>
1641+
<connections>
1642+
<action selector="toggleHelper:" target="p4y-fC-51t" id="f2P-mU-U81"/>
1643+
</connections>
1644+
</segmentedControl>
16011645
</subviews>
16021646
</view>
16031647
<connections>
16041648
<outlet property="rootFolder" destination="4os-jd-sv5" id="8FX-qI-mrd"/>
1649+
<outlet property="updateHelper" destination="wBV-Uc-oE8" id="m68-tp-OvY"/>
1650+
<outlet property="useHelper" destination="9gP-Eq-qKM" id="VgN-g2-lQI"/>
16051651
</connections>
16061652
</viewController>
16071653
<customObject id="L85-zs-ndx" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>

TmpDisk/Info.plist

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5-
<key>LSUIElement</key>
6-
<true/>
5+
<key>SMPrivilegedExecutables</key>
6+
<dict>
7+
<key>com.imothee.TmpDiskHelper</key>
8+
<string>identifier "com.imothee.TmpDiskHelper" and anchor apple generic and certificate leaf[subject.CN] = "Apple Development: Timothy Marks (R824A4SSXM)" and certificate 1[field.1.2.840.113635.100.6.2.1] /* exists */</string>
9+
</dict>
710
<key>SUEnableSystemProfiling</key>
811
<true/>
912
<key>SUFeedURL</key>
@@ -12,5 +15,7 @@
1215
<string>dsa_pub.pem</string>
1316
<key>SUPublicEDKey</key>
1417
<string>cHYVa9jmyIHtzvsj9w8WQ/L19rbBklLx75GNou5ipjw=</string>
18+
<key>TmpDiskHelperVersion</key>
19+
<string>1</string>
1520
</dict>
1621
</plist>

0 commit comments

Comments
 (0)