~ubuntu-branches/ubuntu/karmic/migration-assistant/karmic

« back to all changes in this revision

Viewing changes to import.c

  • Committer: Bazaar Package Importer
  • Author(s): Evan Dandrea
  • Date: 2007-07-31 20:21:35 UTC
  • Revision ID: james.westby@ubuntu.com-20070731202135-y6zv761s1zlscpov
Tags: 0.5.0
* Handle more than one installed copy of Windows (LP: #97081).
* Error if unable to mount Linux partitions.
* Bump installer-menu-item to 6400.
* Close directories in ma-search-users.
* Don't unmount devices when we can avoid having to.
* Look for registry files case-insensitively.
* Quote arguments to add_user (LP: #123425).
* Use stat instead of the DT_ macros to avoid issues with fuse.
* Add a debug log.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
#include <pwd.h>
9
9
#include <unistd.h>
10
10
 
 
11
// For directory manipulation
 
12
#include <dirent.h>
 
13
#include <fcntl.h>
 
14
 
11
15
// For umask
12
16
#include <sys/stat.h>
13
17
 
24
28
            argv[0]);
25
29
    exit(EXIT_FAILURE);
26
30
}
27
 
 
28
31
int main(int argc, char** argv) {
29
32
 
30
33
    void (*target)();
45
48
        switch(c) {
46
49
            case 'o' :
47
50
                if(strcmp(optarg, "linux") == 0) os_type = LINUX;
48
 
                else if(strcmp(optarg, "windowsxp") == 0)
 
51
                else if(strcmp(optarg, "windowsxp") == 0) {
49
52
                    os_type = WINDOWSXP;
 
53
            initialize_registry_paths();
 
54
        }
50
55
                else
51
56
                    usage(argv);
52
57
                break;
84
89
                    target = windowsxp_import_userpicture;
85
90
                else if(strcmp(optarg, "wallpaper") == 0)
86
91
                    target = windowsxp_import_wallpaper;
87
 
                else if(strcmp(optarg, "mozillafirefox") == 0)
88
 
                    target = firefox_import_firefox;
89
 
                else if(strcmp(optarg, "internetexplorer") == 0)
90
 
                    target = firefox_import_internetexplorer;
91
 
                else if(strcmp(optarg, "opera") == 0)
92
 
                    target = firefox_import_opera;
93
 
                else if(strcmp(optarg, "outlookexpress") == 0)
94
 
                    target = evolution_import_outlookexpress;
95
 
                else if(strcmp(optarg, "evolution") == 0)
96
 
                    target = evolution_import_evolution;
 
92
        else if(strcmp(optarg, "mozillafirefox") == 0)
 
93
            target = firefox_import_firefox;
 
94
        else if(strcmp(optarg, "internetexplorer") == 0)
 
95
            target = firefox_import_internetexplorer;
 
96
        else if(strcmp(optarg, "opera") == 0)
 
97
            target = firefox_import_opera;
 
98
        else if(strcmp(optarg, "outlookexpress") == 0)
 
99
            target = evolution_import_outlookexpress;
 
100
        else if(strcmp(optarg, "evolution") == 0)
 
101
            target = evolution_import_evolution;
97
102
                else
98
103
                    usage(argv);
99
104
                break;
104
109
    }
105
110
    
106
111
    if((from_user && to_user) && (from_location && to_location)) {
107
 
    
108
 
        // Instead of chowning everything we create, we just drop to the user
109
 
        // we're working with.  Not entirely sure if this is a good/bad idea.
110
 
        
111
 
        struct passwd *p;
112
 
        char* passwd_file;
113
 
        FILE* fp = NULL;
114
 
        
115
 
        asprintf(&passwd_file, "%s/etc/passwd", to_location);
116
 
        fp = fopen(passwd_file, "r");
117
 
        free(passwd_file);
118
 
        
119
 
        while((p = fgetpwent(fp)) != NULL) {
120
 
            if(strcmp(p->pw_name, to_user) == 0) {
121
 
                setgid(p->pw_gid);
122
 
                setuid(p->pw_uid);
123
 
            }
124
 
        }
125
 
        endpwent();
126
 
        fclose(fp);
127
 
        
128
 
        target();
 
112
        struct passwd *p;
 
113
        char* passwd_file;
 
114
        FILE* fp = NULL;
 
115
        
 
116
        
 
117
        // Instead of chowning everything we create, we just drop to the user
 
118
        // we're working with.  Not entirely sure if this is a good/bad idea.
 
119
        asprintf(&passwd_file, "%s/etc/passwd", to_location);
 
120
        fp = fopen(passwd_file, "r");
 
121
        
 
122
        if(fp) {
 
123
            while((p = fgetpwent(fp)) != NULL) {
 
124
                if(strcmp(p->pw_name, to_user) == 0) {
 
125
                    setgid(p->pw_gid);
 
126
                    setuid(p->pw_uid);
 
127
                }
 
128
            }
 
129
            endpwent();
 
130
            fclose(fp);
 
131
        } else {
 
132
            fprintf(stderr, "Unable to open %s\n", passwd_file);
 
133
            exit(EXIT_FAILURE);
 
134
        }
 
135
        free(passwd_file);
 
136
        
 
137
        target();
129
138
    } else
130
139
        usage(argv);
131
140
    
132
141
    return 0;
133
142
}
134
 
// vim:ai:et:sts=4:tw=80:sw=4:
 
143
/* vim:ai:et:sts=4:tw=80:sw=4: */