root/trunk/max-multiseat-storage/src/umount.multiseat.c

Revision 862, 2.0 KB (checked in by mario.izquierdo, 16 months ago)

max-multiseat-storage (6.0.max2)

  • Add license headers and cosmetic changes
Line 
1/*
2*  CALL multiseat-udisks to umount a MULTISEAT storage device
3*               (this app have bit SUID)
4* Copyright 2011, Mario Izquierdo, mariodebian at gmail
5*
6* This program is free software; you can redistribute it and/or
7* modify it under the terms of the GNU General Public License
8* as published by the Free Software Foundation; either version 2
9* of the License, or (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19*/
20
21#include <stdio.h>
22#include <unistd.h>
23#include <sys/types.h>
24#include <string.h>
25
26#include <stdlib.h>
27
28int snprintf(char *str, size_t size, const char *format, ...);
29char *fgets(char *s, int tam, FILE *flujo);
30FILE *popen(const char *orden, const char *tipo);
31int pclose(FILE *flujo);
32
33
34#define BSIZE 1024
35#define APP "/usr/sbin/multiseat-udisks"
36
37/* replace \n in command output */
38void remove_line_break( char *s ) {
39    s[strcspn ( s, "\n" )] = '\0';
40}
41
42
43int main (int argc, char **argv) {
44  uid_t my_uid=0;
45  uid_t my_euid=0;
46  FILE *fp;
47  char cmd[BSIZE]="";
48  char line[BSIZE]="";
49  char *fret;
50
51  if (argc != 2) {
52    return 1;
53  }
54
55  my_uid=getuid();
56  my_euid=geteuid();
57
58  /*
59  printf("uid=%d\n", my_uid );
60  printf("euid=%d\n",my_euid);
61  */
62
63  snprintf( (char*) cmd, BSIZE, "%s %s %d 2>&1", APP, argv[1], my_uid);
64
65  if ( setuid(0) ) {
66    printf("/sbin/umount.multiseat: No se pudieron elevar los privilegios.\n");
67    return 1;
68  }
69
70  fp=(FILE*)popen( cmd , "r");
71  if (fp == NULL) {
72    printf("/sbin/umount.multiseat: No se pudo ejecutar la aplicación esclava.\n");
73    return 1;
74  }
75
76  fret = fgets( line, sizeof line, fp);
77  remove_line_break(line);
78  pclose(fp);
79
80  printf("%s\n",line);
81  return 0;
82}
Note: See TracBrowser for help on using the browser.