// KISSY (Kissing Interface for Sapphic Smooching over ttY) v1.2 /* Copyright (C) 2025 Magdalunaa This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include // mreowww meow nya :3 int main (int argc, char **argv) { // print help if (argc < 2 || strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0) { printf("%s\n", "Usage: kissy [target] \n\n" "Kissy is a utility that allows you to kiss currently logged in users who allow messages.\n" "It works by writing to files in /dev/pts. It needs to run as the group who owns said files (usually tty), using setgid (2755 permissions)."); return 0; } // are we running with setgid? struct stat stat_self; stat("/proc/self/exe", &stat_self); if (!(stat_self.st_mode & S_ISGID && !(stat_self.st_mode & S_IWOTH))) { printf("%s\n", "setgid is not set, or this file is world writable."); return 3; } // try to find the target's uid struct passwd *pw = getpwnam(argv[1]); if (pw == NULL) { printf("%s\n", "Cannot find target"); return 1; } uid_t target = pw->pw_uid; // get current username struct passwd *pw2 = getpwuid(getuid()); if (pw == NULL) { printf("%s\n", "Cannot find user"); return 2; } char* user = pw2->pw_name; // if we have a second argument, set a custom kiss message char kiss[32] = "*mwah*"; if (argc >= 3) { int len = strlen(argv[2]); int written_chars = 0; for (int i = 0; i < len; i++) { if (written_chars >= 31) { kiss[31] = '\0'; break; }; if (iscntrl(argv[2][i])) continue; kiss[i] = argv[2][i]; written_chars++; } } bool kissed = false; // iterate over all files in directory DIR *dir = opendir("/dev/pts"); while (1) { struct dirent *ent = readdir(dir); if (ent == NULL) break; char filepath[strlen("/dev/pts/") + strlen(ent->d_name) + 1]; strcpy(filepath, "/dev/pts/"); strcat(filepath, ent->d_name); struct stat stats; stat (filepath, &stats); // find all terminals with the correct user and that are group-writable if (stats.st_mode & S_IWGRP && stats.st_uid == target) { kissed = true; if (stats.st_gid != getegid()) { // are we running as the tty user? fprintf(stderr, "%s\n", "Mismatch between file owner group and current effective group. Make sure this program is running with setgid."); } else { FILE *tty = fopen(filepath, "a"); // write to terminal! fprintf(tty, "\a\n%s\n--%s\n", kiss, user); fclose(tty); } } } // print a message if a suitable terminal couldn't be found if (!kissed) fprintf(stderr, "%s\n", "Couldn't find any suitable terminals. User is not logged in or has not enabled messages."); }