Skip to content

Commit 0940271

Browse files
committed
Add free-form text to qube for notes, comments, ...
Core and API part of adding free-form text to each qube for comments, notes, descriptions, remarks, reminders, etc. fixes: QubesOS/qubes-issues#899
1 parent 6828311 commit 0940271

4 files changed

Lines changed: 61 additions & 0 deletions

File tree

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ ADMIN_API_METHODS_SIMPLE = \
109109
admin.vm.firewall.GetPolicy \
110110
admin.vm.firewall.SetPolicy \
111111
admin.vm.firewall.Reload \
112+
admin.vm.notes.Get \
113+
admin.vm.notes.Set \
112114
admin.vm.property.Get \
113115
admin.vm.property.GetAll \
114116
admin.vm.property.GetDefault \

qubes/api/admin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2038,3 +2038,23 @@ async def vm_current_state(self):
20382038
"power_state": self.dest.get_power_state(),
20392039
}
20402040
return " ".join("{}={}".format(k, v) for k, v in state.items())
2041+
2042+
@qubes.api.method(
2043+
"admin.vm.notes.Get", no_payload=True, scope="local", read=True
2044+
)
2045+
async def vm_notes_get(self):
2046+
"""Get qube notes"""
2047+
self.enforce(self.dest.name != "dom0")
2048+
self.fire_event_for_permission()
2049+
return self.dest.get_notes()
2050+
2051+
@qubes.api.method("admin.vm.notes.Set", scope="local", write=True)
2052+
async def vm_notes_set(self, untrusted_payload):
2053+
"""Set qube notes"""
2054+
allowed_chars = string.printable + " \t\n"
2055+
self.enforce(self.dest.name != "dom0")
2056+
self.enforce(all(c in allowed_chars for c in self.arg))
2057+
self.fire_event_for_permission()
2058+
notes = "".join([c if c in allowed_chars else '_' for \
2059+
c in untrusted_payload.decode("ascii")])
2060+
self.dest.set_notes(notes)

qubes/vm/qubesvm.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2585,6 +2585,43 @@ def kernelopts_common(self):
25852585
else:
25862586
return base_kernelopts + qubes.config.defaults["kernelopts_common"]
25872587

2588+
#
2589+
# free-form text for descriptions, notes, comments, remarks, etc.
2590+
#
2591+
2592+
@property
2593+
def notes_file(self) -> str:
2594+
"""Notes file name within /var/lib/qubes (per each qube sub-dir)"""
2595+
return "notes.txt"
2596+
2597+
def has_notes(self) -> bool:
2598+
"""Return `True` if there is a qube notes file present"""
2599+
return os.path.exists(os.path.join(self.dir_path, self.notes_file))
2600+
2601+
def get_notes(self) -> str:
2602+
"""Read the notes file and return its content"""
2603+
try:
2604+
with open(os.path.join(self.dir_path, self.notes_file), \
2605+
encoding="ascii") as fd:
2606+
return fd.read()
2607+
except EnvironmentError: # pylint: disable=broad-except
2608+
# problem accessing file, like ENOTFOUND, EPERM or sth
2609+
return ""
2610+
2611+
def set_notes(self, notes: str) -> bool:
2612+
"""Write to notes file"""
2613+
try:
2614+
with open(
2615+
os.path.join(self.dir_path, self.notes_file),
2616+
'w',
2617+
encoding="ascii",
2618+
) as fd:
2619+
fd.write(notes)
2620+
fd.close()
2621+
except EnvironmentError: # pylint: disable=broad-except
2622+
return False
2623+
return True
2624+
25882625
#
25892626
# helper methods
25902627
#

rpm_spec/core-dom0.spec.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ admin.vm.feature.Set
286286
admin.vm.firewall.Get
287287
admin.vm.firewall.Reload
288288
admin.vm.firewall.Set
289+
admin.vm.notes.Get
290+
admin.vm.notes.Set
289291
admin.vm.property.Get
290292
admin.vm.property.GetAll
291293
admin.vm.property.GetDefault

0 commit comments

Comments
 (0)