databases handling tools chmod, chgrp, chown, ls
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
/////
|
||||
//
|
||||
// File : absec_chown.c
|
||||
// Author : Jean-Luc Cyr
|
||||
// Date : 2018-10
|
||||
//
|
||||
// Description: tool to change ownership from mysql database
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <mysql.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// mysql call
|
||||
int mysql_update(char *url, int uid)
|
||||
{
|
||||
MYSQL *conn;
|
||||
MYSQL_RES *res;
|
||||
MYSQL_ROW row;
|
||||
|
||||
char *server = "localhost";
|
||||
char *user = "jlcyr";
|
||||
char *password = "password"; /* set me first */
|
||||
char *database = "absec";
|
||||
|
||||
conn = mysql_init(NULL);
|
||||
|
||||
/* Connect to database */
|
||||
if (!mysql_real_connect(conn, server,
|
||||
user, password, database, 0, NULL, 0)) {
|
||||
printf("%s\n", mysql_error(conn));
|
||||
return(0);
|
||||
}
|
||||
|
||||
char query[256];
|
||||
sprintf(query, "update urls set uid=%d where url='%s'", uid, url); // where url='%s'", r->uri);
|
||||
//printf("update urls set uid=%d where url='%s'\r\n", uid, url); // where url='%s'", r->uri);
|
||||
/* send SQL query */
|
||||
//if (mysql_query(conn, "show tables")) {
|
||||
if (mysql_query(conn, query)) {
|
||||
printf("%s\n", mysql_error(conn));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
mysql_close(conn);
|
||||
return(0);
|
||||
}
|
||||
|
||||
void main(int argc, char** argv)
|
||||
{
|
||||
int perms = 0;
|
||||
switch (argc) {
|
||||
default:
|
||||
printf("Usage: abchown <uid> <url>\r\n\r\n");
|
||||
exit(1);
|
||||
break;
|
||||
case 3:
|
||||
printf("Updating ownership on %s to %d\r\n", argv[2], atoi(argv[1]));
|
||||
mysql_update(argv[2], atoi(argv[1]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user