* Returns the valid dbus EXTERNAL authentication token for the current user (see above) * */
| 52 | * Returns the valid dbus EXTERNAL authentication token for the current user (see above) |
| 53 | * */ |
| 54 | std::string getAuthToken() |
| 55 | { |
| 56 | // Get uid |
| 57 | int uid = getuid(); |
| 58 | |
| 59 | std::ostringstream uidStream; |
| 60 | uidStream << uid; |
| 61 | |
| 62 | std::string uidStr = uidStream.str(); |
| 63 | |
| 64 | const char hexdigits[16] = { |
| 65 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
| 66 | 'a', 'b', 'c', 'd', 'e', 'f' |
| 67 | }; |
| 68 | |
| 69 | std::ostringstream hexStream; |
| 70 | for (char c : uidStr) { |
| 71 | auto byte = (unsigned char)c; |
| 72 | hexStream << hexdigits[byte >> 4] << hexdigits[byte & 0x0f]; |
| 73 | } |
| 74 | |
| 75 | return hexStream.str(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Shuffles all data between the two file-descriptors until one of them fails or reaches EOF. |
no test coverage detected