Skip to content

Instantly share code, notes, and snippets.

View grawity's full-sized avatar

Mantas Mikulėnas grawity

View GitHub Profile
@grawity
grawity / README.md
Created June 2, 2011 05:39
ADVENT magic mode script for TOPS-10-In-a-Box

This script was written for the TOPS-10-In-a-Box project. It calculates the passwords for Magic Mode in ADVENT, and is based on the one available at Zonadepruebas website.

Description copied from Zonadepruebas:

Don Woods, who deviced this authentication scheme 29 years ago, has given his kind permission to disclose it publically

'Advent' is reputedly the first text adventure game. It was originally created by William Crowthers, and later expanded by Don Woods. It was programmed in Fortran, on a DEC PDP-10 computer, and Woods' version dates from 1977. This first version has a maintenance feature called "Magic Mode". It was intended for administrators only, and involves a bizarre authentication process. After entering "MAGIC MODE" as first command in the game, the program will ask:

  1. "ARE YOU A WIZARD?", (replay "YES")
  2. "PROVE IT! SAY MAGIC WORD", (default is "DWARF")
@grawity
grawity / Makefile
Created January 11, 2012 21:33
NTFS volume creation timestamp
CC = i486-mingw32-gcc
LDFLAGS = -lntoskrnl -lntdll
volumeinfo.exe: volumeinfo.c
$(CC) -o $@ $< $(LDFLAGS)
@grawity
grawity / WinlogonUnlocker.cpp
Created February 23, 2012 12:07
Workstation unlocker
#include "stdafx.h"
#define WM_LOGONNOTIFY 0x004c
#define LN_UNLOCK_WORKSTATION 0x0006
void showError()
{
LPTSTR pBuf;
DWORD nBytes = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, GetLastError(), LANG_USER_DEFAULT, (LPWSTR)&pBuf, 4096, NULL);

These are only examples, for a few very common actions. You are expected to write your own rules for the rest. The syntax is regular JavaScript, but see the polkit(8) manpage for the object structure and available API. These examples are for polkit versions 106 and later, with the JS interpreter. They won't work with Debian's polkit v105.

  • If you don't know the action name, run pkaction:

    pkaction | grep cups
    
  • The possible results are YES, AUTH_SELF(_KEEP), AUTH_ADMIN(_KEEP), NO. Returning a result is final. Returning null will continue checking other rules.

  • Put your rules in /etc/polkit-1/rules.d/*.rules. (You can check everything in one giant addRule, or you can have a separate file and separate addRule for each program; it doesn't matter.)

@grawity
grawity / SASL.md
Last active May 13, 2023 12:06
SASL authentication from the perspective of IRC server-to-server protocols

SASL authentication in IRC

© 2014 Mantas Mikulėnas <grawity@gmail.com>

This documentation is released under Creative Commons 3.0 Attribution license.


This is a description of server-server protocol, intended for ircd and services developers. For the client-server protocol descriptions, intended for client & bot developers, see the IRCv3 [sasl-3.1][] and [sasl-3.2][] specifications.

#if 0
pkg = glib-2.0 gio-2.0
src = $(MAKEFILE_LIST)
app = $(basename $(src))
CFLAGS = $(shell pkg-config --cflags $(pkg)) -x c
LDFLAGS = $(shell pkg-config --libs $(pkg))
$(app): $(src)
#!/usr/bin/env perl
use warnings;
use strict;
use Net::DBus;
use Net::DBus::Reactor;
use POSIX;
my $inhibit_fd;
my $logind_mgr;
# NOTE
#
# Eduroam settings are organization-specific.
#
# If something works with *@foobar.edu, that _does_not_mean_ the same
# settings automatically work elsewhere.
#
# Fortunately, *most* sites use very similar settings – password logins via
# PEAP or TTLS. That's what this example covers.
#
#define _GNU_SOURCE
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_prop_card32(Display *d, Window w, Atom p) {
Atom actual_type;
@grawity
grawity / README.md
Last active November 15, 2023 19:35
systemd Type=notify implementations

The official documentation is in the [sd_notify(3)][1] manual page.

Very short summary:

  1. Change your systemd service to Type=notify.
  2. Your daemon will receive an environment variable NOTIFY_SOCKET, which contains a path to an AF_UNIX socket.
    (If the first path byte is @, this means an "abstract" socket, and you should change the 1st byte to 0x00 before using.)
  3. The protocol consists of sending datagrams containing textual (UTF-8) status messages.
    Each message contains newline-separated KEY=value parameters.
  4. When the daemon is ready, it must send READY=1, and systemd will transition the service from "starting" to "running".