* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-#define _GNU_SOURCE
-#define _XOPEN_SOURCE 700
-
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <libubus.h>
#include <libubox/blobmsg.h>
-#ifdef HAVE_SHADOW
-#include <shadow.h>
-#endif
-
-#include "login.h"
#include "multipart_parser.h"
goto out;
blob_buf_init(&req, 0);
- blobmsg_add_string(&req, "sid", sid);
+ blobmsg_add_string(&req, "ubus_rpc_session", sid);
blobmsg_add_string(&req, "scope", "luci-io");
blobmsg_add_string(&req, "object", obj);
blobmsg_add_string(&req, "function", func);
struct stat s;
printf("Status: 200 OK\r\n");
- printf("Content-Type: application/json\r\n\r\n{\n");
+ printf("Content-Type: text/plain\r\n\r\n{\n");
if (success)
{
{
printf("Status: 500 Internal Server failure\r\n");
printf("Content-Type: text/plain\r\n\r\n");
- printf(message);
+ printf("%s", message);
if (e)
printf(": %s", strerror(e));
const char *var;
multipart_parser *p;
- multipart_parser_settings s = {
+ static multipart_parser_settings s = {
.on_part_data = data_cb,
.on_headers_complete = data_begin_cb,
.on_part_data_end = data_end_cb,
}
}
-static int
-main_login(int argc, char **argv)
-{
- char *hash, *fields[] = { "username", NULL, "password", NULL };
- const char *sid = NULL;
-
- if (postdecode(fields, 2))
- {
-#ifdef HAVE_SHADOW
- struct spwd *sp = getspnam(fields[1]);
-
- if (!sp)
- goto inval;
-
- /* check whether a password is set */
- if (sp->sp_pwdp && *sp->sp_pwdp &&
- strcmp(sp->sp_pwdp, "!") && strcmp(sp->sp_pwdp, "x"))
- {
- hash = crypt(fields[3], sp->sp_pwdp);
-
- if (strcmp(hash, sp->sp_pwdp))
- goto inval;
- }
-#else
- struct passwd *pw = getpwnam(fields[1]);
-
- if (!pw)
- goto inval;
-
- /* check whether a password is set */
- if (pw->pw_passwd && *pw->pw_passwd &&
- strcmp(pw->pw_passwd, "!") && strcmp(pw->pw_passwd, "x"))
- {
- hash = crypt(fields[3], pw->pw_passwd);
-
- if (strcmp(hash, pw->pw_passwd))
- goto inval;
- }
-#endif
-
- sid = setup_session(fields[1]);
-
- if (!sid)
- goto inval;
-
- printf("Status: 200 OK\r\n");
- printf("Content-Type: application/json\r\n\r\n{\n");
- printf("\t\"sessionid\": \"%s\"\n}\n", sid);
- return 0;
- }
-
-inval:
- printf("Status: 200 OK\r\n");
- printf("Content-Type: application/json\r\n\r\n{}\n");
- return 1;
-}
-
int main(int argc, char **argv)
{
if (strstr(argv[0], "luci-upload"))
return main_upload(argc, argv);
else if (strstr(argv[0], "luci-backup"))
return main_backup(argc, argv);
- else if (strstr(argv[0], "luci-login"))
- return main_login(argc, argv);
return -1;
}