128c917368565378356e1e88ff99541a8dc292c4
[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 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <fcntl.h>
17 #include <errno.h>
18
19 #include "common/auth.h"
20
21 static void print_usage(char *progname) {
22   fprintf(stderr, "Usage: %s <user> <token>\n", progname);
23 }
24
25 int main(int argc, char **argv) {
26   if(argc < 3) {
27     print_usage(argv[0]);
28     exit(127);
29   }
30   open_authorizations("r+");
31   struct rs_authorization auth;
32   auth.username = argv[1];
33   auth.token = argv[2];
34   auth.scopes = NULL;
35   int success = remove_authorization(&auth);
36   close_authorizations();
37   fprintf(stderr, (success == 0) ? "Token removed.\n" : "Token not found!\n");
38   return success;
39 }