tweak
[krsd] / src / tools / remove-token.c
1 /*
2  * rs-serve - (c) 2013 Niklas E. Cathor
3  *
4  * This program is distributed in the hope that it will be useful,
5  * but WITHOUT ANY WARRANTY; without even the implied warranty of
6  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7  * GNU Affero General Public License for more details.
8  *
9  * You should have received a copy of the GNU Affero General Public License
10  * along with this program. If not, see <http://www.gnu.org/licenses/>.
11  */
12
13 #define _GNU_SOURCE
14
15 #include <stdio.h>
16 #include <fcntl.h>
17 #include <errno.h>
18 #include <string.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <stdint.h>
22 #include <db.h>
23
24 #include "common/auth.h"
25
26 static void print_usage(char *progname) {
27   fprintf(stderr, "Usage: %s <user> <token>\n", progname);
28 }
29
30 int main(int argc, char **argv) {
31   if(argc < 3) {
32     print_usage(argv[0]);
33     exit(127);
34   }
35   open_authorizations("r+");
36   struct rs_authorization auth;
37   auth.username = argv[1];
38   auth.token = argv[2];
39   int success = remove_authorization(&auth);
40   close_authorizations();
41   fprintf(stderr, (success == DB_NOTFOUND) ? "Token not found!\n" : (success == 0 ? "Token removed.\n" : "Error removing token!\n"));
42   return success;
43 }